diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Drop.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Drop.ts index 2ff35d8b86..54ad0ce7ed 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Drop.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Drop.ts @@ -17,7 +17,6 @@ import { HrTime } from '@opentelemetry/api'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { AggregationTemporality } from '../export/AggregationTemporality'; import { MetricData } from '../export/MetricData'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; import { Maybe } from '../utils'; @@ -48,10 +47,8 @@ export class DropAggregator implements Aggregator { _instrumentationLibrary: InstrumentationLibrary, _instrumentDescriptor: InstrumentDescriptor, _accumulationByAttributes: AccumulationRecord[], - _temporality: AggregationTemporality, - _sdkStartTime: HrTime, - _lastCollectionTime: HrTime, - _collectionTime: HrTime): Maybe { + _startTime: HrTime, + _endTime: HrTime): Maybe { return undefined; } } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Histogram.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Histogram.ts index 820f0c4898..fadfc1f303 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Histogram.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Histogram.ts @@ -25,7 +25,6 @@ import { HistogramMetricData, PointDataType } from '../export/MetricData'; import { Resource } from '@opentelemetry/resources'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { HrTime } from '@opentelemetry/api'; -import { AggregationTemporality } from '../export/AggregationTemporality'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; import { Maybe } from '../utils'; @@ -143,10 +142,8 @@ export class HistogramAggregator implements Aggregator { instrumentationLibrary: InstrumentationLibrary, metricDescriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord[], - temporality: AggregationTemporality, - sdkStartTime: HrTime, - lastCollectionTime: HrTime, - collectionTime: HrTime): Maybe { + startTime: HrTime, + endTime: HrTime): Maybe { return { resource, instrumentationLibrary, @@ -155,8 +152,8 @@ export class HistogramAggregator implements Aggregator { pointData: accumulationByAttributes.map(([attributes, accumulation]) => { return { attributes, - startTime: temporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime, - endTime: collectionTime, + startTime, + endTime, point: accumulation.toPoint(), } }) diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/LastValue.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/LastValue.ts index fb86c26d0b..2ed5b93817 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/LastValue.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/LastValue.ts @@ -18,7 +18,6 @@ import { LastValue, AggregatorKind, Aggregator, Accumulation, AccumulationRecord import { HrTime } from '@opentelemetry/api'; import { hrTime, hrTimeToMicroseconds, InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { AggregationTemporality } from '../export/AggregationTemporality'; import { PointDataType, SingularMetricData } from '../export/MetricData'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; import { Maybe } from '../utils'; @@ -72,10 +71,8 @@ export class LastValueAggregator implements Aggregator { instrumentationLibrary: InstrumentationLibrary, instrumentDescriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord[], - temporality: AggregationTemporality, - sdkStartTime: HrTime, - lastCollectionTime: HrTime, - collectionTime: HrTime): Maybe { + startTime: HrTime, + endTime: HrTime): Maybe { return { resource, instrumentationLibrary, @@ -84,8 +81,8 @@ export class LastValueAggregator implements Aggregator { pointData: accumulationByAttributes.map(([attributes, accumulation]) => { return { attributes, - startTime: temporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime, - endTime: collectionTime, + startTime, + endTime, point: accumulation.toPoint(), } }) diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Sum.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Sum.ts index 081ccf802e..28cb68f77c 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Sum.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/Sum.ts @@ -19,7 +19,6 @@ import { HrTime } from '@opentelemetry/api'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { PointDataType, SingularMetricData } from '../export/MetricData'; -import { AggregationTemporality } from '../export/AggregationTemporality'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; import { Maybe } from '../utils'; @@ -62,10 +61,8 @@ export class SumAggregator implements Aggregator { instrumentationLibrary: InstrumentationLibrary, instrumentDescriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord[], - temporality: AggregationTemporality, - sdkStartTime: HrTime, - lastCollectionTime: HrTime, - collectionTime: HrTime): Maybe { + startTime: HrTime, + endTime: HrTime): Maybe { return { resource, instrumentationLibrary, @@ -74,8 +71,8 @@ export class SumAggregator implements Aggregator { pointData: accumulationByAttributes.map(([attributes, accumulation]) => { return { attributes, - startTime: temporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime, - endTime: collectionTime, + startTime, + endTime, point: accumulation.toPoint(), } }) diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/types.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/types.ts index 8a8e689792..28d20a634e 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/types.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/aggregator/types.ts @@ -18,7 +18,6 @@ import { HrTime } from '@opentelemetry/api'; import { Attributes } from '@opentelemetry/api-metrics'; import { InstrumentationLibrary } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; -import { AggregationTemporality } from '../export/AggregationTemporality'; import { MetricData } from '../export/MetricData'; import { InstrumentDescriptor } from '../InstrumentDescriptor'; import { Maybe } from '../utils'; @@ -113,18 +112,14 @@ export interface Aggregator { * @param instrumentationLibrary the library that instrumented the metric * @param instrumentDescriptor the metric instrument descriptor. * @param accumulationByAttributes the array of attributes and accumulation pairs. - * @param temporality the temporality of the accumulation. - * @param sdkStartTime the start time of the sdk. - * @param lastCollectionTime the last collection time of the instrument. - * @param collectionTime the active collection time of the instrument. + * @param startTime the start time of the metric data. + * @param endTime the end time of the metric data. * @return the {@link MetricData} that this {@link Aggregator} will produce. */ toMetricData(resource: Resource, instrumentationLibrary: InstrumentationLibrary, instrumentDescriptor: InstrumentDescriptor, accumulationByAttributes: AccumulationRecord[], - temporality: AggregationTemporality, - sdkStartTime: HrTime, - lastCollectionTime: HrTime, - collectionTime: HrTime): Maybe; + startTime: HrTime, + endTime: HrTime): Maybe; } diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts index f7154469dd..1853adc8e5 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/src/state/TemporalMetricProcessor.ts @@ -107,7 +107,7 @@ export class TemporalMetricProcessor { collectionTime, }); - // Metric data time span is determined in Aggregator.toMetricData with aggregation temporality: + // Metric data time span is determined as: // 1. Cumulative Aggregation time span: (sdkStartTime, collectionTime] // 2. Delta Aggregation time span: (lastCollectionTime, collectionTime] return this._aggregator.toMetricData( @@ -115,10 +115,8 @@ export class TemporalMetricProcessor { instrumentationLibrary, instrumentDescriptor, AttributesMapToAccumulationRecords(result), - aggregationTemporality, - sdkStartTime, - lastCollectionTime, - collectionTime); + /* startTime */ aggregationTemporality === AggregationTemporality.CUMULATIVE ? sdkStartTime : lastCollectionTime, + /* endTime */ collectionTime); } private _stashAccumulations(collectors: MetricCollectorHandle[], currentAccumulation: AttributeHashMap) { diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Drop.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Drop.test.ts index bc264cc8f8..4d12e38511 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Drop.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Drop.test.ts @@ -17,7 +17,6 @@ import { HrTime } from '@opentelemetry/api'; import * as assert from 'assert'; import { DropAggregator } from '../../src/aggregator'; -import { AggregationTemporality } from '../../src/export/AggregationTemporality'; import { defaultInstrumentationLibrary, defaultInstrumentDescriptor, defaultResource } from '../util'; describe('DropAggregator', () => { @@ -51,19 +50,16 @@ describe('DropAggregator', () => { it('no exceptions', () => { const aggregator = new DropAggregator(); - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; + const startTime: HrTime = [0, 0]; + const endTime: HrTime = [1, 1]; assert.strictEqual(aggregator.toMetricData( defaultResource, defaultInstrumentationLibrary, defaultInstrumentDescriptor, [[{}, undefined]], - AggregationTemporality.DELTA, - sdkStartTime, - lastCollectionTime, - collectionTime, + startTime, + endTime, ), undefined); }); }); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Histogram.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Histogram.test.ts index 21ba31b848..2af44dc804 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Histogram.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Histogram.test.ts @@ -17,7 +17,6 @@ import { HrTime } from '@opentelemetry/api'; import * as assert from 'assert'; import { HistogramAccumulation, HistogramAggregator } from '../../src/aggregator'; -import { AggregationTemporality } from '../../src/export/AggregationTemporality'; import { MetricData, PointDataType } from '../../src/export/MetricData'; import { commonValues, defaultInstrumentationLibrary, defaultInstrumentDescriptor, defaultResource } from '../util'; @@ -82,16 +81,15 @@ describe('HistogramAggregator', () => { }); describe('toMetricData', () => { - it('transform with AggregationTemporality.DELTA', () => { + it('transform without exception', () => { const aggregator = new HistogramAggregator([1, 10, 100]); const accumulation = aggregator.createAccumulation(); accumulation.record(0); accumulation.record(1); - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; + const startTime: HrTime = [0, 0]; + const endTime: HrTime = [1, 1]; const expected: MetricData = { resource: defaultResource, @@ -101,8 +99,8 @@ describe('HistogramAggregator', () => { pointData: [ { attributes: {}, - startTime: lastCollectionTime, - endTime: collectionTime, + startTime, + endTime, point: { buckets: { boundaries: [1, 10, 100], @@ -119,54 +117,8 @@ describe('HistogramAggregator', () => { defaultInstrumentationLibrary, defaultInstrumentDescriptor, [[{}, accumulation]], - AggregationTemporality.DELTA, - sdkStartTime, - lastCollectionTime, - collectionTime, - ), expected); - }); - - it('transform with AggregationTemporality.CUMULATIVE', () => { - const aggregator = new HistogramAggregator([1, 10, 100]); - - const accumulation = aggregator.createAccumulation(); - accumulation.record(0); - accumulation.record(1); - - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; - - const expected: MetricData = { - resource: defaultResource, - instrumentationLibrary: defaultInstrumentationLibrary, - instrumentDescriptor: defaultInstrumentDescriptor, - pointDataType: PointDataType.HISTOGRAM, - pointData: [ - { - attributes: {}, - startTime: sdkStartTime, - endTime: collectionTime, - point: { - buckets: { - boundaries: [1, 10, 100], - counts: [1, 1, 0, 0], - }, - count: 2, - sum: 1, - }, - }, - ], - }; - assert.deepStrictEqual(aggregator.toMetricData( - defaultResource, - defaultInstrumentationLibrary, - defaultInstrumentDescriptor, - [[{}, accumulation]], - AggregationTemporality.CUMULATIVE, - sdkStartTime, - lastCollectionTime, - collectionTime, + startTime, + endTime, ), expected); }); }); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/LastValue.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/LastValue.test.ts index 1f6017f3af..5b7ec19e91 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/LastValue.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/LastValue.test.ts @@ -17,7 +17,6 @@ import { HrTime } from '@opentelemetry/api'; import * as assert from 'assert'; import { LastValueAccumulation, LastValueAggregator } from '../../src/aggregator'; -import { AggregationTemporality } from '../../src/export/AggregationTemporality'; import { MetricData, PointDataType } from '../../src/export/MetricData'; import { commonValues, defaultInstrumentationLibrary, defaultInstrumentDescriptor, defaultResource, sleep } from '../util'; @@ -88,7 +87,7 @@ describe('LastValueAggregator', () => { }); describe('toMetricData', () => { - it('transform with AggregationTemporality.DELTA', () => { + it('transform without exception', () => { const aggregator = new LastValueAggregator(); const accumulation = aggregator.createAccumulation(); @@ -97,9 +96,8 @@ describe('LastValueAggregator', () => { accumulation.record(1); accumulation.record(4); - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; + const startTime: HrTime = [0, 0]; + const endTime: HrTime = [1, 1]; const expected: MetricData = { resource: defaultResource, @@ -109,8 +107,8 @@ describe('LastValueAggregator', () => { pointData: [ { attributes: {}, - startTime: lastCollectionTime, - endTime: collectionTime, + startTime, + endTime, point: 4, }, ], @@ -120,48 +118,8 @@ describe('LastValueAggregator', () => { defaultInstrumentationLibrary, defaultInstrumentDescriptor, [[{}, accumulation]], - AggregationTemporality.DELTA, - sdkStartTime, - lastCollectionTime, - collectionTime, - ), expected); - }); - - it('transform with AggregationTemporality.CUMULATIVE', () => { - const aggregator = new LastValueAggregator(); - - const accumulation = aggregator.createAccumulation(); - accumulation.record(1); - accumulation.record(2); - accumulation.record(1); - - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; - - const expected: MetricData = { - resource: defaultResource, - instrumentationLibrary: defaultInstrumentationLibrary, - instrumentDescriptor: defaultInstrumentDescriptor, - pointDataType: PointDataType.SINGULAR, - pointData: [ - { - attributes: {}, - startTime: sdkStartTime, - endTime: collectionTime, - point: 1, - }, - ], - }; - assert.deepStrictEqual(aggregator.toMetricData( - defaultResource, - defaultInstrumentationLibrary, - defaultInstrumentDescriptor, - [[{}, accumulation]], - AggregationTemporality.CUMULATIVE, - sdkStartTime, - lastCollectionTime, - collectionTime, + startTime, + endTime, ), expected); }); }); diff --git a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Sum.test.ts b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Sum.test.ts index 99db9b2712..26c322ebdc 100644 --- a/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Sum.test.ts +++ b/experimental/packages/opentelemetry-sdk-metrics-base/test/aggregator/Sum.test.ts @@ -17,7 +17,6 @@ import { HrTime } from '@opentelemetry/api'; import * as assert from 'assert'; import { SumAccumulation, SumAggregator } from '../../src/aggregator'; -import { AggregationTemporality } from '../../src/export/AggregationTemporality'; import { MetricData, PointDataType } from '../../src/export/MetricData'; import { commonValues, defaultInstrumentationLibrary, defaultInstrumentDescriptor, defaultResource } from '../util'; @@ -69,15 +68,14 @@ describe('SumAggregator', () => { }); describe('toMetricData', () => { - it('transform with AggregationTemporality.DELTA', () => { + it('transform without exception', () => { const aggregator = new SumAggregator(); const accumulation = aggregator.createAccumulation(); accumulation.record(1); accumulation.record(2); - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; + const startTime: HrTime = [0, 0]; + const endTime: HrTime = [1, 1]; const expected: MetricData = { resource: defaultResource, @@ -87,8 +85,8 @@ describe('SumAggregator', () => { pointData: [ { attributes: {}, - startTime: lastCollectionTime, - endTime: collectionTime, + startTime, + endTime, point: 3, }, ], @@ -98,46 +96,8 @@ describe('SumAggregator', () => { defaultInstrumentationLibrary, defaultInstrumentDescriptor, [[{}, accumulation]], - AggregationTemporality.DELTA, - sdkStartTime, - lastCollectionTime, - collectionTime, - ), expected); - }); - - it('transform with AggregationTemporality.CUMULATIVE', () => { - const aggregator = new SumAggregator(); - const accumulation = aggregator.createAccumulation(); - accumulation.record(1); - accumulation.record(2); - - const sdkStartTime: HrTime = [0, 0]; - const lastCollectionTime: HrTime = [1, 1]; - const collectionTime: HrTime = [2, 2]; - - const expected: MetricData = { - resource: defaultResource, - instrumentationLibrary: defaultInstrumentationLibrary, - instrumentDescriptor: defaultInstrumentDescriptor, - pointDataType: PointDataType.SINGULAR, - pointData: [ - { - attributes: {}, - startTime: sdkStartTime, - endTime: collectionTime, - point: 3, - }, - ], - }; - assert.deepStrictEqual(aggregator.toMetricData( - defaultResource, - defaultInstrumentationLibrary, - defaultInstrumentDescriptor, - [[{}, accumulation]], - AggregationTemporality.CUMULATIVE, - sdkStartTime, - lastCollectionTime, - collectionTime, + startTime, + endTime, ), expected); }); });