Skip to content
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

fix: support NULL values for key labels #321

Merged
merged 3 commits into from
Sep 19, 2023
Merged

Conversation

burningalchemist
Copy link
Owner

@burningalchemist burningalchemist commented Sep 17, 2023

Description

At the moment, if at least one of the columns specified in key_labels contains NULL in a row, the query will return the error and the metrics won't be published (for a single target). It's by design of database/sql - NULL is not an empty string, so it cannot be converted to a string out of the box.

We actually want to support NULL values for metric labels (strings). If a row contains NULL in a column that's defined in key_labels, we return its value as an empty string. In addition we create a log (under debug log level) message, that the column value is NULL for a particular row.


Example

Sample Dataset:

Username Identifier Firstname Lastname
9012 Rachel Booker
grey07 2070 Laura Grey
johnson81 4081 Craig Johnson
jenkins46 9346 Mary Jenkins
smith79 5079 Jamie Smith

Metric configuration:

- metric_name: test
  type: gauge
  values: [Identifier]
  key_labels:
  - Username
  - Firstname
  - Lastname
  query: |
    SET @@DELIMITER TO ';';
    SELECT Username, Firstname, Lastname, Identifier FROM `username.csv`

The result:

# HELP test
# TYPE test gauge
test{Firstname="Craig",Lastname="Johnson",Username="johnson81",instance="test"} 4081
test{Firstname="Jamie",Lastname="Smith",Username="smith79",instance="test"} 5079
test{Firstname="Laura",Lastname="Grey",Username="grey07",instance="test"} 2070
test{Firstname="Mary",Lastname="Jenkins",Username="jenkins46",instance="test"} 9346
test{Firstname="Rachel",Lastname="Booker",Username="",instance="test"} 9012

fixes #317

@burningalchemist burningalchemist added this to the v0.13 milestone Sep 17, 2023
@burningalchemist burningalchemist merged commit 1eedd19 into master Sep 19, 2023
3 checks passed
@burningalchemist burningalchemist deleted the fix/null-labels branch September 19, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possibility to add optional labels
1 participant