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

Commit

Permalink
chore(deps): bump prom-client from 14.2.0 to 15.1.0 (#1272)
Browse files Browse the repository at this point in the history
* chore(deps): bump prom-client from 14.2.0 to 15.1.0

Bumps [prom-client](https://github.com/siimon/prom-client) from 14.2.0 to 15.1.0.
- [Release notes](https://github.com/siimon/prom-client/releases)
- [Changelog](https://github.com/siimon/prom-client/blob/master/CHANGELOG.md)
- [Commits](siimon/prom-client@v14.2.0...v15.1.0)

---
updated-dependencies:
- dependency-name: prom-client
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* test(metrics): dont mock prom-client

* test(counters): additional arguments

* fix(metrics): provide promClient for fastify-metrics

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jamie King <jamie.king@aexp.com>
  • Loading branch information
dependabot[bot] and 10xLaCroixDrinker authored Feb 5, 2024
1 parent 4e1fcb9 commit 1fc247f
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 108 deletions.
3 changes: 0 additions & 3 deletions __tests__/server/metrics/__snapshots__/counters.spec.js.snap

This file was deleted.

7 changes: 0 additions & 7 deletions __tests__/server/metrics/__snapshots__/gauges.spec.js.snap

This file was deleted.

55 changes: 35 additions & 20 deletions __tests__/server/metrics/counters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* permissions and limitations under the License.
*/

/* eslint-disable no-underscore-dangle -- prom-client uses dangling underscore */

describe('counters', () => {
let Counter;
let register;

function load() {
jest.resetModules();

jest.mock('prom-client');
({ Counter } = require('prom-client'));

({ Counter, register } = require('prom-client'));
return require('../../../src/server/metrics/counters');
}

Expand All @@ -34,18 +34,19 @@ describe('counters', () => {

it('creates a counter with the options', () => {
const { createCounter } = load();
createCounter({ name: 'yup' });
expect(Counter).toHaveBeenCalledTimes(1);
const counter = Counter.mock.instances[0];
expect(register._metrics).toEqual({});
createCounter({ name: 'yup', help: 'yup_help' });
const counter = register._metrics.yup;
expect(counter).toBeInstanceOf(Counter);
});

it('does not create a new counter if one with the same name already exists', () => {
const { createCounter } = load();
createCounter({ name: 'yup' });
expect(Counter).toHaveBeenCalledTimes(1);
createCounter({ name: 'yup' });
expect(Counter).toHaveBeenCalledTimes(1);
expect(register._metrics).toEqual({});
createCounter({ name: 'yup', help: 'yup_help' });
const counter = register._metrics.yup;
createCounter({ name: 'yup', help: 'yup_help' });
expect(register._metrics.yup).toBe(counter);
});
});

Expand All @@ -57,24 +58,38 @@ describe('counters', () => {

it('throws an error if the counter does not exist', () => {
const { incrementCounter } = load();
expect(() => incrementCounter('nope')).toThrowErrorMatchingSnapshot();
expect(() => incrementCounter('nope')).toThrowErrorMatchingInlineSnapshot(
'"unable to find counter nope, please create it first"'
);
});

it('calls the inc method of the counter', () => {
const { createCounter, incrementCounter } = load();
createCounter({ name: 'yup' });
const counter = Counter.mock.instances[0];
createCounter({ name: 'yup', help: 'yup_help' });
const counter = register._metrics.yup;
expect(counter.hashMap[''].value).toBe(0);
incrementCounter('yup');
expect(counter.inc).toHaveBeenCalledTimes(1);
expect(counter.hashMap[''].value).toBe(1);
incrementCounter('yup', 2);
expect(counter.hashMap[''].value).toBe(3);
});

it('calls the inc method of the counter with the arguments', () => {
const { createCounter, incrementCounter } = load();
createCounter({ name: 'yup' });
const counter = Counter.mock.instances[0];
incrementCounter('yup', 1, 'two', [null, null, null]);
expect(counter.inc).toHaveBeenCalledTimes(1);
expect(counter.inc).toHaveBeenCalledWith(1, 'two', [null, null, null]);
createCounter({ name: 'yup', help: 'yup_help', labelNames: ['foo'] });
const counter = register._metrics.yup;
expect(counter.hashMap).toEqual({});
incrementCounter('yup', { foo: 'bar' }, 2);
expect(counter.hashMap).toMatchInlineSnapshot(`
{
"foo:bar,": {
"labels": {
"foo": "bar",
},
"value": 2,
},
}
`);
});
});
});
110 changes: 66 additions & 44 deletions __tests__/server/metrics/gauges.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* permissions and limitations under the License.
*/

/* eslint-disable no-underscore-dangle -- prom-client uses dangling underscore */

describe('gauges', () => {
let Gauge;
let register;

function load() {
jest.resetModules();

jest.mock('prom-client');
({ Gauge } = require('prom-client'));

({ Gauge, register } = require('prom-client'));
return require('../../../src/server/metrics/gauges');
}

Expand All @@ -34,18 +34,19 @@ describe('gauges', () => {

it('creates a gauge with the options', () => {
const { createGauge } = load();
createGauge({ name: 'yup' });
expect(Gauge).toHaveBeenCalledTimes(1);
const gauge = Gauge.mock.instances[0];
expect(register._metrics).toEqual({});
createGauge({ name: 'yup', help: 'yup_help' });
const gauge = register._metrics.yup;
expect(gauge).toBeInstanceOf(Gauge);
});

it('does not create a new gauge if one with the same name already exists', () => {
const { createGauge } = load();
createGauge({ name: 'yup' });
expect(Gauge).toHaveBeenCalledTimes(1);
createGauge({ name: 'yup' });
expect(Gauge).toHaveBeenCalledTimes(1);
expect(register._metrics).toEqual({});
createGauge({ name: 'yup', help: 'yup_help' });
const gauge = register._metrics.yup;
createGauge({ name: 'yup', help: 'yup_help' });
expect(register._metrics.yup).toBe(gauge);
});
});

Expand All @@ -57,24 +58,38 @@ describe('gauges', () => {

it('throws an error if the gauge does not exist', () => {
const { incrementGauge } = load();
expect(() => incrementGauge('nope')).toThrowErrorMatchingSnapshot();
expect(() => incrementGauge('nope')).toThrowErrorMatchingInlineSnapshot(
'"unable to find gauge nope, please create it first"'
);
});

it('calls the inc method of the gauge', () => {
const { createGauge, incrementGauge } = load();
createGauge({ name: 'yup' });
const gauge = Gauge.mock.instances[0];
createGauge({ name: 'yup', help: 'yup_help' });
const gauge = register._metrics.yup;
expect(gauge.hashMap[''].value).toBe(0);
incrementGauge('yup');
expect(gauge.inc).toHaveBeenCalledTimes(1);
expect(gauge.hashMap[''].value).toBe(1);
incrementGauge('yup', 2);
expect(gauge.hashMap[''].value).toBe(3);
});

it('calls the inc method of the gauge with the arguments', () => {
const { createGauge, incrementGauge } = load();
createGauge({ name: 'yup' });
const gauge = Gauge.mock.instances[0];
incrementGauge('yup', 1, 'two', [null, null, null]);
expect(gauge.inc).toHaveBeenCalledTimes(1);
expect(gauge.inc).toHaveBeenCalledWith(1, 'two', [null, null, null]);
createGauge({ name: 'yup', help: 'yup_help', labelNames: ['foo'] });
const gauge = register._metrics.yup;
expect(gauge.hashMap).toEqual({});
incrementGauge('yup', { foo: 'bar' }, 2);
expect(gauge.hashMap).toMatchInlineSnapshot(`
{
"foo:bar,": {
"labels": {
"foo": "bar",
},
"value": 2,
},
}
`);
});
});

Expand All @@ -86,24 +101,36 @@ describe('gauges', () => {

it('throws an error if the gauge does not exist', () => {
const { setGauge } = load();
expect(() => setGauge('nope')).toThrowErrorMatchingSnapshot();
expect(() => setGauge('nope')).toThrowErrorMatchingInlineSnapshot(
'"unable to find gauge nope, please create it first"'
);
});

it('calls the set method of the gauge', () => {
const { createGauge, setGauge } = load();
createGauge({ name: 'yup' });
const gauge = Gauge.mock.instances[0];
setGauge('yup');
expect(gauge.set).toHaveBeenCalledTimes(1);
createGauge({ name: 'yup', help: 'yup_help' });
const gauge = register._metrics.yup;
expect(gauge.hashMap[''].value).toBe(0);
setGauge('yup', 101);
expect(gauge.hashMap[''].value).toBe(101);
});

it('calls the set method of the gauge with the arguments', () => {
const { createGauge, setGauge } = load();
createGauge({ name: 'yup' });
const gauge = Gauge.mock.instances[0];
setGauge('yup', 1, 'two', [null, null, null]);
expect(gauge.set).toHaveBeenCalledTimes(1);
expect(gauge.set).toHaveBeenCalledWith(1, 'two', [null, null, null]);
createGauge({ name: 'yup', help: 'yup_help', labelNames: ['foo'] });
const gauge = register._metrics.yup;
expect(gauge.hashMap).toEqual({});
setGauge('yup', { foo: 'bar' }, 101);
expect(gauge.hashMap).toMatchInlineSnapshot(`
{
"foo:bar,": {
"labels": {
"foo": "bar",
},
"value": 101,
},
}
`);
});
});

Expand All @@ -115,24 +142,19 @@ describe('gauges', () => {

it('throws an error if the gauge does not exist', () => {
const { resetGauge } = load();
expect(() => resetGauge('nope')).toThrowErrorMatchingSnapshot();
expect(() => resetGauge('nope')).toThrowErrorMatchingInlineSnapshot(
'"unable to find gauge nope, please create it first"'
);
});

it('calls the reset method of the gauge', () => {
const { createGauge, resetGauge } = load();
createGauge({ name: 'yup' });
const gauge = Gauge.mock.instances[0];
const { createGauge, resetGauge, setGauge } = load();
createGauge({ name: 'yup', help: 'yup_help' });
const gauge = register._metrics.yup;
setGauge('yup', 101);
expect(gauge.hashMap[''].value).toBe(101);
resetGauge('yup');
expect(gauge.reset).toHaveBeenCalledTimes(1);
});

it('calls the reset method of the gauge with the arguments', () => {
const { createGauge, resetGauge } = load();
createGauge({ name: 'yup' });
const gauge = Gauge.mock.instances[0];
resetGauge('yup', 1, 'two', [null, null, null]);
expect(gauge.reset).toHaveBeenCalledTimes(1);
expect(gauge.reset).toHaveBeenCalledWith(1, 'two', [null, null, null]);
expect(gauge.hashMap[''].value).toBe(0);
});
});
});
47 changes: 27 additions & 20 deletions __tests__/server/metrics/summaries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* permissions and limitations under the License.
*/

/* eslint-disable no-underscore-dangle -- prom-client uses dangling underscore */

describe('summaries', () => {
let Summary;
let register;

function load() {
jest.resetModules();

jest.mock('prom-client');
({ Summary } = require('prom-client'));

({ Summary, register } = require('prom-client'));
return require('../../../src/server/metrics/summaries');
}

Expand All @@ -34,18 +34,19 @@ describe('summaries', () => {

it('creates a summary with the options', () => {
const { createSummary } = load();
createSummary({ name: 'yup' });
expect(Summary).toHaveBeenCalledTimes(1);
const summary = Summary.mock.instances[0];
expect(register._metrics).toEqual({});
createSummary({ name: 'yup', help: 'yup_help' });
const summary = register._metrics.yup;
expect(summary).toBeInstanceOf(Summary);
});

it('does not create a new summary if one with the same name already exists', () => {
const { createSummary } = load();
createSummary({ name: 'yup' });
expect(Summary).toHaveBeenCalledTimes(1);
createSummary({ name: 'yup' });
expect(Summary).toHaveBeenCalledTimes(1);
expect(register._metrics).toEqual({});
createSummary({ name: 'yup', help: 'yup_help' });
const summary = register._metrics.yup;
createSummary({ name: 'yup', help: 'yup_help' });
expect(register._metrics.yup).toBe(summary);
});
});

Expand All @@ -64,19 +65,25 @@ describe('summaries', () => {

it('calls the startTimer method of the summary', () => {
const { createSummary, startSummaryTimer } = load();
createSummary({ name: 'yup' });
const summary = Summary.mock.instances[0];
startSummaryTimer('yup');
expect(summary.startTimer).toHaveBeenCalledTimes(1);
createSummary({ name: 'yup', help: 'yup_help' });
const summary = register._metrics.yup;
expect(summary.hashMap[''].count).toBe(0);
expect(summary.hashMap[''].sum).toBe(0);
const endTimer = startSummaryTimer('yup');
endTimer();
expect(summary.hashMap[''].count).toBe(1);
expect(summary.hashMap[''].sum).toBeGreaterThan(0);
});

it('calls the startTimer method of the summary with the arguments', () => {
const { createSummary, startSummaryTimer } = load();
createSummary({ name: 'yup' });
const summary = Summary.mock.instances[0];
startSummaryTimer('yup', 1, 'two', [null, null, null]);
expect(summary.startTimer).toHaveBeenCalledTimes(1);
expect(summary.startTimer).toHaveBeenCalledWith(1, 'two', [null, null, null]);
createSummary({ name: 'yup', help: 'yup_help', labelNames: ['foo'] });
const summary = register._metrics.yup;
expect(summary.hashMap).toEqual({});
const endTimer = startSummaryTimer('yup', { foo: 'bar' });
endTimer();
expect(summary.hashMap['foo:bar,'].count).toBe(1);
expect(summary.hashMap['foo:bar,'].sum).toBeGreaterThan(0);
});
});
});
7 changes: 6 additions & 1 deletion __tests__/server/ssrServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import fastifyStatic from '@fastify/static';
import fastifyHelmet from '@fastify/helmet';
import fastifySensible from '@fastify/sensible';
import fastifyMetrics from 'fastify-metrics';
import client from 'prom-client';

import ensureCorrelationId from '../../src/server/plugins/ensureCorrelationId';
import setAppVersionHeader from '../../src/server/plugins/setAppVersionHeader';
Expand Down Expand Up @@ -130,7 +131,11 @@ describe('ssrServer', () => {
expect(register.mock.calls[2][0]).toEqual(ensureCorrelationId);
expect(register.mock.calls[3][0]).toEqual(fastifyCookie);
expect(register.mock.calls[4][0]).toEqual(logging);
expect(register.mock.calls[5][0]).toEqual(fastifyMetrics);
expect(register.mock.calls[5]).toEqual([fastifyMetrics, {
defaultMetrics: { enabled: false },
endpoint: null,
promClient: client,
}]);
expect(register.mock.calls[6]).toEqual([
compress,
{
Expand Down
Loading

0 comments on commit 1fc247f

Please sign in to comment.