Skip to content

Commit 6feeea3

Browse files
authored
Merge branch 'main' into chore/nodejs22_switch
2 parents 559c8fc + c71a3ae commit 6feeea3

File tree

9 files changed

+259
-152
lines changed

9 files changed

+259
-152
lines changed

.husky/pre-push

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ npm t \
44
npx vitest --run \
55
--exclude tests/unit/layer-publisher.test.ts \
66
--coverage --coverage.thresholds.100 \
7-
--changed="$(git merge-base HEAD main)" \
87
tests/unit

docs/requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mike==1.1.2
2-
mkdocs-material==9.5.44
2+
mkdocs-material==9.5.45
33
mkdocs-git-revision-date-plugin==0.3.2
44
mkdocs-exclude==1.0.2

docs/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ mkdocs-get-deps==0.2.0 \
235235
mkdocs-git-revision-date-plugin==0.3.2 \
236236
--hash=sha256:2e67956cb01823dd2418e2833f3623dee8604cdf223bddd005fe36226a56f6ef
237237
# via -r requirements.in
238-
mkdocs-material==9.5.44 \
239-
--hash=sha256:47015f9c167d58a5ff5e682da37441fc4d66a1c79334bfc08d774763cacf69ca \
240-
--hash=sha256:f3a6c968e524166b3f3ed1fb97d3ed3e0091183b0545cedf7156a2a6804c56c0
238+
mkdocs-material==9.5.45 \
239+
--hash=sha256:286489cf0beca4a129d91d59d6417419c63bceed1ce5cd0ec1fc7e1ebffb8189 \
240+
--hash=sha256:a9be237cfd0be14be75f40f1726d83aa3a81ce44808dc3594d47a7a592f44547
241241
# via -r requirements.in
242242
mkdocs-material-extensions==1.3.1 \
243243
--hash=sha256:10c9511cea88f568257f960358a467d12b970e1f7b2c0e5fb2bb48cab1928443 \

package-lock.json

Lines changed: 149 additions & 142 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@types/aws-lambda": "^8.10.145",
5555
"@types/jest": "^29.5.14",
5656
"@types/node": "^22.9.0",
57-
"@vitest/coverage-v8": "^2.1.4",
57+
"@vitest/coverage-v8": "^2.1.5",
5858
"husky": "^9.1.6",
5959
"jest": "^29.7.0",
6060
"jest-runner-groups": "^2.2.0",

