Skip to content

Commit

Permalink
chore(extension-metrics): address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Oct 17, 2019
1 parent 0e7087b commit ba183e4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions extensions/metrics/src/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/metrics/src/observers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
3 changes: 3 additions & 0 deletions extensions/metrics/src/observers/metrics.observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ba183e4

Please sign in to comment.