-
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
Changes from all commits
ee2efda
b6e38f3
ed82796
8f23353
5f05ea7
926b759
8fb5596
b48f0cb
f49a302
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 |
|---|---|---|
| @@ -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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| FROM influxdb:2.9-alpine | ||
|
|
||
| COPY ./init-v1-compat.sh /docker-entrypoint-initdb.d/init-v1-compat.sh | ||
| RUN chmod +x /docker-entrypoint-initdb.d/init-v1-compat.sh |
|
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
K3das marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||
| #!/bin/sh | ||||||||||||
| set -eu | ||||||||||||
|
|
||||||||||||
| host="${INFLUX_HOST:-http://localhost: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