Skip to content

feat(sdk-metrics)!: drop View and Aggregation for options #4931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* feat(sdk-metrics)!: remove MeterProvider.addMetricReader() in favor of constructor option [#4419](https://github.com/open-telemetry/opentelemetry-js/pull/4419) @pichlermarc
* feat(sdk-metrics)!: replace attributeKeys with custom processors option [#4532](https://github.com/open-telemetry/opentelemetry-js/pull/4532) @pichlermarc
* refactor(sdk-trace-base)!: replace `SpanAttributes` with `Attributes` [#5009](https://github.com/open-telemetry/opentelemetry-js/pull/5009) @david-luna
* feat(sdk-metrics)!: drop `View` and `Aggregation` in favor of `ViewOptions` and `AggregationOption` [#4931](https://github.com/open-telemetry/opentelemetry-js/pull/4931) @pichlermarc

### :rocket: (Enhancement)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import * as assert from 'assert';
import * as grpc from '@grpc/grpc-js';
import { VERSION } from '@opentelemetry/core';
import {
ExplicitBucketHistogramAggregation,
AggregationType,
MeterProvider,
MetricReader,
View,
} from '@opentelemetry/sdk-metrics';
import {
encodeAsString,
Expand Down Expand Up @@ -72,10 +71,13 @@ export function setUp() {
meterProvider = new MeterProvider({
resource: testResource,
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 100]),
{
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: { boundaries: [0, 100] },
},
instrumentName: 'int-histogram',
}),
},
],
readers: [reader],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
InstrumentType,
PushMetricExporter,
ResourceMetrics,
Aggregation,
AggregationSelector,
AggregationOption,
AggregationType,
} from '@opentelemetry/sdk-metrics';
import {
AggregationTemporalityPreference,
Expand Down Expand Up @@ -113,7 +114,11 @@
if (config?.aggregationPreference) {
return config.aggregationPreference;
} else {
return (_instrumentType: any) => Aggregation.Default();
return (_instrumentType: any) => {
return {

Check warning on line 118 in experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts

View check run for this annotation

Codecov / codecov/patch

experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/OTLPMetricExporterBase.ts#L118

Added line #L118 was not covered by tests
type: AggregationType.DEFAULT,
};
};
}
}

Expand Down Expand Up @@ -148,7 +153,7 @@
return Promise.resolve();
}

selectAggregation(instrumentType: InstrumentType): Aggregation {
selectAggregation(instrumentType: InstrumentType): AggregationOption {
return this._aggregationSelector(instrumentType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import { InstrumentationScope, VERSION } from '@opentelemetry/core';
import {
ExplicitBucketHistogramAggregation,
AggregationType,
MeterProvider,
MetricReader,
View,
ViewOptions,
} from '@opentelemetry/sdk-metrics';
import {
encodeAsString,
Expand Down Expand Up @@ -59,10 +59,15 @@ class TestMetricReader extends MetricReader {
}
}

export const HISTOGRAM_AGGREGATION_VIEW = new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 100]),
export const HISTOGRAM_AGGREGATION_VIEW: ViewOptions = {
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: {
boundaries: [0, 100],
},
},
instrumentName: 'int-histogram',
});
};

