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

Construct Prometheus Metrics with ValueType #162

Merged
merged 1 commit into from
Jul 1, 2022

Conversation

KAllan357
Copy link
Contributor

I noticed that on the master branch, you'd see the following information once you were set up with the example:

# HELP example_global_value Example of a top-level global value scrape in the json
# TYPE example_global_value untyped
example_global_value{environment="beta",location="planet-mars"} 1234
# HELP example_value_active Example of sub-level value scrapes from a json
# TYPE example_value_active untyped
example_value_active{environment="beta",id="id-A"} 1
example_value_active{environment="beta",id="id-C"} 1

With this PR, and a corresponding config change to the example like:

---
modules:
  default:
    metrics:
    - name: example_global_value
      path: "{ .counter }"
      help: Example of a top-level global value scrape in the json
      valuetype: gauge
      labels:
        environment: beta # static label
        location: "planet-{.location}"          # dynamic label

    - name: example_value
      type: object
      help: Example of sub-level value scrapes from a json
      path: '{.values[?(@.state == "ACTIVE")]}'
      valuetype: counter
      labels:
        environment: beta # static label
        id: '{.id}'          # dynamic label
      values:
        active: 1      # static value
        count: '{.count}' # dynamic value
        boolean: '{.some_boolean}'
    headers:
      X-Dummy: my-test-header

The # TYPE <metric> <valuetype> ends up correct.

# HELP example_global_value Example of a top-level global value scrape in the json
# TYPE example_global_value gauge
example_global_value{environment="beta",location="planet-mars"} 1234
# HELP example_value_active Example of sub-level value scrapes from a json
# TYPE example_value_active counter
example_value_active{environment="beta",id="id-A"} 1
example_value_active{environment="beta",id="id-C"} 1
# HELP example_value_boolean Example of sub-level value scrapes from a json
# TYPE example_value_boolean counter
example_value_boolean{environment="beta",id="id-A"} 1
example_value_boolean{environment="beta",id="id-C"} 0
# HELP example_value_count Example of sub-level value scrapes from a json
# TYPE example_value_count counter
example_value_count{environment="beta",id="id-A"} 1
example_value_count{environment="beta",id="id-C"} 3

I'm not 100% sure the code for the config.ObjectScrape case is correct - maybe those should default to Untyped?

Signed-off-by: Kyle Allan <kallan357@gmail.com>
@SuperQ
Copy link
Contributor

SuperQ commented Jul 1, 2022

Seems correct, but why are the tests not catching this?

@SuperQ
Copy link
Contributor

SuperQ commented Jul 1, 2022

Oh, I see, there's no valuetype in the test config.

Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll follow up with a fix to the tests.

@SuperQ SuperQ merged commit 83189c5 into prometheus-community:master Jul 1, 2022
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.

2 participants