Skip to content

Fixing formatting issue with :infinity #22

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akoutmos
Copy link

@akoutmos akoutmos commented Dec 4, 2024

Came across this error today in an app running PromEx:

[error] Task #PID<0.4021.0> started from Whoosh.PromEx.ETSCronFlusher terminating
** (FunctionClauseError) no function clause matching in Peep.Prometheus.format_value/1
    (peep 3.2.0) lib/peep/prometheus.ex:116: Peep.Prometheus.format_value(:infinity)
    (peep 3.2.0) lib/peep/prometheus.ex:93: anonymous fn/2 in Peep.Prometheus.format_standard/2
    ...

And while I am not 100% sure as to how Peep works internally or how :infinity ended up in that value, according to the Prometheus spec +Inf, -Inf, and NaN are all valid values for a metric. This PR just adds support for formatting :infinity -> +Inf values to solve my immediate issue...but not sure what to do about the other two.

@rkallos
Copy link
Owner

rkallos commented Dec 23, 2024

Thank you for your contribution!

If you ever figure it out, I'd be interested to know how :infinity wound up in Peep.

not sure what to do about the other two.

According to this, Erlang will raise a badarith exception instead of returning +Inf, -Inf, or NaN. Elixir inherits this behavior. For now, I think it's fine to avoid implementing those.

It looks like your contribution will fix your issue, but I'm wondering if your issue isn't a symptom of a larger issue. Peep seems to support associating and storing arbitrary Erlang terms with a Telemetry.Metrics.LastValue, which is different from counter, sum, and distribution metrics, which, for one reason or another, only support integers and sometimes floats.

Looking at other libraries for inspiration, I found:

  • TelemetryMetricsPrometheus.Core appears to drop non-numeric measurement values.
  • TelemetryMetrics doesn't outright specify that metrics values should only be numbers, but it's worth noting that the conversion between units only works on numeric values.
  • :telemetry's typespecs suggest that measurements can either be scalar numbers, or a map(), though the documentation does not specify a type for keys or values within a map.

It's my feeling that it would be better to remove support altogether for non-numeric values being associated with Telemetry.Metrics.LastValue metrics, rather than to add the special-case where the atom :infinity is handled appropriately.

What are your thoughts?

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