From ba183e416e464fa281c5316c25ea35c8485f89fe Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 17 Oct 2019 08:44:09 -0700 Subject: [PATCH] chore(extension-metrics): address review comments --- .../src/__tests__/acceptance/metrics-push.acceptance.ts | 4 +--- .../metrics/src/__tests__/acceptance/metrics.acceptance.ts | 4 +--- extensions/metrics/src/metrics.component.ts | 4 ++-- extensions/metrics/src/observers/index.ts | 2 +- extensions/metrics/src/observers/metrics.observer.ts | 3 +++ .../{pushgateway.observer.ts => metrics.push.observer.ts} | 5 ++++- 6 files changed, 12 insertions(+), 10 deletions(-) rename extensions/metrics/src/observers/{pushgateway.observer.ts => metrics.push.observer.ts} (87%) diff --git a/extensions/metrics/src/__tests__/acceptance/metrics-push.acceptance.ts b/extensions/metrics/src/__tests__/acceptance/metrics-push.acceptance.ts index 483aab8f0bec..d72ded8ea9bf 100644 --- a/extensions/metrics/src/__tests__/acceptance/metrics-push.acceptance.ts +++ b/extensions/metrics/src/__tests__/acceptance/metrics-push.acceptance.ts @@ -7,9 +7,7 @@ import {RestApplication, RestServerConfig} from '@loopback/rest'; import {givenHttpServerConfig, supertest} from '@loopback/testlab'; import {AddressInfo} from 'net'; import {promisify} from 'util'; -import {MetricsComponent} from '../..'; -import {MetricsBindings} from '../../keys'; -import {MetricsOptions} from '../../types'; +import {MetricsBindings, MetricsComponent, MetricsOptions} from '../..'; import {PushGateway} from './mock-pushgateway'; const gateway = new PushGateway(); diff --git a/extensions/metrics/src/__tests__/acceptance/metrics.acceptance.ts b/extensions/metrics/src/__tests__/acceptance/metrics.acceptance.ts index 7eef91ab337b..469bf6e835f3 100644 --- a/extensions/metrics/src/__tests__/acceptance/metrics.acceptance.ts +++ b/extensions/metrics/src/__tests__/acceptance/metrics.acceptance.ts @@ -10,9 +10,7 @@ import { expect, givenHttpServerConfig, } from '@loopback/testlab'; -import {MetricsComponent} from '../..'; -import {MetricsBindings} from '../../keys'; -import {MetricsOptions} from '../../types'; +import {MetricsBindings, MetricsComponent, MetricsOptions} from '../..'; describe('Metrics (acceptance)', () => { let app: RestApplication; diff --git a/extensions/metrics/src/metrics.component.ts b/extensions/metrics/src/metrics.component.ts index 7a07f36a2e62..6e521122976e 100644 --- a/extensions/metrics/src/metrics.component.ts +++ b/extensions/metrics/src/metrics.component.ts @@ -15,7 +15,7 @@ import {Application, Component, CoreBindings} from '@loopback/core'; import {metricsControllerFactory} from './controllers'; import {MetricsInterceptor} from './interceptors'; import {MetricsBindings} from './keys'; -import {MetricsObserver, PushGatewayObserver} from './observers'; +import {MetricsObserver, MetricsPushObserver} from './observers'; import {DEFAULT_METRICS_OPTIONS, MetricsOptions} from './types'; /** @@ -39,7 +39,7 @@ export class MetricsComponent implements Component { !options.pushGateway || (options.pushGateway && !options.pushGateway.disabled) ) { - this.application.lifeCycleObserver(PushGatewayObserver); + this.application.lifeCycleObserver(MetricsPushObserver); } this.application.add(createBindingFromClass(MetricsInterceptor)); if (!options.endpoint || (options.endpoint && !options.endpoint.disabled)) { diff --git a/extensions/metrics/src/observers/index.ts b/extensions/metrics/src/observers/index.ts index c177bafa36d5..ed69679e9a98 100644 --- a/extensions/metrics/src/observers/index.ts +++ b/extensions/metrics/src/observers/index.ts @@ -4,4 +4,4 @@ // License text available at https://opensource.org/licenses/MIT export * from './metrics.observer'; -export * from './pushgateway.observer'; +export * from './metrics.push.observer'; diff --git a/extensions/metrics/src/observers/metrics.observer.ts b/extensions/metrics/src/observers/metrics.observer.ts index 1db72c17d897..aec0669dff0a 100644 --- a/extensions/metrics/src/observers/metrics.observer.ts +++ b/extensions/metrics/src/observers/metrics.observer.ts @@ -8,6 +8,9 @@ import {collectDefaultMetrics, register} from 'prom-client'; import {MetricsBindings} from '../keys'; import {DEFAULT_METRICS_OPTIONS, MetricsOptions} from '../types'; +/** + * An observer to set default Node.js metrics collection + */ export class MetricsObserver implements LifeCycleObserver { private interval: NodeJS.Timeout | undefined; diff --git a/extensions/metrics/src/observers/pushgateway.observer.ts b/extensions/metrics/src/observers/metrics.push.observer.ts similarity index 87% rename from extensions/metrics/src/observers/pushgateway.observer.ts rename to extensions/metrics/src/observers/metrics.push.observer.ts index 76f27e45d28f..c14f2bd4e4c3 100644 --- a/extensions/metrics/src/observers/pushgateway.observer.ts +++ b/extensions/metrics/src/observers/metrics.push.observer.ts @@ -8,7 +8,10 @@ import {Pushgateway} from 'prom-client'; import {MetricsBindings} from '../keys'; import {DEFAULT_METRICS_OPTIONS, MetricsOptions} from '../types'; -export class PushGatewayObserver implements LifeCycleObserver { +/** + * An observer to set up periodical push of metrics to a push gateway + */ +export class MetricsPushObserver implements LifeCycleObserver { private interval: NodeJS.Timeout | undefined; private gateway: Pushgateway;