Skip to content

Histogram buckets such as .005 or 1e-3 are parsed as 0 or 1 #273

Closed

Description

@RaphaelFakhri

Describe the bug

The buckets parameter of a histogram <metric> converts any value that does not match digits.digits with String#to_i:

e[/\A\d+.\d+\Z/] ? e.to_f : e.to_i

As a result:

  • buckets .005, .01, .025 (the notation used by the default buckets of the Go and Python clients) becomes [0, 0, 0]. Every observation lands in the +Inf bucket, without any error.
  • buckets 1e-3, 1e-2, 0.1 becomes [1, 1, 0.1], and Fluentd fails to start with Unsorted buckets, typo?.
  • A value that is not a number, such as abc, becomes 0 instead of being reported as a configuration error.

To reproduce

<metric>
  name request_seconds
  type histogram
  desc Request duration.
  key duration
  buckets .005, .01, .025
</metric>

Send records with duration 0.007 and read /metrics. All le buckets other than +Inf stay at 0, and the bucket labels are le="0".

Expected behavior

.005 parses as 0.005 and 1e-3 as 0.001. A value that is not a number raises a ConfigError.

Your environment

  • fluent-plugin-prometheus: master (86e7729)
  • Ruby 3.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions