Skip to content

Commit

Permalink
Merge branch 'main' into feat/basic-tp-extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Jul 20, 2022
2 parents 61d43d5 + 1e8b896 commit ea6dd7e
Show file tree
Hide file tree
Showing 42 changed files with 934 additions and 600 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
with:
node-version: ${{ matrix.node_version }}

- run: npm install -g npm@latest

- name: restore lerna
id: cache
uses: actions/cache@v3
Expand Down
9 changes: 9 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ All notable changes to experimental packages in this project will be documented

### :boom: Breaking Change

* feature(views): move views registration to MeterProvider constructor [#3066](https://github.com/open-telemetry/opentelemetry-js/pull/3066) @pichlermarc
* feat(sdk-metrics-base): split up Singular into Sum and Gauge in MetricData [#3079](https://github.com/open-telemetry/opentelemetry-js/pull/3079) @pichlermarc
* removes `DataPointType.SINGULAR`, and replaces it with `DataPointType.SUM` and `DataPointType.GAUGE`
* removes `SingularMetricData` and replaces it with `SumMetricData` (including an additional `isMonotonic` flag) and `GaugeMetricData`

### :rocket: (Enhancement)

* feat(otlp-proto): pre-compile proto files [#3098](https://github.com/open-telemetry/opentelemetry-js/pull/3098) @legendecas

### :bug: (Bug Fix)

* fix(histogram): fix maximum when only values < -1 are provided [#3086](https://github.com/open-telemetry/opentelemetry-js/pull/3086) @pichlermarc

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
MockedResponse,
} from './traceHelper';
import { CompressionAlgorithm, OTLPExporterNodeConfigBase, OTLPExporterError } from '@opentelemetry/otlp-exporter-base';
import { getExportRequestProto } from '@opentelemetry/otlp-proto-exporter-base';
import { getExportRequestProto, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base';
import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';

let fakeRequest: PassThrough;
Expand Down Expand Up @@ -208,8 +208,8 @@ describe('OTLPTraceExporter - node with proto over http', () => {

let buff = Buffer.from('');
fakeRequest.on('end', () => {
const ExportTraceServiceRequestProto = getExportRequestProto();
const data = ExportTraceServiceRequestProto?.decode(buff);
const ExportTraceServiceRequestProto = getExportRequestProto(ServiceClientType.SPANS);
const data = ExportTraceServiceRequestProto.decode(buff);
const json = data?.toJSON() as IExportTraceServiceRequest;
const span1 = json.resourceSpans?.[0].scopeSpans?.[0].spans?.[0];
assert.ok(typeof span1 !== 'undefined', "span doesn't exist");
Expand Down Expand Up @@ -294,8 +294,8 @@ describe('OTLPTraceExporter - node with proto over http', () => {
let buff = Buffer.from('');
fakeRequest.on('end', () => {
const unzippedBuff = zlib.gunzipSync(buff);
const ExportTraceServiceRequestProto = getExportRequestProto();
const data = ExportTraceServiceRequestProto?.decode(unzippedBuff);
const ExportTraceServiceRequestProto = getExportRequestProto(ServiceClientType.SPANS);
const data = ExportTraceServiceRequestProto.decode(unzippedBuff);
const json = data?.toJSON() as IExportTraceServiceRequest;
const span1 = json.resourceSpans?.[0].scopeSpans?.[0].spans?.[0];
assert.ok(typeof span1 !== 'undefined', "span doesn't exist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ExplicitBucketHistogramAggregation,
MeterProvider,
MetricReader,
View,
} from '@opentelemetry/sdk-metrics-base';
import { IKeyValue, IMetric, IResource } from '@opentelemetry/otlp-transformer';

Expand Down Expand Up @@ -59,7 +60,15 @@ export async function collect() {
}

export function setUp() {
meterProvider = new MeterProvider({ resource: testResource });
meterProvider = new MeterProvider({
resource: testResource,
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 100]),
instrumentName: 'int-histogram',
})
]
});
reader = new TestMetricReader();
meterProvider.addMetricReader(
reader
Expand Down Expand Up @@ -96,10 +105,7 @@ export function mockObservableGauge(
}

export function mockHistogram(): Histogram {
const name = 'int-histogram';
meterProvider.addView({ aggregation: new ExplicitBucketHistogramAggregation([0, 100]) });

return meter.createHistogram(name, {
return meter.createHistogram('int-histogram', {
description: 'sample histogram description',
valueType: ValueType.INT,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ensureExportMetricsServiceRequestIsSet, ensureHeadersContain,
ensureHistogramIsCorrect,
ensureObservableGaugeIsCorrect,
ensureWebResourceIsCorrect,
ensureWebResourceIsCorrect, HISTOGRAM_AGGREGATION_VIEW,
mockCounter,
mockHistogram,
mockObservableGauge,
Expand All @@ -47,7 +47,7 @@ describe('OTLPMetricExporter - web', () => {
let errorStub: sinon.SinonStub;

beforeEach(async () => {
setUp();
setUp([HISTOGRAM_AGGREGATION_VIEW]);
stubOpen = sinon.stub(XMLHttpRequest.prototype, 'open');
sinon.stub(XMLHttpRequest.prototype, 'send');
stubBeacon = sinon.stub(navigator, 'sendBeacon');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
AggregationTemporality,
ExplicitBucketHistogramAggregation,
MeterProvider,
MetricReader
MetricReader,
View
} from '@opentelemetry/sdk-metrics-base';
import {
IExportMetricsServiceRequest,
Expand Down Expand Up @@ -61,6 +62,11 @@ class TestMetricReader extends MetricReader {
}
}

export const HISTOGRAM_AGGREGATION_VIEW = new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 100]),
instrumentName: 'int-histogram',
});

const defaultResource = Resource.default().merge(new Resource({
service: 'ui',
version: 1,
Expand All @@ -78,8 +84,8 @@ export async function collect() {
return (await reader.collect())!;
}

export function setUp() {
meterProvider = new MeterProvider({ resource: defaultResource });
export function setUp(views?: View[]) {
meterProvider = new MeterProvider({ resource: defaultResource, views });
reader = new TestMetricReader();
meterProvider.addMetricReader(
reader
Expand Down Expand Up @@ -124,7 +130,6 @@ export function mockDoubleCounter(): Counter {
}



export function mockObservableCounter(
callback: (observableResult: ObservableResult) => void,
name = 'double-observable-counter'
Expand Down Expand Up @@ -158,18 +163,7 @@ export function mockObservableUpDownCounter(
}

export function mockHistogram(): Histogram {
const name = 'int-histogram';

meterProvider.addView({
aggregation: new ExplicitBucketHistogramAggregation([0, 100])
},
{
instrument: {
name: name
}
});

return meter.createHistogram(name, {
return meter.createHistogram('int-histogram', {
description: 'sample histogram description',
valueType: ValueType.INT,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
mockCounter,
mockObservableGauge,
mockHistogram,
collect, shutdown, setUp,
collect,
shutdown,
setUp,
HISTOGRAM_AGGREGATION_VIEW,
} from '../metricsHelper';
import { MockedResponse } from './nodeHelpers';
import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metrics-base';
Expand All @@ -54,7 +57,7 @@ describe('OTLPMetricExporter - node with json over http', () => {
let metrics: ResourceMetrics;

beforeEach(async () => {
setUp();
setUp([HISTOGRAM_AGGREGATION_VIEW]);
});

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { diag } from '@opentelemetry/api';
import { ExportResultCode } from '@opentelemetry/core';
import { getExportRequestProto } from '@opentelemetry/otlp-proto-exporter-base';
import { getExportRequestProto, ServiceClientType } from '@opentelemetry/otlp-proto-exporter-base';
import * as assert from 'assert';
import * as http from 'http';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -236,8 +236,8 @@ describe('OTLPMetricExporter - node with proto over http', () => {
let buff = Buffer.from('');

fakeRequest.on('end', () => {
const ExportTraceServiceRequestProto = getExportRequestProto();
const data = ExportTraceServiceRequestProto?.decode(buff);
const ExportTraceServiceRequestProto = getExportRequestProto(ServiceClientType.METRICS);
const data = ExportTraceServiceRequestProto.decode(buff);
const json = data?.toJSON() as IExportMetricsServiceRequest;

const metric1 = json.resourceMetrics[0].scopeMetrics[0].metrics[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
AggregationTemporality,
ExplicitBucketHistogramAggregation,
MeterProvider,
MetricReader
MetricReader,
View
} from '@opentelemetry/sdk-metrics-base';
import { IExportMetricsServiceRequest, IKeyValue, IMetric } from '@opentelemetry/otlp-transformer';
import { Stream } from 'stream';
Expand Down Expand Up @@ -64,7 +65,15 @@ export async function collect() {
}

export function setUp() {
meterProvider = new MeterProvider({ resource: testResource });
meterProvider = new MeterProvider({
resource: testResource,
views: [
new View({
aggregation: new ExplicitBucketHistogramAggregation([0, 100]),
instrumentName: 'int-histogram',
})
]
});
reader = new TestMetricReader();
meterProvider.addMetricReader(
reader
Expand Down Expand Up @@ -102,7 +111,6 @@ export function mockObservableGauge(

export function mockHistogram(): Histogram {
const name = 'int-histogram';
meterProvider.addView({ aggregation: new ExplicitBucketHistogramAggregation([0, 100]) });

return meter.createHistogram(name, {
description: 'sample histogram description',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,15 @@ function valueString(value: number) {
}

function toPrometheusType(
instrumentType: InstrumentType,
dataPointType: DataPointType,
metricData: MetricData,
): PrometheusDataTypeLiteral {
switch (dataPointType) {
case DataPointType.SINGULAR:
if (
instrumentType === InstrumentType.COUNTER ||
instrumentType === InstrumentType.OBSERVABLE_COUNTER
) {
switch (metricData.dataPointType) {
case DataPointType.SUM:
if (metricData.isMonotonic) {
return 'counter';
}
/**
* - HISTOGRAM
* - UP_DOWN_COUNTER
* - OBSERVABLE_GAUGE
* - OBSERVABLE_UP_DOWN_COUNTER
*/
return 'gauge';
case DataPointType.GAUGE:
return 'gauge';
case DataPointType.HISTOGRAM:
return 'histogram';
Expand Down Expand Up @@ -210,13 +202,13 @@ export class PrometheusSerializer {
metricData.descriptor.description || 'description missing'
)}`;
const type = `# TYPE ${name} ${toPrometheusType(
metricData.descriptor.type,
dataPointType
metricData
)}`;

let results = '';
switch (dataPointType) {
case DataPointType.SINGULAR: {
case DataPointType.SUM:
case DataPointType.GAUGE: {
results = metricData.dataPoints
.map(it => this._serializeSingularDataPoint(name, metricData.descriptor.type, it))
.join('');
Expand Down
Loading

0 comments on commit ea6dd7e

Please sign in to comment.