Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 @@ -141,14 +141,14 @@ export class HistogramAggregator implements Aggregator<HistogramAccumulation> {
startTime: HrTime,
endTime: HrTime): Maybe<HistogramMetricData> {
return {
instrumentDescriptor: metricDescriptor,
pointDataType: PointDataType.HISTOGRAM,
pointData: accumulationByAttributes.map(([attributes, accumulation]) => {
descriptor: metricDescriptor,
dataPointType: DataPointType.HISTOGRAM,
dataPoints: accumulationByAttributes.map(([attributes, accumulation]) => {
return {
attributes,
startTime,
endTime,
point: accumulation.toPoint(),
value: accumulation.toPoint(),
};
})
};
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 Down Expand Up @@ -66,19 +66,19 @@ export class LastValueAggregator implements Aggregator<LastValueAccumulation> {
}

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.toPoint(),
};
})
};
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 Down Expand Up @@ -55,19 +55,19 @@ export class SumAggregator implements Aggregator<SumAccumulation> {
}

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.toPoint(),
};
})
};
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

export { Histogram } from './aggregator/types';
export * from './export/AggregationTemporality';
export * from './export/MetricData';
export * from './export/MetricExporter';
Expand All @@ -26,3 +27,4 @@ export * from './Meter';
export * from './MeterProvider';
export * from './ObservableResult';
export { TimeoutError } from './utils';
export * from './view/Aggregation';
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ export class LastValueAggregation extends Aggregation {
* The default histogram aggregation.
*/
export class HistogramAggregation extends Aggregation {
private static DEFAULT_INSTANCE = new HistogramAggregator([0, 5, 10, 25, 50, 75, 100, 250, 500, 1000]);
private DEFAULT_INSTANCE: HistogramAggregator;
constructor(boundaries: number[] = [0, 5, 10, 25, 50, 75, 100, 250, 500, 1000]) {
super();
this.DEFAULT_INSTANCE = new HistogramAggregator(boundaries);
}

createAggregator(_instrument: InstrumentDescriptor) {
return HistogramAggregation.DEFAULT_INSTANCE;
return this.DEFAULT_INSTANCE;
}
}

Expand Down
Loading