-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ResponseOps][MW] Add telemetry for the maintenance window #192483
Merged
guskovaue
merged 26 commits into
elastic:main
from
guskovaue:MX-184088-add-telemetry-for-mw
Sep 19, 2024
Merged
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
763160c
total count MW telemetry
guskovaue 3b01b9e
first method count total MW
guskovaue f4a882e
add positive and negative unit tests for total MW count
guskovaue 146ecea
add telemetry for toggles and fix tests for them
guskovaue 52438fd
fix type
guskovaue b292b33
checking right SO property for recurring check
guskovaue 8819661
Merge branch 'main' into MX-184088-add-telemetry-for-mw
guskovaue c289c84
refresh telemetry mappings
guskovaue 9408886
Merge branch 'MX-184088-add-telemetry-for-mw' of github.com:guskovaue…
guskovaue ceeb6ca
nit
guskovaue b6df6bd
add integrational test for MW telemetry
guskovaue 3c365a2
fix integration test
guskovaue 2806a04
fix await issue in find in tile generator
guskovaue 72e7c54
fix types
guskovaue ce8eb77
Merge branch 'main' into MX-184088-add-telemetry-for-mw
elasticmachine 6a62381
Merge branch 'main' into MX-184088-add-telemetry-for-mw
elasticmachine 732374d
changes after code review
guskovaue c69db28
Merge branch 'MX-184088-add-telemetry-for-mw' of github.com:guskovaue…
guskovaue 2e4440d
fix max amount
guskovaue 2051618
fix max amount
guskovaue 44165b9
Merge branch 'MX-184088-add-telemetry-for-mw' of github.com:guskovaue…
guskovaue a13b6e1
max limit
guskovaue 4c852ba
changes after code review
guskovaue cfc3d0f
Merge branch 'main' into MX-184088-add-telemetry-for-mw
elasticmachine 95ac96b
fix unit tests after last changes
guskovaue 493290a
Merge branch 'main' into MX-184088-add-telemetry-for-mw
guskovaue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const TELEMETRY_MW_COUNT_LIMIT = 10000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import type { | |
AggregationsTermsAggregateBase, | ||
AggregationsStringTermsBucketKeys, | ||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { ElasticsearchClient, Logger } from '@kbn/core/server'; | ||
import { ElasticsearchClient, Logger, ISavedObjectsRepository } from '@kbn/core/server'; | ||
|
||
import { | ||
ConnectorsByConsumersBucket, | ||
|
@@ -23,13 +23,21 @@ import { AlertingUsage } from '../types'; | |
import { NUM_ALERTING_RULE_TYPES } from '../alerting_usage_collector'; | ||
import { parseSimpleRuleTypeBucket } from './parse_simple_rule_type_bucket'; | ||
import { groupRulesBySearchType } from './group_rules_by_search_type'; | ||
import { MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE } from '../../../common'; | ||
import { MaintenanceWindowAttributes } from '../../data/maintenance_window/types'; | ||
import { TELEMETRY_MW_COUNT_LIMIT } from '../constants'; | ||
|
||
interface Opts { | ||
esClient: ElasticsearchClient; | ||
alertIndex: string; | ||
logger: Logger; | ||
} | ||
|
||
interface MWOpts { | ||
savedObjectsClient: ISavedObjectsRepository; | ||
logger: Logger; | ||
} | ||
|
||
type GetTotalCountsResults = Pick< | ||
AlertingUsage, | ||
| 'count_total' | ||
|
@@ -48,6 +56,14 @@ type GetTotalCountsResults = Pick< | |
| 'connectors_per_alert' | ||
> & { errorMessage?: string; hasErrors: boolean }; | ||
|
||
type GetMWTelemetryResults = Pick< | ||
AlertingUsage, | ||
'count_mw_total' | 'count_mw_with_repeat_toggle_on' | 'count_mw_with_filter_alert_toggle_on' | ||
> & { | ||
errorMessage?: string; | ||
hasErrors: boolean; | ||
}; | ||
|
||
interface GetTotalCountInUseResults { | ||
countTotal: number; | ||
countByType: Record<string, number>; | ||
|
@@ -490,3 +506,58 @@ export async function getTotalCountInUse({ | |
}; | ||
} | ||
} | ||
|
||
export async function getMWTelemetry({ | ||
savedObjectsClient, | ||
logger, | ||
}: MWOpts): Promise<GetMWTelemetryResults> { | ||
try { | ||
const mwFinder = savedObjectsClient.createPointInTimeFinder<MaintenanceWindowAttributes>({ | ||
type: MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE, | ||
namespaces: ['*'], | ||
perPage: 100, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: What do you think of using the |
||
}); | ||
|
||
let countMWTotal = 0; | ||
let countMWWithRepeatToggleON = 0; | ||
let countMWWithFilterAlertToggleON = 0; | ||
mwLoop: for await (const response of mwFinder.find()) { | ||
for (const mwSavedObject of response.saved_objects) { | ||
if (countMWTotal > TELEMETRY_MW_COUNT_LIMIT) break mwLoop | ||
countMWTotal = countMWTotal + 1; | ||
// scopedQuery property will be null if "Filter alerts" toggle will be off | ||
if (mwSavedObject.attributes.scopedQuery) { | ||
countMWWithFilterAlertToggleON = countMWWithFilterAlertToggleON + 1; | ||
} | ||
// interval property will be not in place if "Repeat" toggle will be off | ||
if (Object.hasOwn(mwSavedObject.attributes.rRule, 'interval')) { | ||
countMWWithRepeatToggleON = countMWWithRepeatToggleON + 1; | ||
} | ||
} | ||
} | ||
await mwFinder.close(); | ||
|
||
return { | ||
hasErrors: false, | ||
count_mw_total: countMWTotal, | ||
count_mw_with_repeat_toggle_on: countMWWithRepeatToggleON, | ||
count_mw_with_filter_alert_toggle_on: countMWWithFilterAlertToggleON, | ||
}; | ||
} catch (err) { | ||
const errorMessage = err?.message ? err.message : err.toString(); | ||
logger.warn( | ||
`Error executing alerting telemetry task: getTotalMWCount - ${JSON.stringify(err)}`, | ||
{ | ||
tags: ['alerting', 'telemetry-failed'], | ||
error: { stack_trace: err?.stack }, | ||
} | ||
); | ||
return { | ||
hasErrors: true, | ||
errorMessage, | ||
count_mw_total: 0, | ||
count_mw_with_repeat_toggle_on: 0, | ||
count_mw_with_filter_alert_toggle_on: 0, | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Instead of mocking the
constants
what do you think of having thegetMWTelemetry
to accept the count limit as a parameter? Then in your tests, you can pass1
as a limit. You can have defaults likegetMWTelemetry({ savedObjectsClient, logger, maxDocuments = TELEMETRY_MW_COUNT_LIMIT})