diff --git a/CHANGELOG.md b/CHANGELOG.md index 1872e964..49f5b760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- metrics.clear() disables default metrics ## [0.5.0] - 2020-09-18 ### Added diff --git a/metrics/utils.lua b/metrics/utils.lua index 5b7c4c74..b04aa75b 100644 --- a/metrics/utils.lua +++ b/metrics/utils.lua @@ -1,7 +1,5 @@ local metrics = require('metrics') -local gauges_storage = {} - local TNT_PREFIX = 'tnt_' local function prefix_name(name) @@ -9,14 +7,10 @@ local function prefix_name(name) end local function set_gauge(name, description, value, labels) - if (gauges_storage[name] == nil) then - gauges_storage[name] = metrics.gauge(prefix_name(name), description) - end - - gauges_storage[name]:set(value, labels or {}) + local gauge = metrics.gauge(prefix_name(name), description) + gauge:set(value, labels or {}) end - local function box_is_configured() return type(box.cfg) ~= 'function' end @@ -25,4 +19,4 @@ return { set_gauge = set_gauge, box_is_configured = box_is_configured, prefix_name = prefix_name, -} \ No newline at end of file +} diff --git a/test/default_metrics_test.lua b/test/default_metrics_test.lua new file mode 100644 index 00000000..40a853b5 --- /dev/null +++ b/test/default_metrics_test.lua @@ -0,0 +1,34 @@ +#!/usr/bin/env tarantool + +require('strict').on() + +local t = require('luatest') +local g = t.group('default_metrics') + +local metrics = require('metrics') + +g.before_all(function() + box.cfg{} + metrics.clear() +end) + +g.after_each(function() + -- Delete all collectors and global labels + metrics.clear() +end) + +g.test_default_metrics_clear = function() + metrics.clear() + metrics.enable_default_metrics() + t.assert_equals(#metrics.collect(), 0) + + metrics.invoke_callbacks() + t.assert(#metrics.collect() > 0) + + metrics.clear() + t.assert_equals(#metrics.collect(), 0) + + metrics.enable_default_metrics() + metrics.invoke_callbacks() + t.assert(#metrics.collect() > 0) +end