Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Rename prefix name for [StackdriverStatsExporter] (#185)
Browse files Browse the repository at this point in the history
* Uses `require` instead of `import` for [hex2dec] package
* Renames metrixPrefix to prefix for [stackdriver]
* Adds package locks
  • Loading branch information
isaikevych committed Nov 13, 2018
1 parent 49b1185 commit 18e8981
Show file tree
Hide file tree
Showing 24 changed files with 10,710 additions and 14,746 deletions.
150 changes: 75 additions & 75 deletions package-lock.json

Large diffs are not rendered by default.

1,092 changes: 260 additions & 832 deletions packages/opencensus-core/package-lock.json

Large diffs are not rendered by default.

2,699 changes: 1,009 additions & 1,690 deletions packages/opencensus-exporter-instana/package-lock.json

Large diffs are not rendered by default.

1,368 changes: 684 additions & 684 deletions packages/opencensus-exporter-jaeger/package-lock.json

Large diffs are not rendered by default.

1,752 changes: 274 additions & 1,478 deletions packages/opencensus-exporter-ocagent/package-lock.json

Large diffs are not rendered by default.

1,092 changes: 250 additions & 842 deletions packages/opencensus-exporter-stackdriver/package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/opencensus-exporter-stackdriver/src/modules.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {Exporter, ExporterBuffer, ExporterConfig, RootSpan, Span, SpanContext} f
import {logger, Logger} from '@opencensus/core';
import {auth, JWT} from 'google-auth-library';
import {google} from 'googleapis';
import {hexToDec} from 'hex2dec';
// TODO change to use import when types for hex2dec will be available
const {hexToDec}: {[key: string]: (input: string) => string} =
require('hex2dec');

import {StackdriverExporterOptions, TracesWithCredentials, TranslatedSpan, TranslatedTrace} from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class StackdriverStatsExporter implements StatsEventListener {
options.period :
StackdriverStatsExporter.PERIOD;
this.projectId = options.projectId;
this.metricPrefix = options.metricPrefix ||
StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN;
this.metricPrefix =
options.prefix || StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN;
this.logger = options.logger || logger.logger();
this.viewToUpload = {};

Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-exporter-stackdriver/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface StackdriverExporterOptions extends ExporterConfig {
* Prefix for metric overrides the OpenCensus prefix
* of a stackdriver metric. Optional
*/
metricPrefix?: string;
prefix?: string;

/**
* Is called whenever the exporter fails to upload metrics to stackdriver.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {CoreTracer, RootSpan} from '@opencensus/core';
import {logger} from '@opencensus/core';
import * as assert from 'assert';
import * as fs from 'fs';
import {hexToDec} from 'hex2dec';
// TODO change to use import when type package for hex2dec will be available
const {hexToDec}: {[key: string]: (input: string) => string} =
require('hex2dec');
import * as nock from 'nock';

import {StackdriverExporterOptions, StackdriverTraceExporter, TranslatedTrace} from '../src/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,43 +330,157 @@ describe('Stackdriver Stats Exporter', function() {
});
});

describe('With metricPrefix option', () => {
let prefixExporterOptions: StackdriverExporterOptions;
let prefixExporter: StackdriverStatsExporter;

before(() => {
prefixExporterOptions =
Object.assign(exporterOptions, {metricPrefix: 'test'});
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);
stats.registerExporter(prefixExporter);
});
describe('With prefix option', () => {
describe('should be reflected when onRegisterView is called', () => {
const {name} = viewMetricDescriptor;
let prefixExporter: StackdriverStatsExporter;
beforeEach(() => {
if (dryrun) {
nocks.metricDescriptors(PROJECT_ID, null, null, false);
}
});

after(() => {
prefixExporter.close();
});
afterEach(() => {
prefixExporter.close();
});

it(`should be reflected when onRegisterView is called`, async () => {
if (dryrun) {
nocks.metricDescriptors(PROJECT_ID, null, null, false);
}
await prefixExporter.onRegisterView(viewMetricDescriptor).then(() => {
return assertMetricDescriptor(
exporterTestLogger.debugBuffer[0], viewMetricDescriptor,
prefixExporterOptions.metricPrefix);
it('should use custom domain if prefix is undefined', async () => {
prefixExporter = new StackdriverStatsExporter(exporterOptions);
stats.registerExporter(prefixExporter);
await prefixExporter.onRegisterView(viewMetricDescriptor).then(() => {
const metricDescriptor: MetricDescriptor =
exporterTestLogger.debugBuffer[0];
assert.strictEqual(
metricDescriptor.type,
`${StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN}/${name}`);
});
});

it('should use custom domain if prefix is null', async () => {
const prefixExporterOptions: StackdriverExporterOptions =
Object.assign({prefix: null}, exporterOptions);
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);
stats.registerExporter(prefixExporter);
await prefixExporter.onRegisterView(viewMetricDescriptor).then(() => {
const metricDescriptor: MetricDescriptor =
exporterTestLogger.debugBuffer[0];
assert.strictEqual(
metricDescriptor.type,
`${StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN}/${name}`);
});
});

it('should use custom domain if prefix is empty', async () => {
const prefixExporterOptions: StackdriverExporterOptions =
Object.assign({prefix: ''}, exporterOptions);
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);
stats.registerExporter(prefixExporter);
await prefixExporter.onRegisterView(viewMetricDescriptor).then(() => {
const metricDescriptor: MetricDescriptor =
exporterTestLogger.debugBuffer[0];
assert.strictEqual(
metricDescriptor.type,
`${StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN}/${name}`);
});
});

it('should use defined prefix', async () => {
const prefix = 'test';
const prefixExporterOptions: StackdriverExporterOptions =
Object.assign({prefix}, exporterOptions);
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);
stats.registerExporter(prefixExporter);
await prefixExporter.onRegisterView(viewMetricDescriptor).then(() => {
const metricDescriptor: MetricDescriptor =
exporterTestLogger.debugBuffer[0];
assert.strictEqual(metricDescriptor.type, `${prefix}/${name}`);
});
});
});

it(`should be reflected when onRecord is called`, async () => {
if (dryrun) {
nocks.timeSeries(PROJECT_ID, null, null, false);
}
viewTimeSeries.recordMeasurement(measurement);
prefixExporter.onRecord([viewTimeSeries], measurement);
describe('should be reflected when onRecord is called', () => {
let prefixExporter: StackdriverStatsExporter;
const {name} = viewTimeSeries;

await new Promise((resolve) => setTimeout(resolve, DELAY)).then(() => {
return assertTimeSeries(
exporterTestLogger.debugBuffer[0][0], viewTimeSeries, measurement,
PROJECT_ID, prefixExporterOptions.metricPrefix);
beforeEach(() => {
if (dryrun) {
nocks.timeSeries(PROJECT_ID, null, null, false);
}
});

afterEach(() => {
prefixExporter.close();
});

it('should use custom domain if prefix is undefined', async () => {
prefixExporter = new StackdriverStatsExporter(exporterOptions);
stats.registerExporter(prefixExporter);

viewTimeSeries.recordMeasurement(measurement);
prefixExporter.onRecord([viewTimeSeries], measurement);

await new Promise((resolve) => setTimeout(resolve, DELAY))
.then(() => {
const timeSeries = exporterTestLogger.debugBuffer[0][0];
assert.strictEqual(
timeSeries.metric.type,
`${StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN}/${
name}`);
});
});

it('should use custom domain if prefix is null', async () => {
const prefixExporterOptions: StackdriverExporterOptions =
Object.assign({prefix: null}, exporterOptions);
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);
stats.registerExporter(prefixExporter);

viewTimeSeries.recordMeasurement(measurement);
prefixExporter.onRecord([viewTimeSeries], measurement);

await new Promise((resolve) => setTimeout(resolve, DELAY))
.then(() => {
const timeSeries = exporterTestLogger.debugBuffer[0][0];
assert.strictEqual(
timeSeries.metric.type,
`${StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN}/${
name}`);
});
});

it('should use custom domain if prefix is empty', async () => {
const prefixExporterOptions: StackdriverExporterOptions =
Object.assign({prefix: ''}, exporterOptions);
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);
stats.registerExporter(prefixExporter);

viewTimeSeries.recordMeasurement(measurement);
prefixExporter.onRecord([viewTimeSeries], measurement);

await new Promise((resolve) => setTimeout(resolve, DELAY))
.then(() => {
const timeSeries = exporterTestLogger.debugBuffer[0][0];
assert.strictEqual(
timeSeries.metric.type,
`${StackdriverStatsExporter.CUSTOM_OPENCENSUS_DOMAIN}/${
name}`);
});
});

it('should use defined prefix', async () => {
const prefix = 'test';
const prefixExporterOptions: StackdriverExporterOptions =
Object.assign(exporterOptions, {prefix});
prefixExporter = new StackdriverStatsExporter(prefixExporterOptions);

viewTimeSeries.recordMeasurement(measurement);
prefixExporter.onRecord([viewTimeSeries], measurement);

await new Promise((resolve) => setTimeout(resolve, DELAY))
.then(() => {
const timeSeries = exporterTestLogger.debugBuffer[0][0];
assert.strictEqual(timeSeries.metric.type, `${prefix}/${name}`);
});
});
});
});
Expand Down
18 changes: 0 additions & 18 deletions packages/opencensus-exporter-zipkin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 18e8981

Please sign in to comment.