|
2 | 2 |
|
3 | 3 | A Golang application to export table level metrics from BigQuery into Datadog.
|
4 | 4 |
|
5 |
| -## Configuration |
6 |
| -`bqmetrics` and `bqmetricsd` take the same optional parameters. |
| 5 | +Two binaries are provided. `bqmetrics` runs a single round of metrics |
| 6 | +collection. `bqmetricsd` runs metrics collection continually according to the |
| 7 | +provided metric collection interval. |
7 | 8 |
|
8 |
| -It is required that the Datadog API key is set using one of the below options |
9 |
| -in order to run. Credentials also need to be provided for connecting to the |
10 |
| -GCP APIs, although that may be handled automatically by the environment. See |
11 |
| -[the Google authentication documentation](https://cloud.google.com/docs/authentication/production) |
12 |
| -for more information. All other parameters are optional. |
| 9 | +## Metrics |
| 10 | +The metrics exporter queries the BigQuery metadata API to generate metrics. The |
| 11 | +metadata API only stores this information for **tables** and **materialized |
| 12 | +views**, so views and external data sources will not have metrics exported. |
13 | 13 |
|
| 14 | +The following metrics are generated: |
| 15 | +* **row_count** - The number of rows in the table |
| 16 | +* **last_modified** - The number of seconds since this table was last modified |
| 17 | +* **last_modified_time** - The timestamp when the table was last modified |
| 18 | + |
| 19 | +Inserting or modifying data in the table also updates the last modified time, |
| 20 | +so those metrics can be used as a measure of data freshness. |
| 21 | + |
| 22 | +## Recommended usage |
| 23 | +It is recommended to run the metrics collection daemon `bqmetricsd` which will |
| 24 | +continually collect metrics and ship them to Datadog according to the provided |
| 25 | +schedule. |
14 | 26 | ```
|
15 |
| ---datadog-api-key-file |
16 |
| - File containing the Datadog API key |
17 |
| ---datadog-api-key-secret-id |
18 |
| - Google Secret Manager Resource ID containing the Datadog API key |
19 |
| ---gcp-project-id |
20 |
| - The GCP project to extract BigQuery metrics from |
21 |
| ---metric-interval |
22 |
| - The interval between metrics submissions (Default 30s) |
23 |
| ---metric-prefix |
24 |
| - The prefix for the metric names exported to Datadog (Default custom.gcp.bigquery.table) |
25 |
| ---metric-tags |
26 |
| - Comma-delimited list of tags to attach to metrics |
| 27 | +bqmetricsd \ |
| 28 | + --datadog-api-key-file datadog.key \ |
| 29 | + --gcp-project-id my-project \ |
| 30 | + --metric-interval 1m \ |
| 31 | + --metric-tags team:myteam,env:prod |
27 | 32 | ```
|
28 | 33 |
|
29 |
| -All parameters can be supplied as environment variables instead, and there |
30 |
| -are additional environment variables that are not available as parameters. |
31 |
| -Configuration supplied as parameters to the command takes precedence over |
32 |
| -environment variables. |
| 34 | +### Running in Google Cloud Platform |
| 35 | +Running in Google Cloud Platform is the preferred method of operation as it |
| 36 | +will reduce latency for metrics collection and simplify authentication to the |
| 37 | +BigQuery API. A [Terraform provider](terraform/gcp/README.md) is provided to |
| 38 | +simplify running the daemon in GCP. |
33 | 39 |
|
| 40 | +The Terraform provider makes use of Google Secrets Manager to handle the |
| 41 | +Datadog API secret key. This secret can be created with the `gcloud` CLI |
| 42 | +utility using the following command: |
| 43 | +```shell |
| 44 | +printf "secret" | gcloud secrets create datadog-api-key --data-file=- |
34 | 45 | ```
|
35 |
| -DATADOG_API_KEY |
36 |
| - The Datadog API key |
37 |
| -DATADOG_API_KEY_FILE |
38 |
| - File containing the Datadog API key |
39 |
| -DATADOG_API_KEY_SECRET_ID |
40 |
| - Google Secret Manager Resource ID containing the Datadog API key |
41 |
| -GCP_PROJECT_ID |
42 |
| - The GCP project to extract BigQuery metrics from |
43 |
| -GOOGLE_APPLICATION_CREDENTIALS |
44 |
| - File containing the service account details to authenticate to GCP using |
45 |
| -LOG_LEVEL |
46 |
| - The logging level (e.g. trace, debug, info, warn, error) |
47 |
| -METRIC_INTERVAL |
48 |
| - The interval between metrics submissions (Default 30s) |
49 |
| -METRIC_PREFIX |
50 |
| - The prefix for the metric names exported to Datadog (Default custom.gcp.bigquery.table) |
51 |
| -METRIC_TAG |
52 |
| - Comma-delimited list of tags to attach to metrics |
| 46 | + |
| 47 | +Depending on organizational policy, you may need to restrict the secret to |
| 48 | +certain locations. See `gcloud secrets create --help` for full details. |
| 49 | + |
| 50 | +An existing secret can be updated with the following commands: |
| 51 | +```shell |
| 52 | +printf "secret" | gcloud secrets versions add datadog-api-key --data-file=- |
53 | 53 | ```
|
54 | 54 |
|
| 55 | +## Configuration |
| 56 | +`bqmetrics` and `bqmetricsd` take the same optional parameters. Parameters |
| 57 | +can be supplied as either environment variables or on the command line, and |
| 58 | +configuration passed on the command line takes precedence over environment |
| 59 | +variables. |
| 60 | + |
| 61 | +It is required that the Datadog API key is set using one of the below options |
| 62 | +in order to run. Credentials also need to be provided for connecting to the |
| 63 | +GCP APIs, although that may be handled automatically by the environment. See |
| 64 | +[the Google Cloud Platform authentication documentation](https://cloud.google.com/docs/authentication/production) |
| 65 | +for more information. The Google Cloud Project ID is also required. All other |
| 66 | +parameters are optional. |
| 67 | + |
| 68 | +| Environment Variable | Parameter | Description | |
| 69 | +| --- | --- | --- | |
| 70 | +| DATADOG_API_KEY | | The Datadog API key | |
| 71 | +| DATADOG_API_KEY_FILE | --datadog-api-key-file | File containing Datadog API key | |
| 72 | +| DATADOG_API_KEY_SECRET_ID | --datadog-api-key-secret-id | Path to a secret held in Google Secret Manager containing Datadog API key, e.g. `projects/my-project/secrets/datadog-api-key/versions/3` | |
| 73 | +| GCP_PROJECT_ID | --gcp-project-id | (Required) The Google Cloud project containing the BigQuery tables to retrieve metrics from | |
| 74 | +| GOOGLE_APPLICATION_CREDENTIALS | | File containing service account details to authenticate to Google Cloud using | |
| 75 | +| LOG_LEVEL | | The logging level (e.g. trace, debug, info, warn, error). Defaults to *info* | |
| 76 | +| METRIC_INTERVAL | --metric-interval | The interval between metric collection rounds. Must contain a unit and valid units are "ns", "us" (or "µs"), "ms", "s", "m", "h". Defaults to *30s* | |
| 77 | +| METRIC_PREFIX | --metric-prefix | The prefix for the metric names exported to Datadog. Defaults to *custom.gcp.bigquery.table* | |
| 78 | +| METRIC_TAGS | --metric-tags | Comma-delimited list of tags to attach to metrics (e.g. env:prod,team:myteam) | |
| 79 | + |
55 | 80 | ### GCP Service Account permissions
|
56 |
| -The service account may require the following roles: |
| 81 | +The service account running `bqmetricsd` may require the following roles: |
57 | 82 | ```
|
58 | 83 | BigQuery Metadata Viewer
|
59 | 84 | Required to generate table level metrics
|
|
0 commit comments