-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(console-metric-exporter): add temporality configuration #3387
feat(console-metric-exporter): add temporality configuration #3387
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3387 +/- ##
==========================================
+ Coverage 92.43% 93.26% +0.82%
==========================================
Files 240 247 +7
Lines 6871 7346 +475
Branches 1422 1512 +90
==========================================
+ Hits 6351 6851 +500
+ Misses 520 495 -25
|
dc45af9
to
5e6d2ff
Compare
5e6d2ff
to
d914b4b
Compare
describe('export', () => { | ||
let previousConsoleDir: any; | ||
let exporter: ConsoleMetricExporter; | ||
let meterProvider: MeterProvider; | ||
let meterReader: PeriodicExportingMetricReader; | ||
let meter: metrics.Meter; | ||
|
||
beforeEach(() => { | ||
previousConsoleDir = console.dir; | ||
console.dir = () => {}; | ||
|
||
exporter = new ConsoleMetricExporter(); | ||
meterProvider = new MeterProvider({ resource: defaultResource }); | ||
meter = meterProvider.getMeter('ConsoleMetricExporter', '1.0.0'); | ||
meterReader = new PeriodicExportingMetricReader({ | ||
exporter: exporter, | ||
exportIntervalMillis: 100, | ||
exportTimeoutMillis: 100 | ||
}); | ||
meterProvider.addMetricReader(meterReader); | ||
}); | ||
meterProvider.addMetricReader(meterReader); | ||
}); | ||
|
||
afterEach(async () => { | ||
console.dir = previousConsoleDir; | ||
afterEach(async () => { | ||
console.dir = previousConsoleDir; | ||
|
||
await meterReader.shutdown(); | ||
}); | ||
|
||
it('should export information about metric', async () => { | ||
const counter = meter.createCounter('counter_total', { | ||
description: 'a test description', | ||
}); | ||
const counterAttribute = { key1: 'attributeValue1' }; | ||
counter.add(10, counterAttribute); | ||
counter.add(10, counterAttribute); | ||
|
||
const histogram = meter.createHistogram('histogram', { description: 'a histogram' }); | ||
histogram.record(10); | ||
histogram.record(100); | ||
histogram.record(1000); | ||
|
||
const spyConsole = sinon.spy(console, 'dir'); | ||
const spyExport = sinon.spy(exporter, 'export'); | ||
|
||
await waitForNumberOfExports(spyExport, 1); | ||
const resourceMetrics = spyExport.args[0]; | ||
const firstResourceMetric = resourceMetrics[0]; | ||
const consoleArgs = spyConsole.args[0]; | ||
const consoleMetric = consoleArgs[0]; | ||
const keys = Object.keys(consoleMetric).sort().join(','); | ||
|
||
await meterReader.shutdown(); | ||
const expectedKeys = [ | ||
'dataPointType', | ||
'dataPoints', | ||
'descriptor', | ||
].join(','); | ||
|
||
assert.ok(firstResourceMetric.resource.attributes.resourceKey === 'my-resource', 'resourceKey'); | ||
assert.ok(keys === expectedKeys, 'expectedKeys'); | ||
assert.ok(consoleMetric.descriptor.name === 'counter_total', 'name'); | ||
assert.ok(consoleMetric.descriptor.description === 'a test description', 'description'); | ||
assert.ok(consoleMetric.descriptor.type === 'COUNTER', 'type'); | ||
assert.ok(consoleMetric.descriptor.unit === '', 'unit'); | ||
assert.ok(consoleMetric.descriptor.valueType === 1, 'valueType'); | ||
assert.ok(consoleMetric.dataPoints[0].attributes.key1 === 'attributeValue1', 'ensure metric attributes exists'); | ||
|
||
assert.ok(spyExport.calledOnce); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code here is not new and has only been moved into a new describe
block, as the setup is not needed for the tests that I added.
Looks good. Seems like this just logs directly the data structure as it comes from the SDK so no real "logic" changes required. All temporality except selection is handled by the SDK |
Which problem is this PR solving?
As pointed out by @reyang
Originally posted by @reyang in open-telemetry/community#1204 (comment)
Fixes #3395
Short description of the changes
This PR adds configuration options to allow for both DELTA and CUMULATIVE preference in the
ConsoleMetricExporter
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: