Skip to content

Commit

Permalink
feat(otlp-metrics-exporter): update to newest proto versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc committed Apr 27, 2022
1 parent b77ab11 commit 6ed7cd4
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 598 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@opentelemetry/core": "1.2.0",
"@opentelemetry/exporter-metrics-otlp-http": "0.28.0",
"@opentelemetry/otlp-grpc-exporter-base": "0.28.0",
"@opentelemetry/exporter-trace-otlp-http": "0.28.0",
"@opentelemetry/otlp-transformer": "0.28.0",
"@opentelemetry/resources": "1.2.0",
"@opentelemetry/sdk-metrics-base": "0.28.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
* limitations under the License.
*/

import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import {
defaultExporterTemporality,
defaultOptions,
OTLPMetricExporterBase, OTLPMetricExporterOptions,
toOTLPExportMetricServiceRequest
OTLPMetricExporterBase,
OTLPMetricExporterOptions
} from '@opentelemetry/exporter-metrics-otlp-http';
import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metrics-base';
import {
Expand All @@ -30,12 +29,13 @@ import {
} from '@opentelemetry/otlp-grpc-exporter-base';
import { baggageUtils, getEnv } from '@opentelemetry/core';
import { Metadata } from '@grpc/grpc-js';
import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_URL = 'localhost:4317';


class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase<ResourceMetrics,
otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest> {
IExportMetricsServiceRequest> {
protected readonly _aggregationTemporality: AggregationTemporality;

constructor(config: OTLPGRPCExporterConfigNode & OTLPMetricExporterOptions= defaultOptions) {
Expand Down Expand Up @@ -66,12 +66,8 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase<ResourceMetrics,
: DEFAULT_COLLECTOR_URL;
}

convert(metrics: ResourceMetrics[]): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest {
return toOTLPExportMetricServiceRequest(
metrics[0],
this._aggregationTemporality,
this
);
convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest {
return createExportMetricsServiceRequest(metrics[0], this._aggregationTemporality);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import * as protoLoader from '@grpc/proto-loader';
import { diag, DiagLogger } from '@opentelemetry/api';
import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import * as assert from 'assert';
import * as fs from 'fs';
import * as grpc from '@grpc/grpc-js';
Expand All @@ -35,6 +34,7 @@ import {
mockObservableGauge, setUp, shutdown,
} from './metricsHelper';
import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metrics-base';
import { IExportMetricsServiceRequest, IResourceMetrics } from '@opentelemetry/otlp-transformer';

const metricsServiceProtoPath =
'opentelemetry/proto/collector/metrics/v1/metrics_service.proto';
Expand All @@ -57,7 +57,7 @@ const testOTLPMetricExporter = (params: TestParams) =>
let collectorExporter: OTLPMetricExporter;
let server: grpc.Server;
let exportedData:
| otlpTypes.opentelemetryProto.metrics.v1.ResourceMetrics[]
| IResourceMetrics[]
| undefined;
let metrics: ResourceMetrics;
let reqMetadata: grpc.Metadata | undefined;
Expand All @@ -82,7 +82,7 @@ const testOTLPMetricExporter = (params: TestParams) =>
.MetricsService.service,
{
Export: (data: {
request: otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest;
request: IExportMetricsServiceRequest;
metadata: grpc.Metadata;
}) => {
try {
Expand Down Expand Up @@ -220,18 +220,18 @@ const testOTLPMetricExporter = (params: TestParams) =>
exportedData[0].instrumentationLibraryMetrics[0].metrics[2];
ensureExportedCounterIsCorrect(
counter,
counter.intSum?.dataPoints[0].timeUnixNano,
counter.intSum?.dataPoints[0].startTimeUnixNano
counter.sum?.dataPoints[0].timeUnixNano,
counter.sum?.dataPoints[0].startTimeUnixNano
);
ensureExportedObservableGaugeIsCorrect(
observableGauge,
observableGauge.doubleGauge?.dataPoints[0].timeUnixNano,
observableGauge.doubleGauge?.dataPoints[0].startTimeUnixNano
observableGauge.gauge?.dataPoints[0].timeUnixNano,
observableGauge.gauge?.dataPoints[0].startTimeUnixNano
);
ensureExportedHistogramIsCorrect(
histogram,
histogram.intHistogram?.dataPoints[0].timeUnixNano,
histogram.intHistogram?.dataPoints[0].startTimeUnixNano,
histogram.histogram?.dataPoints[0].timeUnixNano,
histogram.histogram?.dataPoints[0].startTimeUnixNano,
[0, 100],
['0', '2', '0']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

import { Counter, Histogram, ObservableResult, ValueType } from '@opentelemetry/api-metrics';
import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import * as grpc from '@grpc/grpc-js';
import { VERSION } from '@opentelemetry/core';
import { ExplicitBucketHistogramAggregation, MeterProvider, MetricReader } from '@opentelemetry/sdk-metrics-base';
import { IKeyValue, IMetric, IResource } from '@opentelemetry/otlp-transformer';

export class TestMetricReader extends MetricReader {
protected onForceFlush(): Promise<void> {
Expand Down Expand Up @@ -95,7 +95,7 @@ export function mockHistogram(): Histogram {
}

export function ensureExportedAttributesAreCorrect(
attributes: otlpTypes.opentelemetryProto.common.v1.KeyValue[]
attributes: IKeyValue[]
) {
assert.deepStrictEqual(
attributes,
Expand All @@ -113,21 +113,23 @@ export function ensureExportedAttributesAreCorrect(
}

export function ensureExportedCounterIsCorrect(
metric: otlpTypes.opentelemetryProto.metrics.v1.Metric,
metric: IMetric,
time?: number,
startTime?: number
) {
assert.deepStrictEqual(metric, {
name: 'int-counter',
description: 'sample counter description',
unit: '1',
data: 'intSum',
intSum: {
data: 'sum',
sum: {
dataPoints: [
{
labels: [],
attributes: [],
exemplars: [],
value: '1',
value: 'asInt',
asInt: '1',
flags: 0,
startTimeUnixNano: String(startTime),
timeUnixNano: String(time),
},
Expand All @@ -139,21 +141,23 @@ export function ensureExportedCounterIsCorrect(
}

export function ensureExportedObservableGaugeIsCorrect(
metric: otlpTypes.opentelemetryProto.metrics.v1.Metric,
metric: IMetric,
time?: number,
startTime?: number
) {
assert.deepStrictEqual(metric, {
name: 'double-observable-gauge',
description: 'sample observable gauge description',
unit: '1',
data: 'doubleGauge',
doubleGauge: {
data: 'gauge',
gauge: {
dataPoints: [
{
labels: [],
attributes: [],
exemplars: [],
value: 6,
value: 'asDouble',
asDouble: 6,
flags: 0,
startTimeUnixNano: String(startTime),
timeUnixNano: String(time),
},
Expand All @@ -163,7 +167,7 @@ export function ensureExportedObservableGaugeIsCorrect(
}

export function ensureExportedHistogramIsCorrect(
metric: otlpTypes.opentelemetryProto.metrics.v1.Metric,
metric: IMetric,
time?: number,
startTime?: number,
explicitBounds: number[] = [Infinity],
Expand All @@ -173,13 +177,14 @@ export function ensureExportedHistogramIsCorrect(
name: 'int-histogram',
description: 'sample histogram description',
unit: '1',
data: 'intHistogram',
intHistogram: {
data: 'histogram',
histogram: {
dataPoints: [
{
labels: [],
attributes: [],
exemplars: [],
sum: '21',
flags: 0,
sum: 21,
count: '2',
startTimeUnixNano: String(startTime),
timeUnixNano: String(time),
Expand All @@ -193,7 +198,7 @@ export function ensureExportedHistogramIsCorrect(
}

export function ensureResourceIsCorrect(
resource: otlpTypes.opentelemetryProto.resource.v1.Resource
resource: IResource
) {
assert.deepStrictEqual(resource, {
attributes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
{
"path": "../../../packages/opentelemetry-resources"
},
{
"path": "../exporter-trace-otlp-http"
},
{
"path": "../opentelemetry-api-metrics"
},
Expand All @@ -29,6 +26,9 @@
},
{
"path": "../otlp-grpc-exporter-base"
},
{
"path": "../otlp-transformer"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"dependencies": {
"@opentelemetry/api-metrics": "0.28.0",
"@opentelemetry/core": "1.2.0",
"@opentelemetry/exporter-trace-otlp-http": "0.28.0",
"@opentelemetry/otlp-transformer": "0.28.0",
"@opentelemetry/otlp-exporter-base": "0.28.0",
"@opentelemetry/resources": "1.2.0",
"@opentelemetry/sdk-metrics-base": "0.28.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import { ExportResult } from '@opentelemetry/core';
import { AggregationTemporality, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics-base';
import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import { defaultOptions, OTLPMetricExporterOptions } from './OTLPMetricExporterOptions';
import { OTLPExporterBase } from '@opentelemetry/otlp-exporter-base';
import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';

export class OTLPMetricExporterBase<T extends OTLPExporterBase<OTLPMetricExporterOptions,
ResourceMetrics,
otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest>>
IExportMetricsServiceRequest>>
implements PushMetricExporter {
public _otlpExporter: T;
protected _preferredAggregationTemporality: AggregationTemporality;
Expand All @@ -48,5 +48,4 @@ implements PushMetricExporter {
getPreferredAggregationTemporality(): AggregationTemporality {
return this._preferredAggregationTemporality;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
export * from './platform';
export * from './OTLPMetricExporterOptions';
export * from './OTLPMetricExporterBase';
export { toOTLPExportMetricServiceRequest } from './transformMetrics';
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/

import { AggregationTemporality, ResourceMetrics } from '@opentelemetry/sdk-metrics-base';
import {
otlpTypes
} from '@opentelemetry/exporter-trace-otlp-http';
import { toOTLPExportMetricServiceRequest } from '../../transformMetrics';
import { baggageUtils, getEnv } from '@opentelemetry/core';
import { defaultExporterTemporality, defaultOptions, OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions';
import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase';
Expand All @@ -27,12 +23,13 @@ import {
OTLPExporterBrowserBase,
OTLPExporterConfigBase
} from '@opentelemetry/otlp-exporter-base';
import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase<ResourceMetrics,
otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest> {
IExportMetricsServiceRequest> {
protected readonly _aggregationTemporality: AggregationTemporality;

constructor(config: OTLPMetricExporterOptions & OTLPExporterConfigBase = defaultOptions) {
Expand All @@ -58,11 +55,10 @@ class OTLPExporterBrowserProxy extends OTLPExporterBrowserBase<ResourceMetrics,

convert(
metrics: ResourceMetrics[]
): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest {
return toOTLPExportMetricServiceRequest(
): IExportMetricsServiceRequest {
return createExportMetricsServiceRequest(
metrics[0],
this._aggregationTemporality,
this
this._aggregationTemporality
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/

import { ResourceMetrics, AggregationTemporality } from '@opentelemetry/sdk-metrics-base';
import {
otlpTypes,
} from '@opentelemetry/exporter-trace-otlp-http';
import { toOTLPExportMetricServiceRequest } from '../../transformMetrics';
import { getEnv, baggageUtils} from '@opentelemetry/core';
import { defaultExporterTemporality, defaultOptions, OTLPMetricExporterOptions } from '../../OTLPMetricExporterOptions';
import { OTLPMetricExporterBase } from '../../OTLPMetricExporterBase';
Expand All @@ -27,12 +23,13 @@ import {
OTLPExporterNodeBase,
OTLPExporterNodeConfigBase
} from '@opentelemetry/otlp-exporter-base';
import { createExportMetricsServiceRequest, IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/metrics';
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

class OTLPExporterNodeProxy extends OTLPExporterNodeBase<ResourceMetrics,
otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest> {
IExportMetricsServiceRequest> {
protected readonly _aggregationTemporality: AggregationTemporality;

constructor(config: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions = defaultOptions) {
Expand All @@ -48,11 +45,10 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase<ResourceMetrics,

convert(
metrics: ResourceMetrics[]
): otlpTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest {
return toOTLPExportMetricServiceRequest(
): IExportMetricsServiceRequest {
return createExportMetricsServiceRequest(
metrics[0],
this._aggregationTemporality,
this
this._aggregationTemporality
);
}

Expand Down
Loading

0 comments on commit 6ed7cd4

Please sign in to comment.