diff --git a/CHANGES.rst b/CHANGES.rst index 86e5ca1..d5a80ae 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ CHANGES for CrateDB Prometheus Adapter Unreleased ========== +- Add option to configure primary key conflict behaviour. 2024-01-23 0.5.1 ================ diff --git a/crate.go b/crate.go index 564b5b4..ba6e81b 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 metrics ("labels", "labels_hash", "timestamp", "value", "valueRaw") VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING` type crateRow struct { labels model.Metric @@ -112,17 +112,17 @@ func newCrateEndpoint(ep *endpointConfig) *crateEndpoint { } func (c *crateEndpoint) endpoint() endpoint.Endpoint { - /** - * Initialize connection pools lazily here instead of in `newCrateEndpoint()`, - * so that the adapter does not crash on startup if the endpoint is unavailable. - **/ - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - + /** + * Initialize connection pools lazily here instead of in `newCrateEndpoint()`, + * so that the adapter does not crash on startup if the endpoint is unavailable. + **/ + return func(ctx context.Context, request interface{}) (response interface{}, err error) { + // Initialize database connection pools. - err = c.createPools(ctx) + err = c.createPools(ctx) // Dispatch by request type. - switch r := request.(type) { + switch r := request.(type) { case *crateWriteRequest: return nil, c.write(ctx, r) case *crateReadRequest: