Skip to content

Commit a25748b

Browse files
KevinMinddiox
andauthored
Add runbooks with examples for localdev/dev/statistics (#23286)
* Add runbooks with examples for localdev/dev/statistics * Update .dockerignore * Update .gitignore * Update settings.py Co-authored-by: Mathieu Pillard <diox@users.noreply.github.com> --------- Co-authored-by: Mathieu Pillard <diox@users.noreply.github.com>
1 parent 2443c37 commit a25748b

File tree

9 files changed

+143
-0
lines changed

9 files changed

+143
-0
lines changed
330 KB
Loading

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ topics/remote_addr
1919
topics/third-party
2020
topics/blocklist
2121
topics/environments
22+
topics/runbooks/index
2223
```
2324

2425
## Archived Contents

docs/topics/runbooks/dev/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Dev Environment
2+
3+
Runbooks designed to run on the `dev` environment.
4+
These should *not* be used in local/stage/production environments.
5+
6+
```{toctree}
7+
:maxdepth: 2
8+
9+
shell_into_dev_pod
10+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Shell into a dev pod
2+
3+
See <https://mozilla-hub.atlassian.net/wiki/spaces/FDPDT/pages/98795521/DevOps#Bastion-Hosts> for details.

docs/topics/runbooks/index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Runbooks
2+
3+
A set of runbooks for the AMO team. These documents should enable anyone to perform
4+
common tasks involved in triaging issues, verifying patches, and maintaining our codebase.
5+
6+
```{toctree}
7+
:maxdepth: 2
8+
9+
localdev/index
10+
dev/index
11+
```
12+
13+
## Example
14+
15+
Follow this template to create a new runbook.
16+
17+
```{tip}
18+
Use ### headings to separate steps so steps will be visible in the table of contents.
19+
```
20+
21+
```markdown
22+
# Runbook Title
23+
24+
Brief description of the runbook.
25+
26+
## Steps
27+
28+
### Step 1
29+
30+
### Step 2
31+
32+
### Step 3
33+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# BigQuery Credentials Setup
2+
3+
Setup bigquery credentials for dev on local environment.
4+
This will allow you to connect to the dev BigQuery database
5+
and run queries.
6+
7+
## Steps
8+
9+
### Get dev bigquery credentials json file
10+
11+
[Shell into a dev pod](../dev/shell_into_dev_pod.md)
12+
13+
a. create a django shell `make djshell`
14+
b. get the value of `settings.GOOGLE_APPLICATION_CREDENTIALS_BIGQUERY`
15+
c. exit the django shell and cat the the file
16+
d. copy the contents to a file on your local machine
17+
18+
```{warning}
19+
This file contains sensitive secrets. Save it in `private/google-application-credentials.json`
20+
which is explicitly gitignored to prevent it from being checked into git.
21+
Do not share this file with anyone.
22+
```
23+
24+
### Run the project locally
25+
26+
a. update `local_settings.py` to point `GOOGLE_APPLICATION_CREDENTIALS_BIGQUERY` to the file on your local machine
27+
b. run `make up` to start the django server with this value enabled
28+
29+
### Verify it is working
30+
31+
Verify you can connect to bigquery by running `make djshell` and then:
32+
33+
```python
34+
from olympia.stats.utils import *
35+
client = create_client()
36+
client.project
37+
```
38+
39+
Expect to get a response like:
40+
41+
```bash
42+
In [3]: client.project
43+
Out[3]: 'moz-fx-amo-environment-abc123'
44+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Local Development
2+
3+
Runbooks designed to run on a local development environment.
4+
These should *not* be used in dev/stage/production environments.
5+
6+
```{toctree}
7+
:maxdepth: 2
8+
9+
bigquery_credentials_setup
10+
test_statistics_dashboard
11+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Test Statistics Dashboard
2+
3+
Test the devhub statistics dashboard locally with bigquery credentials.
4+
5+
## Steps
6+
7+
### Setup bigquery credentials
8+
9+
[Bigquery Credentials Setup](./bigquery_credentials_setup.md)
10+
11+
### Enable a local addon to read from bigquery dev database
12+
13+
Only a [subset of addons][enabled_dev_guids] in dev push data to bigquery. In order to read from bigquery
14+
your local addon will need to use a matching `guid`.
15+
16+
Open a django shell `make djshell` and run the following:
17+
18+
- pk: the database id of the addon you want to use
19+
- guid: the guid from the [list][enabled_dev_guids] you want to use (e.g. `@facebook-container`)
20+
21+
```python
22+
addon = Addon.objects.get(pk=<pg>)
23+
addon.update(guid=<guid>)
24+
addon.save()
25+
```
26+
27+
### Run the statistics dashboard
28+
29+
Open your addon `<http://olympia.test/en-US/firefox/addon/<pk>/statistics/>`
30+
31+
You should see the default overview chart. It should look like this:
32+
33+
![alt text](../../../_static/images/statistics-overview-chart.png)
34+
35+
[enabled_dev_guids]: https://github.com/mozilla/bigquery-etl/blob/main/sql/moz-fx-data-shared-prod/amo_dev/amo_stats_dau_v2/query.sql

settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@ def insert_debug_toolbar_middleware(middlewares):
171171
}
172172

173173
MEMCACHE_MIN_SERVER_COUNT = 1
174+
175+
GOOGLE_APPLICATION_CREDENTIALS_BIGQUERY = env(
176+
'GOOGLE_APPLICATION_CREDENTIALS_BIGQUERY',
177+
# Set default path to the path explicitly gitignored.
178+
default=path('private/google-application-credentials.json'),
179+
)

0 commit comments

Comments
 (0)