-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove zero count metrics from registry (#2163)
* feat: no longer sends counting metrics with a count of zero and removes them from the metrics cache/registry Closes: #1977
- Loading branch information
Showing
4 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const tape = require('tape') | ||
const MetricsReporter = require('../../lib/metrics/reporter') | ||
|
||
function createMockRegistry (fnGenerateStorageKey, fnDelete) { | ||
return { | ||
_generateStorageKey: fnGenerateStorageKey, | ||
_metrics: { | ||
delete: fnDelete | ||
} | ||
} | ||
} | ||
|
||
tape.test('Unit Tests: isStaleMetric and removeMetricFromRegistry', function (t) { | ||
t.test('isStaleMetric', function (t) { | ||
const reg = new MetricsReporter({}) | ||
|
||
t.ok(reg.isStaleMetric({ metricImpl: { _count: 0 } }, '_count 0 is stale')) | ||
t.ok(!reg.isStaleMetric({ metricImpl: {} }, 'no _count property is not stale')) | ||
t.ok(!reg.isStaleMetric({ metricImpl: { _count: 1 } }, 'non-zero values not stale')) | ||
t.ok(!reg.isStaleMetric({ metricImpl: { _count: false } }, 'non-zero values not stale')) | ||
t.ok(!reg.isStaleMetric({ metricImpl: { _count: '' } }, 'non-zero values not stale')) | ||
t.ok(!reg.isStaleMetric({ metricImpl: { _count: null } }, 'non-zero values not stale')) | ||
t.ok(!reg.isStaleMetric({ metricImpl: { _count: undefined } }, 'non-zero values not stale')) | ||
t.ok(!reg.isStaleMetric({}), 'value without metricImpl does not explode') | ||
|
||
t.end() | ||
}) | ||
|
||
t.test('removeMetricFromRegistry functionality', function (t) { | ||
const reg = new MetricsReporter({}) | ||
reg._registry = createMockRegistry( | ||
function generateStorageKey (name, dimensions) { | ||
return JSON.stringify(name) + JSON.stringify(dimensions) | ||
}, | ||
function metricsDelete (key) { | ||
t.equals(key, '"foo"["bar"]', 'requested deletion of correct key') | ||
t.end() | ||
} | ||
) | ||
|
||
reg.removeMetricFromRegistry({ | ||
name: 'foo', | ||
dimensions: ['bar'] | ||
}) | ||
}) | ||
|
||
t.test('removeMetricFromRegistry invalid types', function (t) { | ||
const reg = new MetricsReporter({}) | ||
|
||
t.ok(!reg.removeMetricFromRegistry(), 'call with empty object does not explode') | ||
|
||
reg._registry = {} | ||
t.ok(!reg.removeMetricFromRegistry(), 'call with invalid registry does not explode') | ||
|
||
t.end() | ||
}) | ||
}) |