From e752a4880ee750df7cabaccc4d593a27ba9282fc Mon Sep 17 00:00:00 2001 From: Kamil Dybicz Date: Tue, 3 Jun 2025 20:06:06 +0200 Subject: [PATCH 1/3] Allowing space characters in the Namespace Changes based on the documentation: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace --- src/Constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Constants.ts b/src/Constants.ts index afa8909..2161bfe 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -19,7 +19,7 @@ export enum Constants { MAX_DIMENSION_VALUE_LENGTH = 1024, MAX_METRIC_NAME_LENGTH = 1024, MAX_NAMESPACE_LENGTH = 256, - VALID_NAMESPACE_REGEX = '^[a-zA-Z0-9._#:/-]+$', + VALID_NAMESPACE_REGEX = '^(?=.*\S)[a-zA-Z0-9\._#:/\- ]+$', VALID_DIMENSION_REGEX = '^[\x00-\x7F]+$', MAX_TIMESTAMP_PAST_AGE = 1209600000, // 2 weeks MAX_TIMESTAMP_FUTURE_AGE = 7200000, // 2 hours From 930e98c2ac133c99a42161c5821750086b0c70bf Mon Sep 17 00:00:00 2001 From: Kamil Dybicz Date: Tue, 3 Jun 2025 20:20:03 +0200 Subject: [PATCH 2/3] Updating namespace validation tests --- src/logger/__tests__/MetricsContext.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logger/__tests__/MetricsContext.test.ts b/src/logger/__tests__/MetricsContext.test.ts index 8c9e468..0170999 100644 --- a/src/logger/__tests__/MetricsContext.test.ts +++ b/src/logger/__tests__/MetricsContext.test.ts @@ -414,7 +414,7 @@ test('put metric with same key and different resolution in single flush throws e }).toThrow(InvalidMetricError); }); -test.each([[''], [' '], ['a'.repeat((Constants.MAX_NAMESPACE_LENGTH as number) + 1)], ['àẁş/ćļốṹḓⱳầƭḉⱨ'], ['namespace ']])( +test.each([[''], [' '], ['a'.repeat((Constants.MAX_NAMESPACE_LENGTH as number) + 1)], ['àẁş/ćļốṹḓⱳầƭḉⱨ']])( 'setNamespace with invalid namespace: %s throws error', (namespace) => { // arrange @@ -430,7 +430,7 @@ test.each([[''], [' '], ['a'.repeat((Constants.MAX_NAMESPACE_LENGTH as number) + test('setNamespace with valid namespace does not throw error', () => { // arrange const context = MetricsContext.empty(); - const namespace = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/#:'; + const namespace = '1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz .-_/#:'; // act expect(() => { From 7cbdd77a3f4ee2c742cefcfcdf447b0410a1730b Mon Sep 17 00:00:00 2001 From: Kamil Dybicz Date: Tue, 3 Jun 2025 20:33:47 +0200 Subject: [PATCH 3/3] Fixing regex by leaving hyphen as last character --- src/Constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Constants.ts b/src/Constants.ts index 2161bfe..40f0de7 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -19,7 +19,7 @@ export enum Constants { MAX_DIMENSION_VALUE_LENGTH = 1024, MAX_METRIC_NAME_LENGTH = 1024, MAX_NAMESPACE_LENGTH = 256, - VALID_NAMESPACE_REGEX = '^(?=.*\S)[a-zA-Z0-9\._#:/\- ]+$', + VALID_NAMESPACE_REGEX = '^(?=.*\S)[a-zA-Z0-9 ._#:/-]+$', VALID_DIMENSION_REGEX = '^[\x00-\x7F]+$', MAX_TIMESTAMP_PAST_AGE = 1209600000, // 2 weeks MAX_TIMESTAMP_FUTURE_AGE = 7200000, // 2 hours