packages/metrics/src/Metrics.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class Metrics extends Utility implements MetricsInterface {
218218
* Add a dimension to metrics.
219219
*
220220
* A dimension is a key-value pair that is used to group metrics, and it is included in all metrics emitted after it is added.
221+
* Invalid dimension values are skipped and a warning is logged.
221222
*
222223
* When calling the {@link Metrics.publishStoredMetrics | `publishStoredMetrics()`} method, the dimensions are cleared. This type of
223224
* dimension is useful when you want to add request-specific dimensions to your metrics. If you want to add dimensions that are
@@ -227,6 +228,12 @@ class Metrics extends Utility implements MetricsInterface {
227228
* @param value - The value of the dimension
228229
*/
229230
public addDimension(name: string, value: string): void {
231+
if (!value) {
232+
this.#logger.warn(
233+
`The dimension ${name} doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
234+
);
235+
return;
236+
}
230237
if (MAX_DIMENSION_COUNT <= this.getCurrentDimensionsCount()) {
231238
throw new RangeError(
232239
`The number of metric dimensions must be lower than ${MAX_DIMENSION_COUNT}`
@@ -239,6 +246,7 @@ class Metrics extends Utility implements MetricsInterface {
239246
* Add multiple dimensions to the metrics.
240247
*
241248
* This method is useful when you want to add multiple dimensions to the metrics at once.
249+
* Invalid dimension values are skipped and a warning is logged.
242250
*
243251
* When calling the {@link Metrics.publishStoredMetrics | `publishStoredMetrics()`} method, the dimensions are cleared. This type of
244252
* dimension is useful when you want to add request-specific dimensions to your metrics. If you want to add dimensions that are
@@ -249,7 +257,14 @@ class Metrics extends Utility implements MetricsInterface {
249257
public addDimensions(dimensions: Dimensions): void {
250258
const newDimensions = { ...this.dimensions };
251259
for (const dimensionName of Object.keys(dimensions)) {
252-
newDimensions[dimensionName] = dimensions[dimensionName];
260+
const value = dimensions[dimensionName];
261+
if (value) {
262+
newDimensions[dimensionName] = value;
263+
} else {
264+
this.#logger.warn(
265+
`The dimension ${dimensionName} doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
266+
);
267+
}
253268
}
254269
if (Object.keys(newDimensions).length > MAX_DIMENSION_COUNT) {
255270
throw new RangeError(

packages/metrics/tests/unit/Metrics.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,45 @@ describe('Class: Metrics', () => {
431431
`The number of metric dimensions must be lower than ${MAX_DIMENSION_COUNT}`
432432
);
433433
});
434+
435+
describe('invalid values should not be added as dimensions', () => {
436+
const testCases = [
437+
{ value: undefined as unknown as string, description: 'undefined' },
438+
{ value: null as unknown as string, description: 'null' },
439+
{ value: '', description: 'empty string' },
440+
];
441+
442+
for (const { value, description } of testCases) {
443+
it(`it should not add dimension with ${description} value and log a warning`, () => {
444+
// Prepare
445+
const customLogger = {
446+
warn: jest.fn(),
447+
debug: jest.fn(),
448+
error: jest.fn(),
449+
info: jest.fn(),
450+
};
451+
const metrics: Metrics = new Metrics({
452+
namespace: TEST_NAMESPACE,
453+
logger: customLogger,
454+
});
455+
const consoleWarnSpy = jest.spyOn(customLogger, 'warn');
456+
const testDimensionName = 'test-dimension';
457+
458+
// Act
459+
metrics.addDimension(testDimensionName, value);
460+
461+
// Assess
462+
expect(consoleWarnSpy).toHaveBeenCalledWith(
463+
`The dimension ${testDimensionName} doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
464+
);
465+
expect(metrics).toEqual(
466+
expect.objectContaining({
467+
dimensions: {},
468+
})
469+
);
470+
});
471+
}
472+
});
434473
});
435474

436475
describe('Method: addDimensions', () => {
@@ -520,6 +559,53 @@ describe('Class: Metrics', () => {
520559
`Unable to add 1 dimensions: the number of metric dimensions must be lower than ${MAX_DIMENSION_COUNT}`
521560
);
522561
});
562+
563+
describe('invalid values should not be added as dimensions', () => {
564+
const testCases = [
565+
{ value: undefined as unknown as string, description: 'undefined' },
566+
{ value: null as unknown as string, description: 'null' },
567+
{ value: '', description: 'empty string' },
568+
];
569+
570+
for (const { value, description } of testCases) {
571+
it(`it should not add dimension with ${description} value and log a warning`, () => {
572+
// Prepare
573+
const customLogger = {
574+
warn: jest.fn(),
575+
debug: jest.fn(),
576+
error: jest.fn(),
577+
info: jest.fn(),
578+
};
579+
const metrics: Metrics = new Metrics({
580+
namespace: TEST_NAMESPACE,
581+
logger: customLogger,
582+
});
583+
const consoleWarnSpy = jest.spyOn(customLogger, 'warn');
584+
const dimensionsToBeAdded: LooseObject = {
585+
'test-dimension-1': 'test-value-1',
586+
'test-dimension-2': 'test-value-2',
587+
};
588+
const testDimensionName = 'test-dimension';
589+
590+
// Act
591+
metrics.addDimensions(dimensionsToBeAdded);
592+
metrics.addDimensions({ [testDimensionName]: value });
593+
594+
// Assess
595+
expect(consoleWarnSpy).toHaveBeenCalledWith(
596+
`The dimension ${testDimensionName} doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings`
597+
);
598+
expect(metrics).toEqual(
599+
expect.objectContaining({
600+
dimensions: {
601+
'test-dimension-1': 'test-value-1',
602+
'test-dimension-2': 'test-value-2',
603+
},
604+
})
605+
);
606+
});
607+
}
608+
});
523609
});
524610

525611
describe('Method: addMetadata', () => {

packages/parser/src/schemas/kafka.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const KafkaBaseEventSchema = z.object({
4040
* @example
4141
* ```json
4242
* {
43-
* "eventSource":"aws:SelfManagedKafka",
43+
* "eventSource":"SelfManagedKafka",
4444
* "bootstrapServers":"b-2.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092,b-1.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092",
4545
* "records":{
4646
* "mytopic-0":[
@@ -79,7 +79,7 @@ const KafkaBaseEventSchema = z.object({
7979
* @see {@link https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html}
8080
*/
8181
const KafkaSelfManagedEventSchema = KafkaBaseEventSchema.extend({
82-
eventSource: z.literal('aws:SelfManagedKafka'),
82+
eventSource: z.literal('SelfManagedKafka'),
8383
});
8484

8585
/**

packages/parser/tests/events/kafkaEventSelfManaged.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"eventSource": "aws:SelfManagedKafka",
2+
"eventSource": "SelfManagedKafka",
33
"bootstrapServers": "b-2.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092,b-1.demo-cluster-1.a1bcde.c1.kafka.us-east-1.amazonaws.com:9092",
44
"records": {
55
"mytopic-0": [

0 commit comments

Comments
 (0)