-
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
Changes from 16 commits
763160c
3b01b9e
f4a882e
146ecea
52438fd
b292b33
8819661
c289c84
9408886
ceeb6ca
b6df6bd
3c365a2
2806a04
72e7c54
ce8eb77
6a62381
732374d
c69db28
2e4440d
2051618
44165b9
a13b6e1
4c852ba
cfc3d0f
95ac96b
493290a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,20 @@ 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'; | ||
|
||
interface Opts { | ||
esClient: ElasticsearchClient; | ||
alertIndex: string; | ||
logger: Logger; | ||
} | ||
|
||
interface MWOpts { | ||
savedObjectsClient: ISavedObjectsRepository; | ||
logger: Logger; | ||
} | ||
|
||
type GetTotalCountsResults = Pick< | ||
AlertingUsage, | ||
| 'count_total' | ||
|
@@ -48,6 +55,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 +505,57 @@ 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; | ||
for await (const response of MWFinder.find()) { | ||
for (const MWSavedObject of response.saved_objects) { | ||
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 ('interval' in MWSavedObject.attributes.rRule) { | ||
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 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. Why do you prefer one to another? 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. The |
||
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, | ||
}; | ||
} | ||
} |
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.
How do you feel about starting variables with a lowercase letter? Like
mwFinder
? Same for all variables in the code starting withMW
.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.
Change everything here: 732374d