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?: number[];
/**
* Aggregation Temporality of metric
*/
aggregationTemporality?: AggregationTemporality;
}
export interface BatchObserverOptions {
@ -73,6 +78,13 @@ export enum ValueType {
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
* pre aggregations.

View File

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

View File

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

View File

@ -47,35 +47,12 @@ export function toCollectorLabels(
export function toAggregationTemporality(
metric: MetricRecord
): 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) {
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_UNSPECIFIED;
}
// until spec is resolved keep it as unspecified
if (metric.descriptor.metricKind === MetricKind.VALUE_RECORDER) {
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_CUMULATIVE;
}
return opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_UNSPECIFIED;
return metric.aggregationTemporality;
}
/**

View File

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

View File

@ -574,7 +574,7 @@ export function ensureCounterIsCorrect(
isMonotonic: true,
aggregationTemporality:
collectorTypes.opentelemetryProto.metrics.v1.AggregationTemporality
.AGGREGATION_TEMPORALITY_DELTA,
.AGGREGATION_TEMPORALITY_CUMULATIVE,
},
});
}
@ -599,7 +599,7 @@ export function ensureDoubleCounterIsCorrect(
isMonotonic: true,
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 _descriptor: MetricDescriptor;
protected readonly _boundaries: number[] | undefined;
protected readonly _aggregationTemporality: api.AggregationTemporality;
private readonly _instruments: Map<string, T> = new Map();
constructor(
@ -43,6 +44,10 @@ export abstract class Metric<T extends BaseBoundInstrument>
: api.ValueType.DOUBLE;
this._boundaries = _options.boundaries;
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;
}
getAggregationTemporality() {
return this._aggregationTemporality;
}
getMetricRecord(): Promise<MetricRecord[]> {
return new Promise(resolve => {
resolve(
@ -90,6 +99,7 @@ export abstract class Metric<T extends BaseBoundInstrument>
descriptor: this._descriptor,
labels: instrument.getLabels(),
aggregator: instrument.getAggregator(),
aggregationTemporality: this.getAggregationTemporality(),
resource: this.resource,
instrumentationLibrary: this.instrumentationLibrary,
}))

View File

@ -15,7 +15,11 @@
*/
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 { Resource } from '@opentelemetry/resources';
@ -76,6 +80,7 @@ export interface MetricRecord {
readonly descriptor: MetricDescriptor;
readonly labels: Labels;
readonly aggregator: Aggregator;
readonly aggregationTemporality: AggregationTemporality;
readonly resource: Resource;
readonly instrumentationLibrary: InstrumentationLibrary;
}