Skip to content

Commit

Permalink
Log warning if histogram received cdata
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Apr 4, 2024
1 parent 3370f85 commit da81e52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `tnt_election_leader_idle` metric.

- Histogram now logs a warning if `observe` is called with `cdata` value.

## [1.0.0] - 2023-05-22
### Changed

Expand Down
9 changes: 9 additions & 0 deletions metrics/collectors/histogram.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local log = require('log')

local Shared = require('metrics.collectors.shared')
local Counter = require('metrics.collectors.counter')

Expand Down Expand Up @@ -42,11 +44,18 @@ function Histogram:set_registry(registry)
self.bucket_collector:set_registry(registry)
end

local cdata_warning_logged = false

function Histogram:observe(num, label_pairs)
label_pairs = label_pairs or {}
if num ~= nil and type(tonumber(num)) ~= 'number' then
error("Histogram observation should be a number")
end
if not cdata_warning_logged and type(num) == 'cdata' then
log.warn("Histogram observation is cdata. " ..
"Using cdata as observation can lead to unexpected results.")
cdata_warning_logged = true
end

self.count_collector:inc(1, label_pairs)
self.sum_collector:inc(num, label_pairs)
Expand Down

0 comments on commit da81e52

Please sign in to comment.