Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Metrics extends Utility implements MetricsInterface {
const newDimensions = this.#sanitizeDimensions(dimensions);
const currentCount = this.#dimensionsStore.getDimensionCount();
const newSetCount = Object.keys(newDimensions).length;
if (currentCount + newSetCount >= MAX_DIMENSION_COUNT) {
if (currentCount + newSetCount > MAX_DIMENSION_COUNT) {
throw new RangeError(
`The number of metric dimensions must be lower than ${MAX_DIMENSION_COUNT}`
);
Expand Down
29 changes: 29 additions & 0 deletions packages/metrics/tests/unit/dimensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,35 @@ describe('Working with dimensions', () => {
);
});

it('allows adding a dimension set when it reaches the limit exactly', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a test that calls both addDimension and addDimesions to ensure they behave in the same way. E.g., add 29 dimensions and then check that we throw when we try to add another dimension using both APIs.

// Prepare
const metrics = new Metrics({
singleMetric: true,
});

// Act
// We start with 1 dimension because service name is already added
for (let i = 1; i < MAX_DIMENSION_COUNT - 1; i++) {
metrics.addDimension(`dimension-${i}`, 'test');
}

metrics.addDimensions({
final: 'test',
});

// Assess
metrics.addMetric('foo', MetricUnit.Count, 1);
metrics.publishStoredMetrics();

expect(console.log).toHaveEmittedEMFWith(
expect.objectContaining({
service: 'hello-world',
final: 'test',
foo: 1,
})
);
});

it('handles dimension overrides across multiple dimension sets', () => {
// Prepare
const metrics = new Metrics({
Expand Down
Loading