chore(deps): support cumulative, delta, and pass-through exporters (#2118)

Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
This commit is contained in:
Sergey Lanzman 2021-04-26 21:56:45 +03:00 committed by GitHub
parent d504f32a18
commit b9c842613c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 29 deletions

View File

@ -58,6 +58,11 @@ export interface MetricOptions {
* Boundaries optional for histogram * Boundaries optional for histogram
*/ */
boundaries?: number[]; boundaries?: number[];
/**
* Aggregation Temporality of metric
*/
aggregationTemporality?: AggregationTemporality;
} }
export interface BatchObserverOptions { export interface BatchObserverOptions {
@ -73,6 +78,13 @@ export enum ValueType {
DOUBLE, DOUBLE,
} }
/** The kind of aggregator. */
export enum AggregationTemporality {
AGGREGATION_TEMPORALITY_UNSPECIFIED,
AGGREGATION_TEMPORALITY_DELTA,
AGGREGATION_TEMPORALITY_CUMULATIVE,
}
/** /**
* Metric represents a base class for different types of metric * Metric represents a base class for different types of metric
* pre aggregations. * pre aggregations.

View File

@ -343,7 +343,7 @@ export function ensureExportedCounterIsCorrect(
}, },
], ],
isMonotonic: true, isMonotonic: true,
aggregationTemporality: 'AGGREGATION_TEMPORALITY_DELTA', aggregationTemporality: 'AGGREGATION_TEMPORALITY_CUMULATIVE',
}, },
}); });
} }

View File

@ -308,7 +308,7 @@ export function ensureExportedCounterIsCorrect(
}, },
], ],
isMonotonic: true, isMonotonic: true,
aggregationTemporality: 'AGGREGATION_TEMPORALITY_DELTA', aggregationTemporality: 'AGGREGATION_TEMPORALITY_CUMULATIVE',
}, },
}); });
} }

View File

@ -47,35 +47,12 @@ export function toCollectorLabels(
export function toAggregationTemporality( export function toAggregationTemporality(
metric: MetricRecord metric: MetricRecord
): opentelemetryProto.metrics.v1.AggregationTemporality { ): opentelemetryProto.metrics.v1.AggregationTemporality {
if (
metric.descriptor.metricKind === MetricKind.COUNTER ||
metric.descriptor.metricKind === MetricKind.UP_DOWN_COUNTER
) {
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_DELTA;
}
if (
metric.descriptor.metricKind === MetricKind.SUM_OBSERVER ||
metric.descriptor.metricKind === MetricKind.UP_DOWN_SUM_OBSERVER
) {
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_CUMULATIVE;
}
if (metric.descriptor.metricKind === MetricKind.VALUE_OBSERVER) { if (metric.descriptor.metricKind === MetricKind.VALUE_OBSERVER) {
return opentelemetryProto.metrics.v1.AggregationTemporality return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_UNSPECIFIED; .AGGREGATION_TEMPORALITY_UNSPECIFIED;
} }
// until spec is resolved keep it as unspecified return metric.aggregationTemporality;
if (metric.descriptor.metricKind === MetricKind.VALUE_RECORDER) {
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_CUMULATIVE;
}
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_UNSPECIFIED;
} }
/** /**

View File

@ -171,6 +171,7 @@ describe('transformMetrics', () => {
labels: { foo: (1 as unknown) as string }, labels: { foo: (1 as unknown) as string },
aggregator: new SumAggregator(), aggregator: new SumAggregator(),
resource: new Resource({}), resource: new Resource({}),
aggregationTemporality: 0,
instrumentationLibrary: { name: 'x', version: 'y' }, instrumentationLibrary: { name: 'x', version: 'y' },
}, },
1592602232694000000 1592602232694000000

View File

@ -574,7 +574,7 @@ export function ensureCounterIsCorrect(
isMonotonic: true, isMonotonic: true,
aggregationTemporality: aggregationTemporality:
collectorTypes.opentelemetryProto.metrics.v1.AggregationTemporality collectorTypes.opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_DELTA, .AGGREGATION_TEMPORALITY_CUMULATIVE,
}, },
}); });
} }
@ -599,7 +599,7 @@ export function ensureDoubleCounterIsCorrect(
isMonotonic: true, isMonotonic: true,
aggregationTemporality: aggregationTemporality:
collectorTypes.opentelemetryProto.metrics.v1.AggregationTemporality collectorTypes.opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_DELTA, .AGGREGATION_TEMPORALITY_CUMULATIVE,
}, },
}); });
} }

View File

@ -27,6 +27,7 @@ export abstract class Metric<T extends BaseBoundInstrument>
protected readonly _valueType: api.ValueType; protected readonly _valueType: api.ValueType;
protected readonly _descriptor: MetricDescriptor; protected readonly _descriptor: MetricDescriptor;
protected readonly _boundaries: number[] | undefined; protected readonly _boundaries: number[] | undefined;
protected readonly _aggregationTemporality: api.AggregationTemporality;
private readonly _instruments: Map<string, T> = new Map(); private readonly _instruments: Map<string, T> = new Map();
constructor( constructor(
@ -43,6 +44,10 @@ export abstract class Metric<T extends BaseBoundInstrument>
: api.ValueType.DOUBLE; : api.ValueType.DOUBLE;
this._boundaries = _options.boundaries; this._boundaries = _options.boundaries;
this._descriptor = this._getMetricDescriptor(); this._descriptor = this._getMetricDescriptor();
this._aggregationTemporality =
_options.aggregationTemporality === undefined
? api.AggregationTemporality.AGGREGATION_TEMPORALITY_CUMULATIVE
: _options.aggregationTemporality;
} }
/** /**
@ -83,6 +88,10 @@ export abstract class Metric<T extends BaseBoundInstrument>
return this._kind; return this._kind;
} }
getAggregationTemporality() {
return this._aggregationTemporality;
}
getMetricRecord(): Promise<MetricRecord[]> { getMetricRecord(): Promise<MetricRecord[]> {
return new Promise(resolve => { return new Promise(resolve => {
resolve( resolve(
@ -90,6 +99,7 @@ export abstract class Metric<T extends BaseBoundInstrument>
descriptor: this._descriptor, descriptor: this._descriptor,
labels: instrument.getLabels(), labels: instrument.getLabels(),
aggregator: instrument.getAggregator(), aggregator: instrument.getAggregator(),
aggregationTemporality: this.getAggregationTemporality(),
resource: this.resource, resource: this.resource,
instrumentationLibrary: this.instrumentationLibrary, instrumentationLibrary: this.instrumentationLibrary,
})) }))

View File

@ -15,7 +15,11 @@
*/ */
import { HrTime } from '@opentelemetry/api'; import { HrTime } from '@opentelemetry/api';
import { Labels, ValueType } from '@opentelemetry/api-metrics'; import {
Labels,
AggregationTemporality,
ValueType,
} from '@opentelemetry/api-metrics';
import { ExportResult, InstrumentationLibrary } from '@opentelemetry/core'; import { ExportResult, InstrumentationLibrary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources'; import { Resource } from '@opentelemetry/resources';
@ -76,6 +80,7 @@ export interface MetricRecord {
readonly descriptor: MetricDescriptor; readonly descriptor: MetricDescriptor;
readonly labels: Labels; readonly labels: Labels;
readonly aggregator: Aggregator; readonly aggregator: Aggregator;
readonly aggregationTemporality: AggregationTemporality;
readonly resource: Resource; readonly resource: Resource;
readonly instrumentationLibrary: InstrumentationLibrary; readonly instrumentationLibrary: InstrumentationLibrary;
} }