From c50ce59cce0521b97ee677064da99bca171ca390 Mon Sep 17 00:00:00 2001 From: Igor Zolotarev Date: Thu, 4 Apr 2024 09:50:44 +0300 Subject: [PATCH] Log warning if histogram received cdata --- CHANGELOG.md | 6 ++++++ metrics/collectors/histogram.lua | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e85e3baa..a682cea1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,12 @@ 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. + +### Deprecated + +- Using `cdata` values with `histogram:observe`. + ## [1.0.0] - 2023-05-22 ### Changed diff --git a/metrics/collectors/histogram.lua b/metrics/collectors/histogram.lua index 2e4b7575..708df755 100644 --- a/metrics/collectors/histogram.lua +++ b/metrics/collectors/histogram.lua @@ -1,3 +1,5 @@ +local log = require('log') + local Shared = require('metrics.collectors.shared') local Counter = require('metrics.collectors.counter') @@ -42,11 +44,19 @@ 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("Using cdata as observation in historgam " .. + "can lead to unexpected results. " .. + "That log message will be an error in the future.") + cdata_warning_logged = true + end self.count_collector:inc(1, label_pairs) self.sum_collector:inc(num, label_pairs)