Skip to content

Commit

Permalink
bug: support array argument to labels() again
Browse files Browse the repository at this point in the history
This was undocumented and untested, and broke in 13.1.0.

Fixes #499
  • Loading branch information
zbjornson committed Mar 11, 2023
1 parent 0f872ff commit 3009d92
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ gauge.set({ method: 'GET', statusCode: '200' }, 100);
gauge.labels({ method: 'GET', statusCode: '200' }).set(100);
// 3rd version: And again the same effect as above
gauge.labels('GET', '200').set(100);
// 4th version: And again the same effect as above
gauge.labels(['GET', '200']).set(100);
```

It is also possible to use timers with labels, both before and after the timer
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports.setValueDelta = function setValueDelta(
};

exports.getLabels = function (labelNames, args) {
if (typeof args[0] === 'object') {
if (typeof args[0] === 'object' && !Array.isArray(args[0])) {
return args[0];
}

Expand Down
7 changes: 7 additions & 0 deletions test/gaugeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ describe.each([
it('should handle labels provided as an object', async () => {
instance.labels({ code: '200' }).inc();

const values = (await instance.get()).values;
expect(values).toHaveLength(1);
expect(values[0].labels).toEqual({ code: '200' });
});
it('should handle labels provided as an array', async () => {
instance.labels([200]).inc();

const values = (await instance.get()).values;
expect(values).toHaveLength(1);
expect(values[0].labels).toEqual({ code: '200' });
Expand Down

0 comments on commit 3009d92

Please sign in to comment.