Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Unique metrics #39

@Knudian

Description

@Knudian

In production, we have processes uploading metrics via an API I created, which causes duplication of datas.

I did a workaround locally (using database migrations in the API), to alter a bit the structure:

  1. Adding a unique constraint :
ALTER TABLE metrics_values ADD CONSTRAINT unique_time_value_labels_id UNIQUE (time, value, labels_id);
  1. Adding an "ON CONFLICT" within the function prometheus.insert_view_normal(), at line 149 :
    EXECUTE format('INSERT INTO %I (time, value, labels_id) VALUES (%L, %L, %L)',

    Transforming this line as :
EXECUTE format('INSERT INTO %I (time, value, labels_id) VALUES (%L, %L, %L) ON CONFLICT DO NOTHING', 

so the unique constraint allow to push metrics, and no duplicates to be found afterwards.

Does this qualify to be proposed as a PR ?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions