Skip to content

Commit

Permalink
feat(sdk-metrics-base): update exporting names (#2829)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
  • Loading branch information
legendecas and vmarchaud authored Mar 21, 2022
1 parent 70dc60b commit 3fd1b1e
Show file tree
Hide file tree
Showing 22 changed files with 305 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class SyncInstrument {
/**
* The class implements {@link metrics.UpDownCounter} interface.
*/
export class UpDownCounter extends SyncInstrument implements metrics.UpDownCounter {
export class UpDownCounterInstrument extends SyncInstrument implements metrics.UpDownCounter {
/**
* Increment value of counter by the input. Inputs may be negative.
*/
Expand All @@ -52,7 +52,7 @@ export class UpDownCounter extends SyncInstrument implements metrics.UpDownCount
/**
* The class implements {@link metrics.Counter} interface.
*/
export class Counter extends SyncInstrument implements metrics.Counter {
export class CounterInstrument extends SyncInstrument implements metrics.Counter {
/**
* Increment value of counter by the input. Inputs may not be negative.
*/
Expand All @@ -69,7 +69,7 @@ export class Counter extends SyncInstrument implements metrics.Counter {
/**
* The class implements {@link metrics.Histogram} interface.
*/
export class Histogram extends SyncInstrument implements metrics.Histogram {
export class HistogramInstrument extends SyncInstrument implements metrics.Histogram {
/**
* Records a measurement. Value of the measurement must not be negative.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as metrics from '@opentelemetry/api-metrics-wip';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { createInstrumentDescriptor, InstrumentDescriptor, InstrumentType } from './InstrumentDescriptor';
import { Counter, Histogram, UpDownCounter } from './Instruments';
import { CounterInstrument, HistogramInstrument, UpDownCounterInstrument } from './Instruments';
import { MeterProviderSharedState } from './state/MeterProviderSharedState';
import { MultiMetricStorage } from './state/MultiWritableMetricStorage';
import { SyncMetricStorage } from './state/SyncMetricStorage';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class Meter implements metrics.Meter {
createHistogram(name: string, options?: metrics.HistogramOptions): metrics.Histogram {
const descriptor = createInstrumentDescriptor(name, InstrumentType.HISTOGRAM, options);
const storage = this._registerMetricStorage(descriptor);
return new Histogram(storage, descriptor);
return new HistogramInstrument(storage, descriptor);
}

/**
Expand All @@ -54,7 +54,7 @@ export class Meter implements metrics.Meter {
createCounter(name: string, options?: metrics.CounterOptions): metrics.Counter {
const descriptor = createInstrumentDescriptor(name, InstrumentType.COUNTER, options);
const storage = this._registerMetricStorage(descriptor);
return new Counter(storage, descriptor);
return new CounterInstrument(storage, descriptor);
}

/**
Expand All @@ -63,7 +63,7 @@ export class Meter implements metrics.Meter {
createUpDownCounter(name: string, options?: metrics.UpDownCounterOptions): metrics.UpDownCounter {
const descriptor = createInstrumentDescriptor(name, InstrumentType.UP_DOWN_COUNTER, options);
const storage = this._registerMetricStorage(descriptor);
return new UpDownCounter(storage, descriptor);
return new UpDownCounterInstrument(storage, descriptor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DropAggregator implements Aggregator<undefined> {
}

toMetricData(
_instrumentDescriptor: InstrumentDescriptor,
_descriptor: InstrumentDescriptor,
_accumulationByAttributes: AccumulationRecord<undefined>[],
_startTime: HrTime,
_endTime: HrTime): Maybe<MetricData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
AggregatorKind,
Histogram,
} from './types';
import { HistogramMetricData, PointDataType } from '../export/MetricData';
import { HistogramMetricData, DataPointType } from '../export/MetricData';
import { HrTime } from '@opentelemetry/api';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class HistogramAccumulation implements Accumulation {
this._current.buckets.counts[this._boundaries.length] += 1;
}

toPoint(): Histogram {
toPointValue(): Histogram {
return this._current;
}
}
Expand Down Expand Up @@ -89,66 +89,66 @@ export class HistogramAggregator implements Aggregator<HistogramAccumulation> {
* merging accumulations with different boundaries.
*/
merge(previous: HistogramAccumulation, delta: HistogramAccumulation): HistogramAccumulation {
const previousPoint = previous.toPoint();
const deltaPoint = delta.toPoint();
const previousValue = previous.toPointValue();
const deltaValue = delta.toPointValue();

const previousCounts = previousPoint.buckets.counts;
const deltaCounts = deltaPoint.buckets.counts;
const previousCounts = previousValue.buckets.counts;
const deltaCounts = deltaValue.buckets.counts;

const mergedCounts = new Array(previousCounts.length);
for (let idx = 0; idx < previousCounts.length; idx++) {
mergedCounts[idx] = previousCounts[idx] + deltaCounts[idx];
}

return new HistogramAccumulation(previousPoint.buckets.boundaries, {
return new HistogramAccumulation(previousValue.buckets.boundaries, {
buckets: {
boundaries: previousPoint.buckets.boundaries,
boundaries: previousValue.buckets.boundaries,
counts: mergedCounts,
},
count: previousPoint.count + deltaPoint.count,
sum: previousPoint.sum + deltaPoint.sum,
count: previousValue.count + deltaValue.count,
sum: previousValue.sum + deltaValue.sum,
});
}

/**
* Returns a new DELTA aggregation by comparing two cumulative measurements.
*/
diff(previous: HistogramAccumulation, current: HistogramAccumulation): HistogramAccumulation {
const previousPoint = previous.toPoint();
const currentPoint = current.toPoint();
const previousValue = previous.toPointValue();
const currentValue = current.toPointValue();

const previousCounts = previousPoint.buckets.counts;
const currentCounts = currentPoint.buckets.counts;
const previousCounts = previousValue.buckets.counts;
const currentCounts = currentValue.buckets.counts;

const diffedCounts = new Array(previousCounts.length);
for (let idx = 0; idx < previousCounts.length; idx++) {
diffedCounts[idx] = currentCounts[idx] - previousCounts[idx];
}

return new HistogramAccumulation(previousPoint.buckets.boundaries, {
return new HistogramAccumulation(previousValue.buckets.boundaries, {
buckets: {
boundaries: previousPoint.buckets.boundaries,
boundaries: previousValue.buckets.boundaries,
counts: diffedCounts,
},
count: currentPoint.count - previousPoint.count,
sum: currentPoint.sum - previousPoint.sum,
count: currentValue.count - previousValue.count,
sum: currentValue.sum - previousValue.sum,
});
}

toMetricData(
metricDescriptor: InstrumentDescriptor,
descriptor: InstrumentDescriptor,
accumulationByAttributes: AccumulationRecord<HistogramAccumulation>[],
startTime: HrTime,
endTime: HrTime): Maybe<HistogramMetricData> {
return {
instrumentDescriptor: metricDescriptor,
pointDataType: PointDataType.HISTOGRAM,
pointData: accumulationByAttributes.map(([attributes, accumulation]) => {
descriptor,
dataPointType: DataPointType.HISTOGRAM,
dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {
return {
attributes,
startTime,
endTime,
point: accumulation.toPoint(),
value: accumulation.toPointValue(),
};
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { LastValue, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';
import { HrTime } from '@opentelemetry/api';
import { hrTime, hrTimeToMicroseconds } from '@opentelemetry/core';
import { PointDataType, SingularMetricData } from '../export/MetricData';
import { DataPointType, SingularMetricData } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';

Expand All @@ -29,7 +29,7 @@ export class LastValueAccumulation implements Accumulation {
this.sampleTime = hrTime();
}

toPoint(): LastValue {
toPointValue(): LastValue {
return this._current;
}
}
Expand All @@ -50,7 +50,7 @@ export class LastValueAggregator implements Aggregator<LastValueAccumulation> {
merge(previous: LastValueAccumulation, delta: LastValueAccumulation): LastValueAccumulation {
// nanoseconds may lose precisions.
const latestAccumulation = hrTimeToMicroseconds(delta.sampleTime) >= hrTimeToMicroseconds(previous.sampleTime) ? delta : previous;
return new LastValueAccumulation(latestAccumulation.toPoint(), latestAccumulation.sampleTime);
return new LastValueAccumulation(latestAccumulation.toPointValue(), latestAccumulation.sampleTime);
}

/**
Expand All @@ -62,23 +62,23 @@ export class LastValueAggregator implements Aggregator<LastValueAccumulation> {
diff(previous: LastValueAccumulation, current: LastValueAccumulation): LastValueAccumulation {
// nanoseconds may lose precisions.
const latestAccumulation = hrTimeToMicroseconds(current.sampleTime) >= hrTimeToMicroseconds(previous.sampleTime) ? current : previous;
return new LastValueAccumulation(latestAccumulation.toPoint(), latestAccumulation.sampleTime);
return new LastValueAccumulation(latestAccumulation.toPointValue(), latestAccumulation.sampleTime);
}

toMetricData(
instrumentDescriptor: InstrumentDescriptor,
descriptor: InstrumentDescriptor,
accumulationByAttributes: AccumulationRecord<LastValueAccumulation>[],
startTime: HrTime,
endTime: HrTime): Maybe<SingularMetricData> {
return {
instrumentDescriptor,
pointDataType: PointDataType.SINGULAR,
pointData: accumulationByAttributes.map(([attributes, accumulation]) => {
descriptor,
dataPointType: DataPointType.SINGULAR,
dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {
return {
attributes,
startTime,
endTime,
point: accumulation.toPoint(),
value: accumulation.toPointValue(),
};
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Sum, AggregatorKind, Aggregator, Accumulation, AccumulationRecord } from './types';
import { HrTime } from '@opentelemetry/api';
import { PointDataType, SingularMetricData } from '../export/MetricData';
import { DataPointType, SingularMetricData } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';

Expand All @@ -27,7 +27,7 @@ export class SumAccumulation implements Accumulation {
this._current += value;
}

toPoint(): Sum {
toPointValue(): Sum {
return this._current;
}
}
Expand All @@ -44,30 +44,30 @@ export class SumAggregator implements Aggregator<SumAccumulation> {
* Returns the result of the merge of the given accumulations.
*/
merge(previous: SumAccumulation, delta: SumAccumulation): SumAccumulation {
return new SumAccumulation(previous.toPoint() + delta.toPoint());
return new SumAccumulation(previous.toPointValue() + delta.toPointValue());
}

/**
* Returns a new DELTA aggregation by comparing two cumulative measurements.
*/
diff(previous: SumAccumulation, current: SumAccumulation): SumAccumulation {
return new SumAccumulation(current.toPoint() - previous.toPoint());
return new SumAccumulation(current.toPointValue() - previous.toPointValue());
}

toMetricData(
instrumentDescriptor: InstrumentDescriptor,
descriptor: InstrumentDescriptor,
accumulationByAttributes: AccumulationRecord<SumAccumulation>[],
startTime: HrTime,
endTime: HrTime): Maybe<SingularMetricData> {
return {
instrumentDescriptor,
pointDataType: PointDataType.SINGULAR,
pointData: accumulationByAttributes.map(([attributes, accumulation]) => {
descriptor,
dataPointType: DataPointType.SINGULAR,
dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {
return {
attributes,
startTime,
endTime,
point: accumulation.toPoint(),
value: accumulation.toPointValue(),
};
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export enum AggregatorKind {
HISTOGRAM,
}

/** Point type for SumAggregation. */
/** DataPoint value type for SumAggregation. */
export type Sum = number;

/** Point type for LastValueAggregation. */
/** DataPoint value type for LastValueAggregation. */
export type LastValue = number;

/** Point type for HistogramAggregation. */
/** DataPoint value type for HistogramAggregation. */
export interface Histogram {
/**
* Buckets are implemented using two different arrays:
Expand Down Expand Up @@ -106,15 +106,13 @@ export interface Aggregator<T> {
/**
* Returns the {@link MetricData} that this {@link Aggregator} will produce.
*
* @param resource the resource producing the metric.
* @param instrumentationLibrary the library that instrumented the metric
* @param instrumentDescriptor the metric instrument descriptor.
* @param descriptor the metric instrument descriptor.
* @param accumulationByAttributes the array of attributes and accumulation pairs.
* @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(instrumentDescriptor: InstrumentDescriptor,
toMetricData(descriptor: InstrumentDescriptor,
accumulationByAttributes: AccumulationRecord<T>[],
startTime: HrTime,
endTime: HrTime): Maybe<MetricData>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ import { Histogram } from '../aggregator/types';
* Basic metric data fields.
*/
export interface BaseMetricData {
readonly instrumentDescriptor: InstrumentDescriptor;
readonly descriptor: InstrumentDescriptor;
/**
* PointDataType of the metric instrument.
* DataPointType of the metric instrument.
*/
readonly pointDataType: PointDataType;
readonly dataPointType: DataPointType;
}

/**
* Represents a metric data aggregated by either a LastValueAggregation or
* SumAggregation.
*/
export interface SingularMetricData extends BaseMetricData {
readonly pointDataType: PointDataType.SINGULAR;
readonly pointData: PointData<number>[];
readonly dataPointType: DataPointType.SINGULAR;
readonly dataPoints: DataPoint<number>[];
}

/**
* Represents a metric data aggregated by a HistogramAggregation.
*/
export interface HistogramMetricData extends BaseMetricData {
readonly pointDataType: PointDataType.HISTOGRAM;
readonly pointData: PointData<Histogram>[];
readonly dataPointType: DataPointType.HISTOGRAM;
readonly dataPoints: DataPoint<Histogram>[];
}

/**
Expand All @@ -67,7 +67,7 @@ export interface ResourceMetrics {
/**
* The aggregated point data type.
*/
export enum PointDataType {
export enum DataPointType {
SINGULAR,
HISTOGRAM,
EXPONENTIAL_HISTOGRAM,
Expand All @@ -77,9 +77,9 @@ export enum PointDataType {
* Represents an aggregated point data with start time, end time and their
* associated attributes and points.
*/
export interface PointData<T> {
export interface DataPoint<T> {
/**
* The start epoch timestamp of the PointData, usually the time when
* The start epoch timestamp of the DataPoint, usually the time when
* the metric was created when the preferred AggregationTemporality is
* CUMULATIVE, or last collection time otherwise.
*/
Expand All @@ -90,11 +90,11 @@ export interface PointData<T> {
*/
readonly endTime: HrTime;
/**
* The attributes associated with this PointData.
* The attributes associated with this DataPoint.
*/
readonly attributes: Attributes;
/**
* The data points for this metric.
* The value for this DataPoint.
*/
readonly point: T;
readonly value: T;
}
Loading

0 comments on commit 3fd1b1e

Please sign in to comment.