Skip to content

Commit e73e035

Browse files
kibanamachinermyzdmlemeshko
authored
[8.19] [SDH][APM] Handle create anomaly detection jobs failures (elastic#219364) (elastic#219677)
# Backport This will backport the following commits from `main` to `8.19`: - [[SDH][APM] Handle create anomaly detection jobs failures (elastic#219364)](elastic#219364) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sergi Romeu","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-30T08:49:04Z","message":"[SDH][APM] Handle create anomaly detection jobs failures (elastic#219364)\n\n## Summary\n\nFixes elastic#157704\n\nThis PR shows the error toast when you try to create an anomaly\ndetection job that throws an error.\n\n\nhttps://github.com/user-attachments/assets/0c3ca1a5-36a6-4385-8cf1-473e689e9afb\n\n## How to test\n1. Run kibana \n2. Modify\n[this](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-apm-synthtrace/src/lib/utils/get_synthtrace_environment.ts)\nto have a long environment name.\n3. Go to APM -> Settings -> Anomaly detection.\n4. Try to create a job after running the synthtrace scenario, it should\nfail.\n\n---------\n\nCo-authored-by: jennypavlova <[email protected]>","sha":"da434192989436d55292433ccd0543364af57f20","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","apm:ml","sdh-linked","Team:obs-ux-infra_services","backport:version","v9.1.0","v8.19.0","v8.18.1","v9.0.1","v8.17.6"],"title":"[SDH][APM] Handle create anomaly detection jobs failures","number":219364,"url":"https://github.com/elastic/kibana/pull/219364","mergeCommit":{"message":"[SDH][APM] Handle create anomaly detection jobs failures (elastic#219364)\n\n## Summary\n\nFixes elastic#157704\n\nThis PR shows the error toast when you try to create an anomaly\ndetection job that throws an error.\n\n\nhttps://github.com/user-attachments/assets/0c3ca1a5-36a6-4385-8cf1-473e689e9afb\n\n## How to test\n1. Run kibana \n2. Modify\n[this](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-apm-synthtrace/src/lib/utils/get_synthtrace_environment.ts)\nto have a long environment name.\n3. Go to APM -> Settings -> Anomaly detection.\n4. Try to create a job after running the synthtrace scenario, it should\nfail.\n\n---------\n\nCo-authored-by: jennypavlova <[email protected]>","sha":"da434192989436d55292433ccd0543364af57f20"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","8.18","9.0","8.17"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219364","number":219364,"mergeCommit":{"message":"[SDH][APM] Handle create anomaly detection jobs failures (elastic#219364)\n\n## Summary\n\nFixes elastic#157704\n\nThis PR shows the error toast when you try to create an anomaly\ndetection job that throws an error.\n\n\nhttps://github.com/user-attachments/assets/0c3ca1a5-36a6-4385-8cf1-473e689e9afb\n\n## How to test\n1. Run kibana \n2. Modify\n[this](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-apm-synthtrace/src/lib/utils/get_synthtrace_environment.ts)\nto have a long environment name.\n3. Go to APM -> Settings -> Anomaly detection.\n4. Try to create a job after running the synthtrace scenario, it should\nfail.\n\n---------\n\nCo-authored-by: jennypavlova <[email protected]>","sha":"da434192989436d55292433ccd0543364af57f20"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Sergi Romeu <[email protected]> Co-authored-by: Dzmitry Lemechko <[email protected]>
1 parent 798bc87 commit e73e035

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

x-pack/solutions/observability/plugins/apm/ftr_e2e/cypress/e2e/settings/anomaly_detection.cy.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function generateData({
5151
const getAbleToModifyCase = () => {
5252
it('should be able to modify settings', () => {
5353
const { rangeFrom, rangeTo } = timeRange;
54-
const TEST_ENV = 'test environment ' + new Date().toISOString();
54+
const TEST_ENV = 'test env ' + new Date().toISOString();
5555

5656
synthtrace.index(
5757
generateData({
@@ -66,13 +66,37 @@ const getAbleToModifyCase = () => {
6666
const button = cy.get('button[data-test-subj="apmJobsListCreateJobButton"]');
6767
button.should('not.be.disabled');
6868
button.click();
69-
cy.get('div[data-test-subj="comboBoxInput"]').click();
70-
cy.get(`button[title="${TEST_ENV}"]`).click();
69+
cy.get('div[data-test-subj="comboBoxInput"]').click({ force: true });
70+
cy.get(`button[title="${TEST_ENV}"]`).click({ force: true });
7171
cy.get('button[data-test-subj="apmAddEnvironmentsCreateJobsButton"]').click();
7272
cy.intercept('GET', '/internal/apm/settings/anomaly-detection/jobs*').as('internalApiRequest');
73-
cy.wait('@internalApiRequest');
73+
cy.wait('@internalApiRequest', { timeout: 15000 });
7474
cy.contains('Anomaly detection jobs created');
7575
});
76+
77+
it('should show error if api call crashes when modifying settings', () => {
78+
const { rangeFrom, rangeTo } = timeRange;
79+
const TEST_ENV =
80+
'Synthtrace: case scenario TEST-with-a-really-long-name ' + new Date().toISOString();
81+
82+
synthtrace.index(
83+
generateData({
84+
from: new Date(rangeFrom).getTime(),
85+
to: new Date(rangeTo).getTime(),
86+
serviceName: 'opbeans-node',
87+
environment: TEST_ENV,
88+
})
89+
);
90+
91+
cy.visitKibana(basePath);
92+
const button = cy.get('button[data-test-subj="apmJobsListCreateJobButton"]');
93+
button.should('not.be.disabled');
94+
button.click();
95+
cy.get('div[data-test-subj="comboBoxInput"]').click({ force: true });
96+
cy.get(`button[title="${TEST_ENV}"]`).click({ force: true });
97+
cy.get('button[data-test-subj="apmAddEnvironmentsCreateJobsButton"]').click();
98+
cy.contains('Anomaly detection jobs could not be created');
99+
});
76100
};
77101

78102
const getUnableToModifyCase = () => {

x-pack/solutions/observability/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ export async function createAnomalyDetectionJobs({
6868
// https://github.com/elastic/elasticsearch/issues/36271
6969
for (const environment of uniqueMlJobEnvs) {
7070
try {
71-
responses.push(
72-
await createAnomalyDetectionJob({
73-
mlClient,
74-
environment,
75-
apmMetricIndex,
76-
})
77-
);
71+
const response = await createAnomalyDetectionJob({
72+
mlClient,
73+
environment,
74+
apmMetricIndex,
75+
});
76+
if (response.jobs[0].success || !response.jobs[0].error) {
77+
responses.push(response);
78+
} else {
79+
failedJobs.push({ id: response.jobs[0].id, error: response.jobs[0].error });
80+
}
7881
} catch (e) {
7982
if (!e.id || !e.error) {
8083
throw e;

0 commit comments

Comments
 (0)