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

WIP: Feature/value on counter #96

Merged
merged 10 commits into from
May 6, 2020

Conversation

Skeen
Copy link
Contributor

@Skeen Skeen commented Apr 21, 2020

This PR introduces adds an optional configuration field to the counter metric type, namely the value template field, also seen on the gauge.

It enables counting up with more than one, a motivating example could be for instance counting time spent or bytes ingested, both of which are monotonically increasing, and thus not will fit as gauges.

The PR has several commits;

  • 050c2e5 renames two callbacks from cb to callback for consistency.
  • 877a386 prepares for support for the counter, by allowing the callbacks to reject samples, specifically to reject floats which are negative for the counter. The change is made throughout to support future needs for late sample rejection.
  • cdba743 changes the counter into an observeMetric and changes configuration to allow for the value key.
  • 25314da updates the documentation, such that the optional field of value is reflected for the counter metric.

@Skeen
Copy link
Contributor Author

Skeen commented Apr 21, 2020

I have tested the change using:

global:
  config_version: 3
input:
  type: webhook
  webhook_path: /webhook
  webhook_format: json_single
  webhook_json_selector: .message
  webhook_text_bulk_separator: "\n\n"
imports:
- type: grok_patterns
  dir: ./logstash-patterns-core/patterns
metrics:
- type: counter
  name: bytes_processed
  help: Total number of bytes processed
  match: '%{NUMBER:bytes} bytes processed'
  value: '{{ .bytes }}'
server:
  host: "[::]"
  port: 9144

Started as:

go run grok_exporter.go -config example/config_counter_val.yml

With the following log messages being posted:

curl localhost:9144/webhook --data '{"message": "5 bytes processed"}'

And this as output:

# HELP bytes_processed Total number of bytes processed
# TYPE bytes_processed counter
bytes_processed 5

Leaving out value: '{{ .bytes }}', in the configuration and running the rest the same way, yields:

# HELP bytes_processed Total number of bytes processed
# TYPE bytes_processed counter
bytes_processed 1

As expected for backwards compatability.

@Skeen
Copy link
Contributor Author

Skeen commented Apr 21, 2020

Assuming this is something you'll consider merging, I will fix the broken tests, get the build to succeed, and then remove the WIP: prefix on the PR.

@fstab
Copy link
Owner

fstab commented Apr 21, 2020

Thanks a lot for the PR! Yes, aligning counter and gauge sounds like a good idea. Please go ahead with fixing the tests.

Just a heads up: Some tests in tailer are flaky, so you don't need to fix them if their failure has nothing to do with your changes.

@coveralls
Copy link

coveralls commented Apr 22, 2020

Coverage Status

Coverage decreased (-0.1%) to 67.135% when pulling 4eddad3 on magenta-aps:feature/value_on_counter into 1c7e020 on fstab:master.

@Skeen
Copy link
Contributor Author

Skeen commented Apr 30, 2020

Hi,

Do you want me to duplicate the value test from the guage metric for the counter metric, to test out the value configuration key-word and default of 1? - or do you think it is good as is?

Copy link
Owner

@fstab fstab left a comment

Choose a reason for hiding this comment

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

I added a few minor comments, apart from that it's looking good.

exporter/metrics.go Outdated Show resolved Hide resolved
exporter/metrics.go Outdated Show resolved Hide resolved
exporter/metrics_test.go Show resolved Hide resolved
exporter/metrics.go Outdated Show resolved Hide resolved
@fstab
Copy link
Owner

fstab commented Apr 30, 2020

Hi,

Do you want me to duplicate the value test from the guage metric for the counter metric, to test out the value configuration key-word and default of 1? - or do you think it is good as is?

Yes, that would be good. Sounds like overkill because it's just copy-and-paste, but on the other hand it's an easy addition and it might prevent a bug in the future if someone refactors the counter but forgets that it might have a value.

@Skeen
Copy link
Contributor Author

Skeen commented May 1, 2020

Hi,
Do you want me to duplicate the value test from the guage metric for the counter metric, to test out the value configuration key-word and default of 1? - or do you think it is good as is?

Yes, that would be good. Sounds like overkill because it's just copy-and-paste, but on the other hand it's an easy addition and it might prevent a bug in the future if someone refactors the counter but forgets that it might have a value.

I added a test, in 487bcf4.

@Skeen Skeen force-pushed the feature/value_on_counter branch from 3722d12 to 487bcf4 Compare May 1, 2020 09:40
@Skeen Skeen force-pushed the feature/value_on_counter branch from c674dc0 to 4eddad3 Compare May 5, 2020 08:45
@Skeen
Copy link
Contributor Author

Skeen commented May 6, 2020

@fstab will you take a last look at this, and see if you deem it okay, or if there's more you'd like me to do?

@fstab fstab merged commit 1aa59d4 into fstab:master May 6, 2020
@fstab
Copy link
Owner

fstab commented May 6, 2020

Thanks a lot!

@Skeen Skeen deleted the feature/value_on_counter branch May 6, 2020 21:03
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.

3 participants