[Synthetics] Fix service name usage from project monitors !! (#212229)

## Summary

In support of https://github.com/elastic/synthetics/pull/974

Fix service name usage from project monitors !!

<img width="1728" alt="image"
src="https://github.com/user-attachments/assets/cb88cb9c-f4a2-41e9-a869-96c25d14ec67"
/>
This commit is contained in:
Shahzad 2025-03-12 05:45:11 +01:00 committed by GitHub
parent 5f05349930
commit 40dd061823
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 3 deletions

View file

@ -63,6 +63,7 @@ export const ProjectMonitorCodec = t.intersection([
namespace: t.string,
retestOnFailure: t.boolean,
fields: t.record(t.string, t.string),
'service.name': t.string,
}),
]);

View file

@ -73,6 +73,7 @@ describe('browser normalizers', () => {
tags: ['tag1', 'tag2'],
ignoreHTTPSErrors: true,
hash: testHash,
'service.name': 'test-service',
} as ProjectMonitor, // test that normalizers defaults to browser when type is omitted
{
type: MonitorTypeEnum.BROWSER,
@ -144,7 +145,7 @@ describe('browser normalizers', () => {
unit: 'm',
},
screenshots: 'off',
'service.name': '',
'service.name': 'test-service',
'source.project.content': 'test content 1',
tags: ['tag1', 'tag2'],
params: '',
@ -328,7 +329,7 @@ describe('browser normalizers', () => {
unit: 'm',
},
screenshots: 'off',
'service.name': '',
'service.name': 'test-service',
'source.project.content': 'test content 1',
tags: ['tag1', 'tag2'],
params: '',
@ -398,7 +399,7 @@ describe('browser normalizers', () => {
unit: 'm',
},
screenshots: 'off',
'service.name': '',
'service.name': 'test-service',
'source.project.content': 'test content 1',
tags: ['tag1', 'tag2'],
params: '',

View file

@ -96,6 +96,9 @@ export const getNormalizeCommonFields = ({
// picking out keys specifically, so users can't add arbitrary fields
[ConfigKey.ALERT_CONFIG]: getAlertConfig(monitor),
[ConfigKey.LABELS]: monitor.fields || defaultFields[ConfigKey.LABELS],
...(monitor[ConfigKey.APM_SERVICE_NAME] && {
[ConfigKey.APM_SERVICE_NAME]: monitor[ConfigKey.APM_SERVICE_NAME],
}),
};
return { normalizedFields, errors };
};