diff --git a/backlog.md b/backlog.md index 270ca52..2ecaf55 100644 --- a/backlog.md +++ b/backlog.md @@ -1,11 +1,7 @@ # Backlog ## Iteration +1 -- Make schema **and** table name configurable -- Regular expressions not working - - https://github.com/crate/cratedb-prometheus-adapter/issues/24 - - https://prometheus.io/docs/prometheus/latest/querying/basics/ - - https://prometheus.io/docs/prometheus/latest/querying/examples/ +- Make `tablename` setting configurable. Right now, it is hard-coded to `schema` - Expose metrics about both database connection pools https://github.com/crate/cratedb-prometheus-adapter/pull/105 @@ -29,3 +25,11 @@ - Refactor metric names > Generated/dynamic metric names are a sign that you should be using labels instead. > -- https://prometheus.io/docs/instrumenting/writing_clientlibs/#metric-names + + +## Done +- Regular expressions not working? + - https://github.com/crate/cratedb-prometheus-adapter/issues/24 + - https://prometheus.io/docs/prometheus/latest/querying/basics/ + - https://prometheus.io/docs/prometheus/latest/querying/examples/ +- Make `schema` setting configurable diff --git a/crate.go b/crate.go index 564b5b4..b4e854e 100644 --- a/crate.go +++ b/crate.go @@ -13,7 +13,7 @@ import ( "github.com/prometheus/common/model" ) -const crateWriteStatement = `INSERT INTO metrics ("labels", "labels_hash", "timestamp", "value", "valueRaw") VALUES ($1, $2, $3, $4, $5)` +const crateWriteStatement = `INSERT INTO "%s" ("labels", "labels_hash", "timestamp", "value", "valueRaw") VALUES ($1, $2, $3, $4, $5)` type crateRow struct { labels model.Metric @@ -37,6 +37,7 @@ type crateReadResponse struct { type crateEndpoint struct { poolConf *pgxpool.Config + tableName string readPoolSize int writePoolSize int readTimeout time.Duration @@ -96,7 +97,8 @@ func newCrateEndpoint(ep *endpointConfig) *crateEndpoint { } } - _, err := conn.Prepare(ctx, "write_statement", crateWriteStatement) + writeStatement := fmt.Sprintf(crateWriteStatement, ep.Table) + _, err := conn.Prepare(ctx, "write_statement", writeStatement) if err != nil { return fmt.Errorf("error preparing write statement: %v", err) } @@ -104,6 +106,7 @@ func newCrateEndpoint(ep *endpointConfig) *crateEndpoint { } return &crateEndpoint{ poolConf: poolConf, + tableName: ep.Table, readPoolSize: ep.ReadPoolSize, writePoolSize: ep.WritePoolSize, readTimeout: time.Duration(ep.ReadTimeout) * time.Second, diff --git a/server.go b/server.go index 4382def..f80b584 100644 --- a/server.go +++ b/server.go @@ -211,6 +211,7 @@ type crateDbPrometheusAdapter struct { } func (ca *crateDbPrometheusAdapter) runQuery(q *prompb.Query) ([]*prompb.TimeSeries, error) { + //fmt.Printf("QUERY: %s", config{}.Endpoints[0].Table) query, err := queryToSQL(q) if err != nil { return nil, err @@ -357,6 +358,7 @@ type endpointConfig struct { Port uint16 `yaml:"port"` User string `yaml:"user"` Password string `yaml:"password"` + Table string `yaml:"table"` Schema string `yaml:"schema"` MaxConnections int `yaml:"max_connections"` ReadPoolSize int `yaml:"read_pool_size_max"` @@ -383,8 +385,11 @@ func (ep *endpointConfig) toDSN() string { if ep.Password != "" { params = append(params, fmt.Sprintf("password=%s", ep.Password)) } + if ep.Table != "" { + params = append(params, fmt.Sprintf("table=%s", ep.Table)) + } if ep.Schema != "" { - params = append(params, fmt.Sprintf("database=%s", ep.Schema)) + params = append(params, fmt.Sprintf("schema=%s", ep.Schema)) } if ep.ConnectTimeout != 0 { params = append(params, fmt.Sprintf("connect_timeout=%v", ep.ConnectTimeout))