diff --git a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts index 4608562df39..03d6f9a468e 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts @@ -184,7 +184,7 @@ export class PrometheusSerializer { return str; } - serializeScopeMetrics(scopeMetrics: ScopeMetrics) { + private serializeScopeMetrics(scopeMetrics: ScopeMetrics) { let str = ''; for (const metric of scopeMetrics.metrics) { str += this.serializeMetricData(metric) + '\n'; @@ -192,7 +192,7 @@ export class PrometheusSerializer { return str; } - serializeMetricData(metricData: MetricData) { + private serializeMetricData(metricData: MetricData) { let name = sanitizePrometheusMetricName( escapeString(metricData.descriptor.name) ); @@ -236,7 +236,7 @@ export class PrometheusSerializer { return `${help}\n${type}\n${results}`.trim(); } - serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { + private serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { let results = ''; name = enforcePrometheusNamingConvention(name, type); @@ -252,7 +252,7 @@ export class PrometheusSerializer { return results; } - serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { + private serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint): string { let results = ''; name = enforcePrometheusNamingConvention(name, type); diff --git a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts index 51733e6386e..7a159436460 100644 --- a/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts +++ b/experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts @@ -48,6 +48,10 @@ class TestMetricReader extends MetricReader { async onShutdown() {} } +function ignoreComments(result: string): string { + return result.split("\n").filter((line) => !line.startsWith('#')).join("\n"); +} + describe('PrometheusSerializer', () => { beforeEach(() => { mockHrTime(); @@ -86,7 +90,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = ignoreComments(serializer.serialize(resourceMetrics)); return result; } @@ -129,7 +133,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeHistogramDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = ignoreComments(serializer.serialize(resourceMetrics)); return result; } @@ -182,9 +186,8 @@ describe('PrometheusSerializer', () => { assert.strictEqual(errors.length, 0); assert.strictEqual(resourceMetrics.scopeMetrics.length, 1); assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1); - const scopeMetrics = resourceMetrics.scopeMetrics[0]; - const result = serializer.serializeScopeMetrics(scopeMetrics); + const result = serializer.serialize(resourceMetrics); return result; } @@ -234,9 +237,8 @@ describe('PrometheusSerializer', () => { assert.strictEqual(errors.length, 0); assert.strictEqual(resourceMetrics.scopeMetrics.length, 1); assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1); - const scopeMetrics = resourceMetrics.scopeMetrics[0]; - const result = serializer.serializeScopeMetrics(scopeMetrics); + const result = serializer.serialize(resourceMetrics); return result; } @@ -284,7 +286,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = ignoreComments(serializer.serialize(resourceMetrics)); return result; } @@ -323,7 +325,7 @@ describe('PrometheusSerializer', () => { const pointData = metric.dataPoints as DataPoint[]; assert.strictEqual(pointData.length, 1); - const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]); + const result = ignoreComments(serializer.serialize(resourceMetrics)); return result; }