Skip to content

Commit

Permalink
fix(configuration): configuration option enabled changed to `metric…
Browse files Browse the repository at this point in the history
…sEnabled`

Rename configuration property `enabled` to `metricsEnabled` to avoid collision with other plugin
configurations that are merged into the configuration object passed to the plugin.

BREAKING CHANGE: configuration option `enabled` changed to `metricsEnabled`
  • Loading branch information
Ed Clement committed Dec 23, 2021
1 parent e822ad4 commit dbd0afe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Complete configuration example:
middlewares:
metrics:
## Optional. Defaults to `false` so make sure to set this to `true` if you want to collect metrics.
enabled: true
metricsEnabled: true

## Optional. Defaults to `/-/metrics`.
metricsPath: /custom/path/metrics
Expand Down Expand Up @@ -64,7 +64,7 @@ Given the following example configuration:
# Verdaccio config file
middlewares:
metrics:
enabled: true
metricsEnabled: true
packageGroups:
'@babel[/]plugin': 'babel-plugin'
'babel[-]plugin': 'babel-plugin'
Expand Down
2 changes: 1 addition & 1 deletion src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class VerdaccioMiddlewarePlugin implements IPluginMiddleware<Metr
private requestsCounter = new Counter(REQUEST_COUNTER_OPTIONS);

public constructor(config: MetricsConfig, options: PluginOptions<MetricsConfig>) {
this.metricsEnabled = [true, 'true'].includes(config.enabled);
this.metricsEnabled = [true, 'true'].includes(config.metricsEnabled);
this.metricsPath = config.metricsPath || '/-/metrics';
this.packageGroups = config.packageGroups || [];
this.logger = options.logger;
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config } from '@verdaccio/types';

export interface MetricsConfig extends Config {
enabled: boolean;
metricsEnabled: boolean;
metricsPath: string;
packageGroups: Record<string, string>;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Metrics Plugin', () => {
beforeAll(() => {
register.clear();
const metricsPlugin = new MetricsPlugin(
{ enabled: true } as MetricsConfig,
{ metricsEnabled: true } as MetricsConfig,
{ logger } as PluginOptions<MetricsConfig>
);
metricsPlugin.register_middlewares(app, {} as IBasicAuth<MetricsConfig>, {} as IStorageManager<MetricsConfig>);
Expand All @@ -48,7 +48,7 @@ describe('Metrics Plugin', () => {
beforeAll(() => {
register.clear();
const metricsPlugin = new MetricsPlugin(
{ enabled: false } as MetricsConfig,
{ metricsEnabled: false } as MetricsConfig,
{ logger } as PluginOptions<MetricsConfig>
);
metricsPlugin.register_middlewares(app, {} as IBasicAuth<MetricsConfig>, {} as IStorageManager<MetricsConfig>);
Expand All @@ -69,7 +69,7 @@ describe('Metrics Plugin', () => {
beforeAll(() => {
register.clear();
const metricsPlugin = new MetricsPlugin(
{ enabled: true } as MetricsConfig,
{ metricsEnabled: true } as MetricsConfig,
{ logger: getLogger() } as PluginOptions<MetricsConfig>
);
metricsPlugin.collectMetrics(req, res, next);
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('Metrics Plugin', () => {
beforeAll(() => {
register.clear();
metricsPlugin = new MetricsPlugin(
{ enabled: true } as MetricsConfig,
{ metricsEnabled: true } as MetricsConfig,
{ logger: getLogger() } as PluginOptions<MetricsConfig>
);
expressMocks.forEach(({ req, res, next }) => metricsPlugin.collectMetrics(req, res, next));
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('Metrics Plugin', () => {
beforeAll(() => {
register.clear();
metricsPlugin = new MetricsPlugin(
{ enabled: true, packageGroups } as MetricsConfig,
{ metricsEnabled: true, packageGroups } as MetricsConfig,
{ logger: getLogger() } as PluginOptions<MetricsConfig>
);
expressMocks.forEach(({ req, res, next }) => metricsPlugin.collectMetrics(req, res, next));
Expand Down

0 comments on commit dbd0afe

Please sign in to comment.