pg.schema didn't take effect
yifanyou opened this issue · 3 comments
v0.4.1
command:
./prometheus-postgresql-adapter -pg.host=localhost -pg.user=prometheus -pg.password=secret -pg.database=postgres -pg.schema=prometheus -pg.prometheus-log-samples -log.level=debug
data is always inserted in postgres.public
for me, with 0.4.1, seems that pg.schema is now hardcoded to be "prometheus"
i.e. the -pg.schema=whatever command line option is not observed at all.
hey @yifanyou and @tamer-hassan could you guys update to the latest version of the adapter 0.5.0 and try passing this in as -pg-schema= rather than -pg.schema and see if this addresses your issue?
I am having same issue with 0.6.0 adapter.
From following the code in client.go I do not see it sending any commands to choose the schema at all. There is no SET search_path TO command so it takes some default one nor it is using the schema.table_name. It seems like it has no support currently to tell to create_prometheus_table() which tablespace to use. For one test DB on postgres user it took the public, but on user named prometheus it chose prometheus for me.
{"caller":"log.go:31","config":"\u0026{remoteTimeout:30000000000 listenAddr::9201 telemetryPath:/metrics pgPrometheusConfig:{host:localhost port:5432 user:prometheus password:Prom_PW database:prometheus schema:public sslMode:disable table:metrics copyTable: maxOpenConns:50 maxIdleConns:10 pgPrometheusNormalize:true pgPrometheusLogSamples:false pgPrometheusChunkInterval:43200000000000 useTimescaleDb:true dbConnectRetries:0 readOnly:false} logLevel:debug haGroupLockID:0 restElection:false prometheusTimeout:-1 electionInterval:5000000000}","level":"info","ts":"2020-01-23T08:43:32.584Z"}
{"caller":"log.go:31","level":"info","msg":"host=localhost port=5432 user=prometheus dbname=prometheus password='Prom_PW' sslmode=disable connect_timeout=10","ts":"2020-01-23T08:43:32.584Z"}
resulted in structure like that
Weird is that it gives me also the error of "relation 'metrics_labels' already exists" when I try to start it 2nd time after tables have been created.
edit:
Took a look into my postgresql.conf and it makes sense now.
search_path = '"$user", public'
So it will write to prometheus schema, if the user is named prometheus when creating a table.
If it is not prometheus, then it will go to public by default and the -pg-schema switch does nothing. It should overwrite the search_path to ensure tables are created in correct schema.