const defaultResource = Resource.default().merge(
new Resource({
Expand All @@ -83,7 +88,7 @@ export async function collect() {
return (await reader.collect())!;
}

export function setUp(views?: View[]) {
export function setUp(views?: ViewOptions[]) {
reader = new TestMetricReader();
meterProvider = new MeterProvider({
resource: defaultResource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import {
} from '../metricsHelper';
import { MockedResponse } from './nodeHelpers';
import {
Aggregation,
AggregationOption,
AggregationTemporality,
ExplicitBucketHistogramAggregation,
AggregationType,
InstrumentType,
ResourceMetrics,
} from '@opentelemetry/sdk-metrics';
Expand Down Expand Up @@ -225,9 +225,13 @@ describe('OTLPMetricExporter - node with json over http', () => {

describe('aggregation', () => {
it('aggregationSelector calls the selector supplied to the constructor', () => {
const aggregation = new ExplicitBucketHistogramAggregation([
0, 100, 100000,
]);
const aggregation: AggregationOption = {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: {
boundaries: [0, 100, 100000],
},
};

const exporter = new OTLPMetricExporter({
aggregationPreference: _instrumentType => aggregation,
});
Expand All @@ -239,11 +243,15 @@ describe('OTLPMetricExporter - node with json over http', () => {

it('aggregationSelector returns the default aggregation preference when nothing is supplied', () => {
const exporter = new OTLPMetricExporter({
aggregationPreference: _instrumentType => Aggregation.Default(),
aggregationPreference: _instrumentType => {
return { type: AggregationType.DEFAULT };
},
});
assert.equal(
assert.deepStrictEqual(
exporter.selectAggregation(InstrumentType.COUNTER),
Aggregation.Default()
{
type: AggregationType.DEFAULT,
}
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import {
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import {
ExplicitBucketHistogramAggregation,
AggregationType,
MeterProvider,
MetricReader,
View,
} from '@opentelemetry/sdk-metrics';
import {
encodeAsString,
Expand Down Expand Up @@ -71,10 +70,13 @@ export function setUp() {
meterProvider = new MeterProvider({
resource: testResource,
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 100]),
{
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: { boundaries: [0, 100] },
},
instrumentName: 'int-histogram',
}),
},
],
readers: [reader],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { diag } from '@opentelemetry/api';
import { globalErrorHandler } from '@opentelemetry/core';
import {
Aggregation,
AggregationTemporality,
AggregationType,
MetricReader,
} from '@opentelemetry/sdk-metrics';
import { createServer, IncomingMessage, Server, ServerResponse } from 'http';
Expand Down Expand Up @@ -60,7 +60,11 @@ export class PrometheusExporter extends MetricReader {
callback: (error: Error | void) => void = () => {}
) {
super({
aggregationSelector: _instrumentType => Aggregation.Default(),
aggregationSelector: _instrumentType => {
return {
type: AggregationType.DEFAULT,
};
},
aggregationTemporalitySelector: _instrumentType =>
AggregationTemporality.CUMULATIVE,
metricProducers: config.metricProducers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
import * as assert from 'assert';
import { Attributes, UpDownCounter } from '@opentelemetry/api';
import {
Aggregation,
AggregationTemporality,
DataPoint,
DataPointType,
ExplicitBucketHistogramAggregation,
Histogram,
LastValueAggregation,
MeterProvider,
MetricReader,
SumAggregation,
View,
} from '@opentelemetry/sdk-metrics';
import * as sinon from 'sinon';
import { PrometheusSerializer } from '../src';
Expand All @@ -40,6 +35,7 @@ import {
serviceName,
} from './util';
import { Resource } from '@opentelemetry/resources';
import { AggregationType } from '@opentelemetry/sdk-metrics';

const attributes = {
foo1: 'bar1',
Expand All @@ -56,7 +52,9 @@ class TestMetricReader extends MetricReader {
super({
aggregationTemporalitySelector: _instrumentType =>
AggregationTemporality.CUMULATIVE,
aggregationSelector: _instrumentType => Aggregation.Default(),
aggregationSelector: _instrumentType => {
return { type: AggregationType.DEFAULT };
},
});
}

Expand Down Expand Up @@ -86,10 +84,10 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new SumAggregation(),
{
aggregation: { type: AggregationType.SUM },
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -136,10 +134,15 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([1, 10, 100]),
{
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: {
boundaries: [1, 10, 100],
},
},
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -201,10 +204,10 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new SumAggregation(),
{
aggregation: { type: AggregationType.SUM },
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -256,10 +259,10 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new SumAggregation(),
{
aggregation: { type: AggregationType.SUM },
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -310,10 +313,12 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new LastValueAggregation(),
{
aggregation: {
type: AggregationType.LAST_VALUE,
},
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -364,10 +369,13 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([1, 10, 100]),
{
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: { boundaries: [1, 10, 100] },
},
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -419,10 +427,13 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([1, 10, 100]),
{
aggregation: {
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
options: { boundaries: [1, 10, 100] },
},
instrumentName: '*',
}),
},
],
readers: [reader],
});
Expand Down Expand Up @@ -472,7 +483,10 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({ aggregation: new SumAggregation(), instrumentName: '*' }),
{
aggregation: { type: AggregationType.SUM },
instrumentName: '*',
},
],
readers: [reader],
});
Expand Down Expand Up @@ -561,7 +575,10 @@ describe('PrometheusSerializer', () => {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [
new View({ aggregation: new SumAggregation(), instrumentName: '*' }),
{
aggregation: { type: AggregationType.SUM },
instrumentName: '*',
},
],
readers: [reader],
});
Expand Down
Loading
Loading