Skip to content

Commit

Permalink
[8.x] [ResponseOps][Telemetry] Add default value for new telemetry fi…
Browse files Browse the repository at this point in the history
…elds for old tasks (#194827) (#195140)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Telemetry] Add default value for new telemetry fields
for old tasks (#194827)](#194827)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT
[{"author":{"name":"Julia","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-04T18:51:54Z","message":"[ResponseOps][Telemetry]
Add default value for new telemetry fields for old tasks
(#194827)\n\nSolve:
https://github.com/elastic/kibana/issues/194717\r\n\r\nWhen we add new
fields to telemetry, we forgot to add them to this\r\nplace, which for
tasks that were created < 8.10 will go migration.\r\nProbably serverless
has some old tasks. Probably because of it task run\r\nfails. So I fix
it
here.","sha":"38abda52bb9af156be245b3ffc1a8ea93e58fe12","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[ResponseOps][Telemetry]
Add default value for new telemetry fields for old
tasks","number":194827,"url":"https://github.com/elastic/kibana/pull/194827","mergeCommit":{"message":"[ResponseOps][Telemetry]
Add default value for new telemetry fields for old tasks
(#194827)\n\nSolve:
https://github.com/elastic/kibana/issues/194717\r\n\r\nWhen we add new
fields to telemetry, we forgot to add them to this\r\nplace, which for
tasks that were created < 8.10 will go migration.\r\nProbably serverless
has some old tasks. Probably because of it task run\r\nfails. So I fix
it
here.","sha":"38abda52bb9af156be245b3ffc1a8ea93e58fe12"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194827","number":194827,"mergeCommit":{"message":"[ResponseOps][Telemetry]
Add default value for new telemetry fields for old tasks
(#194827)\n\nSolve:
https://github.com/elastic/kibana/issues/194717\r\n\r\nWhen we add new
fields to telemetry, we forgot to add them to this\r\nplace, which for
tasks that were created < 8.10 will go migration.\r\nProbably serverless
has some old tasks. Probably because of it task run\r\nfails. So I fix
it
here.","sha":"38abda52bb9af156be245b3ffc1a8ea93e58fe12"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Julia <[email protected]>
  • Loading branch information
kibanamachine and guskovaue authored Oct 4, 2024
1 parent 0046213 commit c917833
Show file tree
Hide file tree
Showing 2 changed files with 294 additions and 101 deletions.
176 changes: 176 additions & 0 deletions x-pack/plugins/alerting/server/usage/task_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,180 @@ describe('telemetry task state', () => {
expect(result).not.toHaveProperty('foo');
});
});

describe('v2', () => {
const v2 = stateSchemaByVersion[2];
it('should work on empty object when running the up migration', () => {
const result = v2.up({});
expect(result).toMatchInlineSnapshot(`
Object {
"avg_es_search_duration_by_type_per_day": Object {},
"avg_es_search_duration_per_day": 0,
"avg_execution_time_by_type_per_day": Object {},
"avg_execution_time_per_day": 0,
"avg_total_search_duration_by_type_per_day": Object {},
"avg_total_search_duration_per_day": 0,
"connectors_per_alert": Object {
"avg": 0,
"max": 0,
"min": 0,
},
"count_active_by_type": Object {},
"count_active_total": 0,
"count_alerts_by_rule_type": Object {},
"count_alerts_total": 0,
"count_by_type": Object {},
"count_connector_types_by_consumers": Object {},
"count_disabled_total": 0,
"count_failed_and_unrecognized_rule_tasks_by_status_by_type_per_day": Object {},
"count_failed_and_unrecognized_rule_tasks_by_status_per_day": Object {},
"count_failed_and_unrecognized_rule_tasks_per_day": 0,
"count_mw_total": 0,
"count_mw_with_filter_alert_toggle_on": 0,
"count_mw_with_repeat_toggle_on": 0,
"count_rules_by_execution_status": Object {
"error": 0,
"success": 0,
"warning": 0,
},
"count_rules_by_execution_status_per_day": Object {},
"count_rules_by_notify_when": Object {
"on_action_group_change": 0,
"on_active_alert": 0,
"on_throttle_interval": 0,
},
"count_rules_executions_by_type_per_day": Object {},
"count_rules_executions_failured_by_reason_by_type_per_day": Object {},
"count_rules_executions_failured_by_reason_per_day": Object {},
"count_rules_executions_failured_per_day": 0,
"count_rules_executions_per_day": 0,
"count_rules_executions_timeouts_by_type_per_day": Object {},
"count_rules_executions_timeouts_per_day": 0,
"count_rules_muted": 0,
"count_rules_namespaces": 0,
"count_rules_snoozed": 0,
"count_rules_with_muted_alerts": 0,
"count_rules_with_tags": 0,
"count_total": 0,
"error_messages": undefined,
"has_errors": false,
"percentile_num_alerts_by_type_per_day": Object {},
"percentile_num_alerts_per_day": Object {},
"percentile_num_generated_actions_by_type_per_day": Object {},
"percentile_num_generated_actions_per_day": Object {},
"runs": 0,
"schedule_time": Object {
"avg": "0s",
"max": "0s",
"min": "0s",
},
"schedule_time_number_s": Object {
"avg": 0,
"max": 0,
"min": 0,
},
"throttle_time": Object {
"avg": "0s",
"max": "0s",
"min": "0s",
},
"throttle_time_number_s": Object {
"avg": 0,
"max": 0,
"min": 0,
},
}
`);
});

it(`shouldn't overwrite properties when running the up migration`, () => {
const state = {
avg_es_search_duration_by_type_per_day: { '.index-threshold': 1 },
avg_es_search_duration_per_day: 2,
avg_execution_time_by_type_per_day: { '.index-threshold': 3 },
avg_execution_time_per_day: 4,
avg_total_search_duration_by_type_per_day: { '.index-threshold': 5 },
avg_total_search_duration_per_day: 6,
connectors_per_alert: {
avg: 7,
max: 8,
min: 9,
},
count_active_by_type: { '.index-threshold': 10 },
count_active_total: 11,
count_alerts_by_rule_type: {},
count_alerts_total: 0,
count_by_type: { '.index-threshold': 12 },
count_connector_types_by_consumers: { '.index-threshold': 13 },
count_disabled_total: 14,
count_failed_and_unrecognized_rule_tasks_by_status_by_type_per_day: {
'.index-threshold': 15,
},
count_failed_and_unrecognized_rule_tasks_by_status_per_day: { '.index-threshold': 16 },
count_failed_and_unrecognized_rule_tasks_per_day: 17,
count_mw_total: 0,
count_mw_with_filter_alert_toggle_on: 0,
count_mw_with_repeat_toggle_on: 0,
count_rules_by_execution_status: {
error: 18,
success: 19,
warning: 20,
},
count_rules_by_execution_status_per_day: { '.index-threshold': 21 },
count_rules_by_notify_when: {
on_action_group_change: 22,
on_active_alert: 23,
on_throttle_interval: 24,
},
count_rules_executions_by_type_per_day: { '.index-threshold': 25 },
count_rules_executions_failured_by_reason_by_type_per_day: { '.index-threshold': 26 },
count_rules_executions_failured_by_reason_per_day: { '.index-threshold': 27 },
count_rules_executions_failured_per_day: 28,
count_rules_executions_per_day: 29,
count_rules_executions_timeouts_by_type_per_day: { '.index-threshold': 30 },
count_rules_executions_timeouts_per_day: 31,
count_rules_muted: 32,
count_rules_namespaces: 33,
count_rules_snoozed: 34,
count_rules_with_muted_alerts: 35,
count_rules_with_tags: 36,
count_total: 37,
error_messages: ['foo'],
has_errors: true,
percentile_num_alerts_by_type_per_day: { '.index-threshold': 38 },
percentile_num_alerts_per_day: { '.index-threshold': 39 },
percentile_num_generated_actions_by_type_per_day: { '.index-threshold': 40 },
percentile_num_generated_actions_per_day: { '.index-threshold': 41 },
runs: 42,
schedule_time: {
avg: '43s',
max: '44s',
min: '45s',
},
schedule_time_number_s: {
avg: 46,
max: 47,
min: 48,
},
throttle_time: {
avg: '49s',
max: '50s',
min: '51s',
},
throttle_time_number_s: {
avg: 52,
max: 53,
min: 54,
},
};
const result = v2.up(cloneDeep(state));
expect(result).toEqual(state);
});

it('should drop unknown properties when running the up migration', () => {
const state = { foo: true };
const result = v2.up(state);
expect(result).not.toHaveProperty('foo');
});
});
});
Loading

0 comments on commit c917833

Please sign in to comment.