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

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Synthetics] Fix service name usage from project monitors !!
(#212229)](https://github.com/elastic/kibana/pull/212229)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2025-03-12T04:45:11Z","message":"[Synthetics]
Fix service name usage from project monitors !! (#212229)\n\n##
Summary\n\nIn support of
https://github.com/elastic/synthetics/pull/974\n\nFix service name usage
from project monitors !!\n\n<img width=\"1728\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cb88cb9c-f4a2-41e9-a869-96c25d14ec67\"\n/>","sha":"40dd0618230971cbac03f7ee0ca620a032910cbf","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0"],"title":"[Synthetics]
Fix service name usage from project monitors
!!","number":212229,"url":"https://github.com/elastic/kibana/pull/212229","mergeCommit":{"message":"[Synthetics]
Fix service name usage from project monitors !! (#212229)\n\n##
Summary\n\nIn support of
https://github.com/elastic/synthetics/pull/974\n\nFix service name usage
from project monitors !!\n\n<img width=\"1728\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cb88cb9c-f4a2-41e9-a869-96c25d14ec67\"\n/>","sha":"40dd0618230971cbac03f7ee0ca620a032910cbf"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212229","number":212229,"mergeCommit":{"message":"[Synthetics]
Fix service name usage from project monitors !! (#212229)\n\n##
Summary\n\nIn support of
https://github.com/elastic/synthetics/pull/974\n\nFix service name usage
from project monitors !!\n\n<img width=\"1728\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/cb88cb9c-f4a2-41e9-a869-96c25d14ec67\"\n/>","sha":"40dd0618230971cbac03f7ee0ca620a032910cbf"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
Kibana Machine 2025-03-12 17:25:34 +11:00 committed by GitHub
parent 053f69908f
commit 23c1e5cd0b
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 };
};