-
Notifications
You must be signed in to change notification settings - Fork 1
Support Influx V2 on Docker #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,12 +57,17 @@ If you need to change dashboards or datasources, set `GF_AUTH_ANONYMOUS_ORG_ROLE | |
| #### Accessing InfluxDB | ||
|
|
||
| You can access the InfluxDB CLI using `docker compose exec -it influxdb influx`. | ||
| For example, to export all receiver telemetry as a CSV, run: | ||
| For example, to list buckets, run: | ||
| ```shell | ||
| $ docker compose exec influxdb influx \ | ||
| -database "gsw" \ | ||
| -format csv \ | ||
| -execute "SELECT * FROM receiver" | ||
| docker compose exec influxdb influx bucket list | ||
| ``` | ||
|
|
||
| To query the `gsw` bucket directly, run: | ||
| ```shell | ||
| docker compose exec influxdb influx query \ | ||
| --org gsw \ | ||
| --token gsw-local-dev-token \ | ||
| 'from(bucket: "gsw") |> range(start: -15m)' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could potentially be changed to |
||
| ``` | ||
|
|
||
| ### Attaching to the container | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,8 +43,10 @@ | |||||
|
|
||||||
| ENV GSW_LOGGER_OUTPUT_PATHS=stdout | ||||||
|
|
||||||
| 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 | ||||||
|
Check warning on line 47 in cmd/Containerfile
|
||||||
|
||||||
| ENV GSW_DATABASE_V2_TOKEN=gsw-local-dev-token | |
| ENV GSW_DATABASE_V2_TOKEN=CHANGE_ME_AT_RUNTIME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/AarC10/GSW-V2/lib/db" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func newTestConfig() *viper.Viper { | ||
| cfg := viper.New() | ||
| cfg.SetEnvPrefix("GSW") | ||
| cfg.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | ||
| cfg.AutomaticEnv() | ||
| return cfg | ||
| } | ||
|
|
||
| func TestResolveDBConfigFromEnvironmentUsesV2(t *testing.T) { | ||
| t.Setenv("GSW_DATABASE_V2_URL", "http://influxdb:8086") | ||
| t.Setenv("GSW_DATABASE_V2_TOKEN", "test-token") | ||
| t.Setenv("GSW_DATABASE_V2_ORG", "gsw") | ||
| t.Setenv("GSW_DATABASE_V2_BUCKET", "gsw") | ||
| t.Setenv("GSW_DATABASE_V2_BATCH_SIZE", "250") | ||
| t.Setenv("GSW_DATABASE_V2_FLUSH_INTERVAL_MS", "1500") | ||
| t.Setenv("GSW_DATABASE_V2_PRECISION", "ms") | ||
|
|
||
| cfg := newTestConfig() | ||
|
|
||
| got, err := resolveDBConfig(cfg) | ||
| if err != nil { | ||
| t.Fatalf("resolveDBConfig returned error: %v", err) | ||
| } | ||
| if got.v2 == nil { | ||
| t.Fatal("expected v2 config to be selected") | ||
| } | ||
| if got.v1 != nil { | ||
| t.Fatal("expected v1 config to remain unset") | ||
| } | ||
|
|
||
| want := db.InfluxDBV2Config{ | ||
| URL: "http://influxdb:8086", | ||
| Token: "test-token", | ||
| Org: "gsw", | ||
| Bucket: "gsw", | ||
| BatchSize: 250, | ||
| FlushInterval: 1500, | ||
| Precision: db.PrecisionMS, | ||
| } | ||
| if *got.v2 != want { | ||
| t.Fatalf("got %+v, want %+v", *got.v2, want) | ||
| } | ||
| } | ||
|
|
||
| func TestResolveDBConfigPrefersV2OverV1(t *testing.T) { | ||
| cfg := viper.New() | ||
| cfg.Set("database_host_name", "legacy") | ||
| cfg.Set("database_port_number", 8089) | ||
| cfg.Set("database_v2.url", "http://influxdb:8086") | ||
| cfg.Set("database_v2.token", "token") | ||
| cfg.Set("database_v2.org", "gsw") | ||
| cfg.Set("database_v2.bucket", "gsw") | ||
|
|
||
| got, err := resolveDBConfig(cfg) | ||
| if err != nil { | ||
| t.Fatalf("resolveDBConfig returned error: %v", err) | ||
| } | ||
| if got.v2 == nil { | ||
| t.Fatal("expected v2 config to be selected") | ||
| } | ||
| if got.v1 != nil { | ||
| t.Fatal("expected v1 config to remain unset when v2 is configured") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,26 +6,52 @@ services: | |
| ports: | ||
| - "127.0.0.1:3000:3000/tcp" | ||
| depends_on: | ||
| influxdb: | ||
| condition: service_started | ||
| influxdb-init: | ||
| condition: service_completed_successfully | ||
| environment: | ||
| - GSW_GRAFANA_INFLUXDB_URL=http://influxdb:8086 | ||
| - GSW_GRAFANA_INFLUXDB_USER=root | ||
| - GSW_GRAFANA_INFLUXDB_PASSWORD=root | ||
| - GSW_GRAFANA_INFLUXDB_DB_NAME=${GSW_INFLUXDB_BUCKET:-gsw} | ||
| - GSW_GRAFANA_INFLUXDB_TOKEN=${GSW_INFLUXDB_ADMIN_TOKEN:-gsw-local-dev-token} | ||
| - GF_AUTH_ANONYMOUS_ENABLED=true | ||
| - GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer | ||
| - GF_AUTH_BASIC_ENABLED=false | ||
| volumes: | ||
| - grafana-data:/var/lib/grafana | ||
| influxdb: | ||
| image: influxdb:1.11-alpine | ||
| image: influxdb:2.7-alpine | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| volumes: | ||
| - influxdb-data:/var/lib/influxdb | ||
| - influxdb-data:/var/lib/influxdb2 | ||
| - influxdb-config:/etc/influxdb2 | ||
| environment: | ||
| - INFLUXDB_UDP_ENABLED=true | ||
| - INFLUXDB_UDP_DATABASE=gsw | ||
| - DOCKER_INFLUXDB_INIT_MODE=setup | ||
| - DOCKER_INFLUXDB_INIT_USERNAME=${GSW_INFLUXDB_USERNAME:-gsw} | ||
| - DOCKER_INFLUXDB_INIT_PASSWORD=${GSW_INFLUXDB_PASSWORD:-gsw-password} | ||
| - DOCKER_INFLUXDB_INIT_ORG=${GSW_INFLUXDB_ORG:-gsw} | ||
| - DOCKER_INFLUXDB_INIT_BUCKET=${GSW_INFLUXDB_BUCKET:-gsw} | ||
| - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${GSW_INFLUXDB_ADMIN_TOKEN:-gsw-local-dev-token} | ||
| ports: | ||
| - "127.0.0.1:8089:8089/udp" | ||
| - "127.0.0.1:8086:8086/tcp" | ||
| healthcheck: | ||
| test: ["CMD", "influx", "ping", "--host", "http://localhost:8086"] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 20 | ||
| start_period: 10s | ||
| influxdb-init: | ||
| image: influxdb:2.7-alpine | ||
| depends_on: | ||
| influxdb: | ||
| condition: service_healthy | ||
| environment: | ||
| - INFLUX_HOST=http://influxdb:8086 | ||
| - DOCKER_INFLUXDB_INIT_ORG=${GSW_INFLUXDB_ORG:-gsw} | ||
| - DOCKER_INFLUXDB_INIT_BUCKET=${GSW_INFLUXDB_BUCKET:-gsw} | ||
| - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${GSW_INFLUXDB_ADMIN_TOKEN:-gsw-local-dev-token} | ||
| - GSW_INFLUXDB_V1_DATABASE=${GSW_INFLUXDB_BUCKET:-gsw} | ||
| - GSW_INFLUXDB_V1_RETENTION_POLICY=autogen | ||
| volumes: | ||
| - ./data/influxdb/init-v1-compat.sh:/docker-entrypoint-initdb.d/init-v1-compat.sh:ro | ||
| entrypoint: ["/bin/sh", "/docker-entrypoint-initdb.d/init-v1-compat.sh"] | ||
|
|
||
| mosquitto: | ||
| build: | ||
|
|
@@ -38,3 +64,4 @@ services: | |
| volumes: | ||
| grafana-data: | ||
| influxdb-data: | ||
| influxdb-config: | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,12 +9,12 @@ telemetry_config: data/config/backplane.yaml | |||||
| # If database_v2 is set, V2 will be used and V1 settings are ignored | ||||||
| database_v2: | ||||||
| url: http://localhost:8086 | ||||||
| token: your-token-here | ||||||
| token: gsw-local-dev-token | ||||||
|
||||||
| token: gsw-local-dev-token | |
| token: your-token-here |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. honestly wouldn't hurt to have this in general
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||
| #!/bin/sh | ||||||||||||
| set -eu | ||||||||||||
|
|
||||||||||||
| host="${INFLUX_HOST:-http://influxdb:8086}" | ||||||||||||
| org="${DOCKER_INFLUXDB_INIT_ORG:?DOCKER_INFLUXDB_INIT_ORG is required}" | ||||||||||||
| bucket="${DOCKER_INFLUXDB_INIT_BUCKET:?DOCKER_INFLUXDB_INIT_BUCKET is required}" | ||||||||||||
| token="${DOCKER_INFLUXDB_INIT_ADMIN_TOKEN:?DOCKER_INFLUXDB_INIT_ADMIN_TOKEN is required}" | ||||||||||||
| database="${GSW_INFLUXDB_V1_DATABASE:-$bucket}" | ||||||||||||
| retention_policy="${GSW_INFLUXDB_V1_RETENTION_POLICY:-autogen}" | ||||||||||||
|
|
||||||||||||
| echo "Waiting for InfluxDB at ${host}" | ||||||||||||
| until influx ping --host "${host}" >/dev/null 2>&1; do | ||||||||||||
| sleep 1 | ||||||||||||
| done | ||||||||||||
|
|
||||||||||||
| bucket_id="$(influx bucket list \ | ||||||||||||
| --host "${host}" \ | ||||||||||||
| --org "${org}" \ | ||||||||||||
| --token "${token}" \ | ||||||||||||
| --name "${bucket}" \ | ||||||||||||
| --hide-headers | awk 'NR == 1 { print $1 }')" | ||||||||||||
|
|
||||||||||||
| if [ -z "${bucket_id}" ]; then | ||||||||||||
| echo "Unable to resolve bucket ID for ${bucket}" >&2 | ||||||||||||
| exit 1 | ||||||||||||
| fi | ||||||||||||
|
|
||||||||||||
| if influx v1 dbrp list \ | ||||||||||||
| --host "${host}" \ | ||||||||||||
| --org "${org}" \ | ||||||||||||
| --token "${token}" \ | ||||||||||||
| --db "${database}" \ | ||||||||||||
| --hide-headers | grep -Eq "[[:space:]]${retention_policy}([[:space:]]|$)"; then | ||||||||||||
|
||||||||||||
| --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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README hardcodes
--token gsw-local-dev-tokenin 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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcoded token is probably fine in the docs