Skip to content

Commit

Permalink
Make only PrometheusSerializer.serialize public
Browse files Browse the repository at this point in the history
  • Loading branch information
matschaffer committed Jun 16, 2022
1 parent fb7b15d commit 4b3ac64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ 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';
}
return str;
}

serializeMetricData(metricData: MetricData) {
private serializeMetricData(metricData: MetricData) {
let name = sanitizePrometheusMetricName(
escapeString(metricData.descriptor.name)
);
Expand Down Expand Up @@ -236,7 +236,7 @@ export class PrometheusSerializer {
return `${help}\n${type}\n${results}`.trim();
}

serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<number>): string {
private serializeSingularDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<number>): string {
let results = '';

name = enforcePrometheusNamingConvention(name, type);
Expand All @@ -252,7 +252,7 @@ export class PrometheusSerializer {
return results;
}

serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<Histogram>): string {
private serializeHistogramDataPoint(name: string, type: InstrumentType, dataPoint: DataPoint<Histogram>): string {
let results = '';

name = enforcePrometheusNamingConvention(name, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -86,8 +90,8 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<number>[];
assert.strictEqual(pointData.length, 1);

const result = serializer.serializeSingularDataPoint(metric.descriptor.name, metric.descriptor.type, pointData[0]);
return result;
const result = ignoreComments(serializer.serialize(resourceMetrics));
return result
}

it('should serialize metrics with singular data type', async () => {
Expand Down Expand Up @@ -129,7 +133,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<Histogram>[];
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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -284,7 +286,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<number>[];
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;
}

Expand Down Expand Up @@ -323,7 +325,7 @@ describe('PrometheusSerializer', () => {
const pointData = metric.dataPoints as DataPoint<number>[];
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;
}

Expand Down

0 comments on commit 4b3ac64

Please sign in to comment.