-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[APM] Support specific fields when creating service groups (#142201) #143881
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
Merged
ogupte
merged 18 commits into
elastic:main
from
ogupte:apm-142201-service-groups-dimensions
Oct 29, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
be46156
[APM] Support specific fields when creating service groups (#142201)
ogupte d5f5a19
add support to anomaly rule type to store supported service group fie…
ogupte 401d3da
address PR feedback and fixes checks
ogupte 516f987
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 0abc855
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine e4c4743
add API tests for field validation
ogupte 198589b
fixes linting
ogupte 9ec7cf3
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 112edf6
fixes multi_terms sort order paths, for each rule type query
ogupte 081b2cd
adds unit tests and moves some source files
ogupte 324a820
Merge branch 'main' into apm-142201-service-groups-dimensions
ogupte 0ae856e
Merge branch 'main' into apm-142201-service-groups-dimensions
ogupte 4152d06
Merge branch 'main' into apm-142201-service-groups-dimensions
ogupte 9a91b16
fixed back import path
ogupte 0940bf3
PR feedback
ogupte b446737
Merge branch 'main' into apm-142201-service-groups-dimensions
ogupte 51fcde7
improvements to kuery validation
ogupte f3bb573
fixes selecting 'All' in service.name, transaction.type fields when c…
ogupte 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 hidden or 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,67 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| import { | ||
| isSupportedField, | ||
| validateServiceGroupKuery, | ||
| SERVICE_GROUP_SUPPORTED_FIELDS, | ||
| } from './service_groups'; | ||
| import { | ||
| TRANSACTION_TYPE, | ||
| TRANSACTION_DURATION, | ||
| SERVICE_FRAMEWORK_VERSION, | ||
| } from './elasticsearch_fieldnames'; | ||
|
|
||
| describe('service_groups common utils', () => { | ||
| describe('isSupportedField', () => { | ||
| it('should allow supported fields', () => { | ||
| SERVICE_GROUP_SUPPORTED_FIELDS.map((field) => { | ||
| expect(isSupportedField(field)).toBe(true); | ||
| }); | ||
| }); | ||
| it('should reject unsupported fields', () => { | ||
| const unsupportedFields = [ | ||
| TRANSACTION_TYPE, | ||
| TRANSACTION_DURATION, | ||
| SERVICE_FRAMEWORK_VERSION, | ||
| ]; | ||
| unsupportedFields.map((field) => { | ||
| expect(isSupportedField(field)).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
| describe('validateServiceGroupKuery', () => { | ||
| it('should validate supported KQL filter for a service group', () => { | ||
| const result = validateServiceGroupKuery( | ||
| `service.name: testbeans* or agent.name: "nodejs"` | ||
| ); | ||
| expect(result).toHaveProperty('isValidFields', true); | ||
| expect(result).toHaveProperty('isValidSyntax', true); | ||
| expect(result).not.toHaveProperty('message'); | ||
| }); | ||
| it('should return validation error when unsupported fields are used', () => { | ||
| const result = validateServiceGroupKuery( | ||
| `service.name: testbeans* or agent.name: "nodejs" or transaction.type: request` | ||
| ); | ||
| expect(result).toHaveProperty('isValidFields', false); | ||
| expect(result).toHaveProperty('isValidSyntax', true); | ||
| expect(result).toHaveProperty( | ||
| 'message', | ||
| 'Query filter for service group does not support fields [transaction.type]' | ||
| ); | ||
| }); | ||
| it('should return parsing error when KQL is incomplete', () => { | ||
| const result = validateServiceGroupKuery( | ||
| `service.name: testbeans* or agent.name: "nod` | ||
| ); | ||
| expect(result).toHaveProperty('isValidFields', false); | ||
| expect(result).toHaveProperty('isValidSyntax', false); | ||
| expect(result).toHaveProperty('message'); | ||
| expect(result).not.toBe(''); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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
91 changes: 91 additions & 0 deletions
91
...ugins/apm/server/routes/alerts/rule_types/anomaly/get_service_group_fields_for_anomaly.ts
This file contains hidden or 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,91 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import { firstValueFrom } from 'rxjs'; | ||
| import { | ||
| IScopedClusterClient, | ||
| SavedObjectsClientContract, | ||
| } from '@kbn/core/server'; | ||
| import { | ||
| SERVICE_ENVIRONMENT, | ||
| SERVICE_NAME, | ||
| TRANSACTION_TYPE, | ||
| TRANSACTION_DURATION, | ||
| } from '../../../../../common/elasticsearch_fieldnames'; | ||
| import { alertingEsClient } from '../../alerting_es_client'; | ||
| import { | ||
| getServiceGroupFields, | ||
| getServiceGroupFieldsAgg, | ||
| } from '../get_service_group_fields'; | ||
| import { getApmIndices } from '../../../settings/apm_indices/get_apm_indices'; | ||
| import { RegisterRuleDependencies } from '../../register_apm_rule_types'; | ||
|
|
||
| export async function getServiceGroupFieldsForAnomaly({ | ||
| config$, | ||
| scopedClusterClient, | ||
| savedObjectsClient, | ||
| serviceName, | ||
| environment, | ||
| transactionType, | ||
| timestamp, | ||
| bucketSpan, | ||
| }: { | ||
| config$: RegisterRuleDependencies['config$']; | ||
| scopedClusterClient: IScopedClusterClient; | ||
| savedObjectsClient: SavedObjectsClientContract; | ||
| serviceName: string; | ||
| environment: string; | ||
| transactionType: string; | ||
| timestamp: number; | ||
| bucketSpan: number; | ||
| }) { | ||
| const config = await firstValueFrom(config$); | ||
| const indices = await getApmIndices({ | ||
| config, | ||
| savedObjectsClient, | ||
| }); | ||
| const { transaction: index } = indices; | ||
|
|
||
| const params = { | ||
| index, | ||
| body: { | ||
| size: 0, | ||
| track_total_hits: false, | ||
| query: { | ||
| bool: { | ||
| filter: [ | ||
| { term: { [SERVICE_NAME]: serviceName } }, | ||
| { term: { [TRANSACTION_TYPE]: transactionType } }, | ||
| { term: { [SERVICE_ENVIRONMENT]: environment } }, | ||
| { | ||
| range: { | ||
| '@timestamp': { | ||
| gte: timestamp, | ||
| lte: timestamp + bucketSpan * 1000, | ||
| format: 'epoch_millis', | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| aggs: { | ||
| ...getServiceGroupFieldsAgg({ | ||
| sort: [{ [TRANSACTION_DURATION]: { order: 'desc' as const } }], | ||
| }), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const response = await alertingEsClient({ | ||
| scopedClusterClient, | ||
| params, | ||
| }); | ||
| if (!response.aggregations) { | ||
| return {}; | ||
| } | ||
| return getServiceGroupFields(response.aggregations); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.