google / google/mtail

Float divide-by-zero silently writes +Inf/NaN to a metric (int errors): intended?

Open
#1,005 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
4k
Forks
392
PR merge metrics
No merged PRs in 30d

Description

Hi! Quick one, is this intended or just an oversight?

Integer divide-by-zero raises a runtime error (drops the line, bumps `prog_runtime_errors_total`), but float divide-by-zero doesn't. It just writes `+Inf`/`NaN` straight into the metric, no error. Same with `%` (`Fmod` gives `NaN`).

```
gauge ratio
/(?P-?\d+)/ {
ratio = 1000.0 / $denom
}
```

Feed it the line `0` and `ratio` comes out `+Inf`, silently. The int version (`1000 / $denom`) errors with `Divide by zero` instead, which is what made me notice.

(`float($x)` also happily takes `"Inf"`/`"NaN"`, so you can get a non-finite metric with no division at all.)

Intended? Happy to send a small PR if not. Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.