From e6fbbc2961f836ce252647efe470c569a3cdde69 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Mon, 11 Apr 2022 09:59:41 -0400 Subject: [PATCH 1/4] onweek work --- lib/agent.js | 4 ++++ lib/metrics/reporter.js | 14 ++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 00ee26561e1..5470d88b05a 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -684,3 +684,7 @@ Agent.prototype.registerMetric = function (name, labelsOrCallback, callback) { this._metrics.getOrCreateGauge(name, callback, labels) } + +Agent.prototype.registerMetricCounter = function (name, dimensions) { + return this._metrics.getOrCreateCounter(name, dimensions); +} diff --git a/lib/metrics/reporter.js b/lib/metrics/reporter.js index 93e1dc68b02..3399d3743de 100644 --- a/lib/metrics/reporter.js +++ b/lib/metrics/reporter.js @@ -31,10 +31,11 @@ class MetricsReporter extends Reporter { // due to `metricsLimit` leave empty slots in the list. if (!metric) continue - if (this.isStaleMetric(metric)) { - this.removeMetricFromRegistry(metric, this._registry) - continue - } + // TODO: make this configurable + // if (this.isStaleMetric(metric)) { + // this.removeMetricFromRegistry(metric, this._registry) + // continue + // } const data = seen.ensure(metric.dimensions, () => { const metricData = unflattenBreakdown(metric.dimensions) @@ -46,10 +47,6 @@ class MetricsReporter extends Reporter { data.samples[metric.name] = { value: metric.metricImpl.toJSON() } - - if (metric.metricImpl.constructor.name === 'Counter') { - metric.metricImpl.reset() - } } if (this._agent._transport) { @@ -59,6 +56,7 @@ class MetricsReporter extends Reporter { } }) + for (const collector of this._registry.collectors) { collector.collect(next()) } From 53fe605dc3e956cbc438dc08c852156f30b3dbb6 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Thu, 14 Apr 2022 11:01:49 -0400 Subject: [PATCH 2/4] Clean up --- lib/agent.js | 2 +- lib/metrics/reporter.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index 5470d88b05a..ff75e37d990 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -686,5 +686,5 @@ Agent.prototype.registerMetric = function (name, labelsOrCallback, callback) { } Agent.prototype.registerMetricCounter = function (name, dimensions) { - return this._metrics.getOrCreateCounter(name, dimensions); + return this._metrics.getOrCreateCounter(name, dimensions) } diff --git a/lib/metrics/reporter.js b/lib/metrics/reporter.js index 3399d3743de..15595abd468 100644 --- a/lib/metrics/reporter.js +++ b/lib/metrics/reporter.js @@ -31,11 +31,10 @@ class MetricsReporter extends Reporter { // due to `metricsLimit` leave empty slots in the list. if (!metric) continue - // TODO: make this configurable - // if (this.isStaleMetric(metric)) { - // this.removeMetricFromRegistry(metric, this._registry) - // continue - // } + if (this.isStaleMetric(metric)) { + this.removeMetricFromRegistry(metric, this._registry) + continue + } const data = seen.ensure(metric.dimensions, () => { const metricData = unflattenBreakdown(metric.dimensions) @@ -56,7 +55,6 @@ class MetricsReporter extends Reporter { } }) - for (const collector of this._registry.collectors) { collector.collect(next()) } @@ -66,6 +64,11 @@ class MetricsReporter extends Reporter { // if a metric is a counting metric and that count is // zero, then the metric is considered stale if (metric.metricImpl && metric.metricImpl._count === 0) { + // We need a way to avoid ignoring metrics that might go stale + // because we want values for each counter to appear in every document + // This is not a great check but there does not seem to be a way + // to provide meta data about a metric to enable to better check + if (metric.name.startsWith('kibana')) return false return true } return false From 448986bdd69e7d819723bf71e119a0e1ae4e60cc Mon Sep 17 00:00:00 2001 From: chrisronline Date: Thu, 14 Apr 2022 11:03:18 -0400 Subject: [PATCH 3/4] bring this back --- lib/metrics/reporter.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/metrics/reporter.js b/lib/metrics/reporter.js index 15595abd468..2d7786efa1a 100644 --- a/lib/metrics/reporter.js +++ b/lib/metrics/reporter.js @@ -43,6 +43,16 @@ class MetricsReporter extends Reporter { return merged }) + if (metric.metricImpl.constructor.name === 'Counter') { + // We need a way to avoid ignoring metrics that might go stale + // because we want values for each counter to appear in every document + // This is not a great check but there does not seem to be a way + // to provide meta data about a metric to enable to better check + if (!metric.name.startsWith('kibana')) { + metric.metricImpl.reset() + } + } + data.samples[metric.name] = { value: metric.metricImpl.toJSON() } From eb2295871aa7c3a49988a46ae9c3414127a49a2c Mon Sep 17 00:00:00 2001 From: chrisronline Date: Thu, 14 Apr 2022 11:04:24 -0400 Subject: [PATCH 4/4] match better --- lib/metrics/reporter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/metrics/reporter.js b/lib/metrics/reporter.js index 2d7786efa1a..cfec4ccd0d0 100644 --- a/lib/metrics/reporter.js +++ b/lib/metrics/reporter.js @@ -43,6 +43,10 @@ class MetricsReporter extends Reporter { return merged }) + data.samples[metric.name] = { + value: metric.metricImpl.toJSON() + } + if (metric.metricImpl.constructor.name === 'Counter') { // We need a way to avoid ignoring metrics that might go stale // because we want values for each counter to appear in every document @@ -52,10 +56,6 @@ class MetricsReporter extends Reporter { metric.metricImpl.reset() } } - - data.samples[metric.name] = { - value: metric.metricImpl.toJSON() - } } if (this._agent._transport) {