Support Influx V2 on Docker#68
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Docker Compose support for running the stack against InfluxDB v2 (2.7) while preserving InfluxQL/Grafana compatibility via DBRP (v1 compatibility) mapping.
Changes:
- Switch Docker Compose InfluxDB service to InfluxDB v2.7 with setup env + healthchecks, and add an init job to create v1 DBRP mappings.
- Update Grafana provisioning to use InfluxQL against InfluxDB v2 via Authorization token header.
- Improve
gsw_serviceDB config resolution to correctly detect v2 config from environment variables; add unit tests and refresh documentation/examples.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates InfluxDB CLI usage examples for InfluxDB v2 (bucket list + Flux query). |
| data/influxdb/init-v1-compat.sh | New init script to create InfluxDB v1 DBRP mapping for InfluxQL compatibility. |
| data/grafana/provisioning/datasources/gsw-influxdb-provider.yaml | Switch Grafana datasource config to InfluxQL-over-v2 using an Authorization token header. |
| data/config/gsw_service.yaml.example | Updates example v2 DB config defaults (URL/token/org/bucket). |
| compose.yaml | Updates gsw service env to use InfluxDB v2 connection settings; depends on healthy InfluxDB. |
| compose-services.yaml | Switches InfluxDB container to v2.7 setup mode, adds healthcheck and an init sidecar for DBRP mapping; updates Grafana env wiring. |
| cmd/gsw_service.go | Makes v2 config detection robust for env-var based configuration. |
| cmd/gsw_service_test.go | Adds tests ensuring v2 config is selected from env vars and preferred over v1 when both are present. |
| cmd/Containerfile | Switches container default DB env vars from v1 UDP to v2 HTTP config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ENV GSW_DATABASE_HOST_NAME=influxdb | ||
| ENV GSW_DATABASE_PORT_NUMBER=8089 | ||
| ENV GSW_DATABASE_V2_URL=http://influxdb:8086 | ||
| ENV GSW_DATABASE_V2_TOKEN=gsw-local-dev-token |
There was a problem hiding this comment.
The Containerfile bakes a fixed InfluxDB admin token into the image layer via ENV GSW_DATABASE_V2_TOKEN=.... This is effectively a hardcoded credential and can be unintentionally reused outside local dev (and is retrievable from the built image metadata/history). Prefer leaving the token unset in the image and requiring it to be provided at runtime (e.g., via docker run -e ... / compose env), or set a placeholder value that forces explicit override.
| ENV GSW_DATABASE_V2_TOKEN=gsw-local-dev-token | |
| ENV GSW_DATABASE_V2_TOKEN=CHANGE_ME_AT_RUNTIME |
| database_v2: | ||
| url: http://localhost:8086 | ||
| token: your-token-here | ||
| token: gsw-local-dev-token |
There was a problem hiding this comment.
This example config now includes a concrete token value (gsw-local-dev-token). Even in example files, committing an actual token encourages copying it into real deployments and makes it easy to end up with shared credentials. Consider using a clear placeholder (e.g. your-token-here) and/or referencing the GSW_INFLUXDB_ADMIN_TOKEN/GSW_DATABASE_V2_TOKEN environment variable so users are nudged to set their own.
| token: gsw-local-dev-token | |
| token: your-token-here |
| To query the `gsw` bucket directly, run: | ||
| ```shell | ||
| docker compose exec influxdb influx query \ | ||
| --org gsw \ | ||
| --token gsw-local-dev-token \ |
There was a problem hiding this comment.
The README hardcodes --token gsw-local-dev-token in the query example. If someone overrides the admin token via compose env (which the compose files support), this command will fail and can be confusing. Consider updating the docs to reference the configured env var (e.g. $GSW_INFLUXDB_ADMIN_TOKEN) or instructing how to retrieve the token used by the current compose setup.
| To query the `gsw` bucket directly, run: | |
| ```shell | |
| docker compose exec influxdb influx query \ | |
| --org gsw \ | |
| --token gsw-local-dev-token \ | |
| To query the `gsw` bucket directly, use the admin token configured for your current compose setup (for example, `$GSW_INFLUXDB_ADMIN_TOKEN` if you exported that environment variable before starting the containers): | |
| ```shell | |
| docker compose exec influxdb influx query \ | |
| --org gsw \ | |
| --token "$GSW_INFLUXDB_ADMIN_TOKEN" \ |
There was a problem hiding this comment.
hardcoded token is probably fine in the docs
| --org "${org}" \ | ||
| --token "${token}" \ | ||
| --db "${database}" \ | ||
| --hide-headers | grep -Eq "[[:space:]]${retention_policy}([[:space:]]|$)"; then |
There was a problem hiding this comment.
retention_policy is interpolated directly into an extended regex passed to grep -E. If the value contains regex metacharacters, the check can produce false positives/negatives (or even fail to compile). Consider avoiding regex here (e.g., parse columns with awk and compare exact fields, or use fixed-string matching) so the existence check is reliable for any retention policy name.
| --hide-headers | grep -Eq "[[:space:]]${retention_policy}([[:space:]]|$)"; then | |
| --hide-headers | awk -v database="${database}" -v retention_policy="${retention_policy}" ' | |
| $2 == database && $3 == retention_policy { found = 1; exit } | |
| END { exit found ? 0 : 1 } | |
| '; then |
There was a problem hiding this comment.
Note this file should be blasted once we blast influx v1 from existence. This is just a bandaid to maintain compatibility with the current Grafana dashboards (technically can blast when that happens actually)
There was a problem hiding this comment.
honestly wouldn't hurt to have this in general
K3das
left a comment
There was a problem hiding this comment.
lgtm- just some slightly subjective changes.
| - grafana-data:/var/lib/grafana | ||
| influxdb: | ||
| image: influxdb:1.11-alpine | ||
| image: influxdb:2.7-alpine |
There was a problem hiding this comment.
2.8-alpine is latest, could probably be bumped unless there are breaking changes in 2.8.
| To query the `gsw` bucket directly, run: | ||
| ```shell | ||
| docker compose exec influxdb influx query \ | ||
| --org gsw \ | ||
| --token gsw-local-dev-token \ |
There was a problem hiding this comment.
hardcoded token is probably fine in the docs
| docker compose exec influxdb influx query \ | ||
| --org gsw \ | ||
| --token gsw-local-dev-token \ | ||
| 'from(bucket: "gsw") |> range(start: -15m)' |
There was a problem hiding this comment.
this could potentially be changed to start: 0 to maintain compatibility with previous docs but it's like no big deal
There was a problem hiding this comment.
honestly wouldn't hurt to have this in general
There was a problem hiding this comment.
Could this be moved to an init script in the influx container? Would make it a lot simpler on the docker-compose and config side of things.
| ENV GSW_DATABASE_HOST_NAME=influxdb | ||
| ENV GSW_DATABASE_PORT_NUMBER=8089 | ||
| ENV GSW_DATABASE_V2_URL=http://influxdb:8086 | ||
| ENV GSW_DATABASE_V2_TOKEN=gsw-local-dev-token | ||
| ENV GSW_DATABASE_V2_ORG=gsw | ||
| ENV GSW_DATABASE_V2_BUCKET=gsw |
There was a problem hiding this comment.
I believe I had the database environment variables in the Dockerfile so that the GSW container could start without a database config, but that was patched previously so now I think all of the database config could be left out of the Dockerfile.
Description
Adds support for InfluxV2 on Docker
How Has This Been Tested?
Ran the docker compose and ran some queries on Influx through docker
Checklist: