Skip to content

Commit

Permalink
chore: remove SIGTERM listener
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Sep 11, 2020
1 parent 9469db5 commit 533e2a3
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 281 deletions.

This file was deleted.

32 changes: 0 additions & 32 deletions packages/opentelemetry-core/src/platform/node/ShutdownNotifier.ts

This file was deleted.

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

import { ObserverResult } from '@opentelemetry/api';
import {
notifyOnGlobalShutdown,
_invokeGlobalShutdown,
} from '@opentelemetry/core';
import {
Expand Down Expand Up @@ -320,39 +319,6 @@ describe('PrometheusExporter', () => {
});
});

it('should export multiple labels on graceful shutdown', done => {
const counter = meter.createCounter('counter', {
description: 'a test description',
}) as CounterMetric;

counter.bind({ counterKey1: 'labelValue1' }).add(10);
counter.bind({ counterKey1: 'labelValue2' }).add(20);
counter.bind({ counterKey1: 'labelValue3' }).add(30);

removeEvent = notifyOnGlobalShutdown(() => {
http
.get('http://localhost:9464/metrics', res => {
res.on('data', chunk => {
const body = chunk.toString();
const lines = body.split('\n');

assert.deepStrictEqual(lines, [
'# HELP counter a test description',
'# TYPE counter counter',
`counter{counterKey1="labelValue1"} 10 ${mockedHrTimeMs}`,
`counter{counterKey1="labelValue2"} 20 ${mockedHrTimeMs}`,
`counter{counterKey1="labelValue3"} 30 ${mockedHrTimeMs}`,
'',
]);

done();
});
})
.on('error', errorHandler(done));
});
_invokeGlobalShutdown();
});

it('should export multiple labels on manual shutdown', done => {
const counter = meter.createCounter('counter', {
description: 'a test description',
Expand Down Expand Up @@ -384,39 +350,6 @@ describe('PrometheusExporter', () => {
});
});

it('should export multiple labels on graceful shutdown', done => {
const counter = meter.createCounter('counter', {
description: 'a test description',
}) as CounterMetric;

counter.bind({ counterKey1: 'labelValue1' }).add(10);
counter.bind({ counterKey1: 'labelValue2' }).add(20);
counter.bind({ counterKey1: 'labelValue3' }).add(30);

removeEvent = notifyOnGlobalShutdown(() => {
http
.get('http://localhost:9464/metrics', res => {
res.on('data', chunk => {
const body = chunk.toString();
const lines = body.split('\n');

assert.deepStrictEqual(lines, [
'# HELP counter a test description',
'# TYPE counter counter',
`counter{counterKey1="labelValue1"} 10 ${mockedHrTimeMs}`,
`counter{counterKey1="labelValue2"} 20 ${mockedHrTimeMs}`,
`counter{counterKey1="labelValue3"} 30 ${mockedHrTimeMs}`,
'',
]);

done();
});
})
.on('error', errorHandler(done));
});
_invokeGlobalShutdown();
});

it('should export multiple labels on manual shutdown', done => {
const counter = meter.createCounter('counter', {
description: 'a test description',
Expand Down
13 changes: 0 additions & 13 deletions packages/opentelemetry-metrics/src/MeterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ export class MeterProvider implements api.MeterProvider {
logger: this.logger,
resource: this.resource,
});
if (this._config.gracefulShutdown) {
this._cleanNotifyOnGlobalShutdown = notifyOnGlobalShutdown(() => {
this._shutdownAllMeters().catch();
});
}
}

/**
Expand All @@ -64,14 +59,6 @@ export class MeterProvider implements api.MeterProvider {
}

shutdown(): Promise<void> {
if (this._cleanNotifyOnGlobalShutdown) {
this._cleanNotifyOnGlobalShutdown();
this._cleanNotifyOnGlobalShutdown = undefined;
}
return this._shutdownAllMeters();
}

private _shutdownAllMeters(): Promise<void> {
if (this._isShutdown) {
return this._shuttingDownPromise;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/opentelemetry-metrics/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ export interface MeterConfig {

/** Metric batcher. */
batcher?: Batcher;

/** Bool for whether or not graceful shutdown is enabled. If disabled metrics will not be exported when SIGTERM is recieved */
gracefulShutdown?: boolean;
}

/** Default Meter configuration. */
export const DEFAULT_CONFIG = {
logLevel: getEnv().OTEL_LOG_LEVEL,
gracefulShutdown: true,
};

/** The default metric creation options value. */
Expand Down
40 changes: 0 additions & 40 deletions packages/opentelemetry-metrics/test/MeterProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import * as sinon from 'sinon';
import { MeterProvider, Meter, CounterMetric } from '../src';
import {
NoopLogger,
notifyOnGlobalShutdown,
_invokeGlobalShutdown,
} from '@opentelemetry/core';

describe('MeterProvider', () => {
Expand Down Expand Up @@ -94,32 +92,9 @@ describe('MeterProvider', () => {
});

describe('shutdown()', () => {
it('should call shutdown when SIGTERM is received', () => {
const meterProvider = new MeterProvider({
interval: Math.pow(2, 31) - 1,
gracefulShutdown: true,
});
const shutdownStub1 = sandbox.stub(
meterProvider.getMeter('meter1'),
'shutdown'
);
const shutdownStub2 = sandbox.stub(
meterProvider.getMeter('meter2'),
'shutdown'
);
removeEvent = notifyOnGlobalShutdown(() => {
setImmediate(() => {
sinon.assert.calledOnce(shutdownStub1);
sinon.assert.calledOnce(shutdownStub2);
});
});
_invokeGlobalShutdown();
});

it('should call shutdown when manually invoked', () => {
const meterProvider = new MeterProvider({
interval: Math.pow(2, 31) - 1,
gracefulShutdown: true,
});
const sandbox = sinon.createSandbox();
const shutdownStub1 = sandbox.stub(
Expand All @@ -135,20 +110,5 @@ describe('MeterProvider', () => {
sinon.assert.calledOnce(shutdownStub2);
});
});

it('should not trigger shutdown if graceful shutdown is turned off', () => {
const meterProvider = new MeterProvider({
interval: Math.pow(2, 31) - 1,
gracefulShutdown: false,
});
const shutdownStub = sandbox.stub(
meterProvider.getMeter('meter1'),
'shutdown'
);
removeEvent = notifyOnGlobalShutdown(() => {
sinon.assert.notCalled(shutdownStub);
});
_invokeGlobalShutdown();
});
});
});
21 changes: 21 additions & 0 deletions packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class NodeSDK {

private _autoDetectResources: boolean;

private _tracerProvider?: NodeTracerProvider;
private _meterProvider?: MeterProvider;

/**
* Create a new NodeJS SDK instance
*/
Expand Down Expand Up @@ -154,6 +157,8 @@ export class NodeSDK {
resource: this._resource,
});

this._tracerProvider = tracerProvider;

tracerProvider.addSpanProcessor(this._tracerProviderConfig.spanProcessor);
tracerProvider.register({
contextManager: this._tracerProviderConfig.contextManager,
Expand All @@ -167,7 +172,23 @@ export class NodeSDK {
resource: this._resource,
});

this._meterProvider = meterProvider;

metrics.setGlobalMeterProvider(meterProvider);
}
}

public shutdown(): Promise<void> {
const promises: Promise<unknown>[] = [];
if (this._tracerProvider) {
promises.push(this._tracerProvider.shutdown());
}
if (this._meterProvider) {
promises.push(this._meterProvider.shutdown());
}

return Promise.all(promises)
// return void instead of the array from Promise.all
.then(() => {});
}
}
14 changes: 0 additions & 14 deletions packages/opentelemetry-tracing/src/BasicTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
HttpTraceContext,
HttpCorrelationContext,
CompositePropagator,
notifyOnGlobalShutdown,
} from '@opentelemetry/core';
import { SpanProcessor, Tracer } from '.';
import { DEFAULT_CONFIG } from './config';
Expand Down Expand Up @@ -49,11 +48,6 @@ export class BasicTracerProvider implements api.TracerProvider {
logger: this.logger,
resource: this.resource,
});
if (this._config.gracefulShutdown) {
this._cleanNotifyOnGlobalShutdown = notifyOnGlobalShutdown(
this._shutdownActiveProcessor.bind(this)
);
}
}

getTracer(name: string, version = '*', config?: TracerConfig): Tracer {
Expand Down Expand Up @@ -108,14 +102,6 @@ export class BasicTracerProvider implements api.TracerProvider {
}

shutdown() {
if (this._cleanNotifyOnGlobalShutdown) {
this._cleanNotifyOnGlobalShutdown();
this._cleanNotifyOnGlobalShutdown = undefined;
}
return this.activeSpanProcessor.shutdown();
}

private _shutdownActiveProcessor() {
return this.activeSpanProcessor.shutdown();
}
}
29 changes: 0 additions & 29 deletions packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import {
setActiveSpan,
setExtractedSpanContext,
TraceState,
notifyOnGlobalShutdown,
_invokeGlobalShutdown,
} from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
Expand Down Expand Up @@ -369,18 +367,6 @@ describe('BasicTracerProvider', () => {
});

describe('.shutdown()', () => {
it('should trigger shutdown when SIGTERM is recieved', () => {
const tracerProvider = new BasicTracerProvider();
const shutdownStub = sandbox.stub(
tracerProvider.getActiveSpanProcessor(),
'shutdown'
);
removeEvent = notifyOnGlobalShutdown(() => {
sinon.assert.calledOnce(shutdownStub);
});
_invokeGlobalShutdown();
});

it('should trigger shutdown when manually invoked', () => {
const tracerProvider = new BasicTracerProvider();
const shutdownStub = sandbox.stub(
Expand All @@ -390,20 +376,5 @@ describe('BasicTracerProvider', () => {
tracerProvider.shutdown();
sinon.assert.calledOnce(shutdownStub);
});

it('should not trigger shutdown if graceful shutdown is turned off', () => {
const tracerProvider = new BasicTracerProvider({
gracefulShutdown: false,
});
const sandbox = sinon.createSandbox();
const shutdownStub = sandbox.stub(
tracerProvider.getActiveSpanProcessor(),
'shutdown'
);
removeEvent = notifyOnGlobalShutdown(() => {
sinon.assert.notCalled(shutdownStub);
});
_invokeGlobalShutdown();
});
});
});
Loading

0 comments on commit 533e2a3

Please sign in to comment.