-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SLOS] fix APM group by cardinality count (#183171)
## Summary Resolves #179046 Summarize your PR. If it involves visual changes include a screenshot or gif. Applies filters based on the selected APM indicator params to the cardinality count query. <img width="845" alt="Screenshot 2024-05-10 at 1 07 27 PM" src="https://github.com/elastic/kibana/assets/11356435/7283f7cc-b141-47e2-883e-e463556e4aec"> ### Testing. 1. Create mock api data via `node scripts/synthtrace continuous_rollups --live` 2. Navigate to create SLI and choose APM latency 3. Select a service 4. Select group by as `service.name`. Cardinality count should be 1 5. Select environment all and change the group by to `service.environment`. Cardinality count should be 2. 6. Now select a specific environment. Notice cardinality count changes to 1. 7. Repeat this testing strategy with transaction name and transaction type, changing the group by field to `transaction.name` or `transaction.type`, respectively and playing around with the ALL_VALUE versus a specific value. 8. Also make sure to test the global filter for regressions ### Release note The cardinality count for SLOs generated from a single SLI definition was previously incorrect for APM latency and APM availability SLIs. The cardinality count is now accurate.
- Loading branch information
1 parent
3ecd73c
commit d3945a3
Showing
11 changed files
with
625 additions
and
301 deletions.
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
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
112 changes: 112 additions & 0 deletions
112
.../slo/public/pages/slo_edit/components/apm_common/get_group_by_cardinality_filters.test.ts
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,112 @@ | ||
/* | ||
* 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 { getGroupByCardinalityFilters } from './get_group_by_cardinality_filters'; | ||
import { ALL_VALUE } from '@kbn/slo-schema'; | ||
|
||
describe('get group by cardinality filters', () => { | ||
it('formats filters correctly', () => { | ||
const serviceName = 'testService'; | ||
const environment = 'testEnvironment'; | ||
const transactionName = 'testTransactionName'; | ||
const transactionType = 'testTransactionType'; | ||
expect( | ||
getGroupByCardinalityFilters({ serviceName, environment, transactionName, transactionType }) | ||
).toEqual([ | ||
{ | ||
$state: { store: 'appState' }, | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
key: 'service.name', | ||
negate: false, | ||
params: serviceName, | ||
type: 'phrases', | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { match_phrase: { 'service.name': serviceName } }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
$state: { store: 'appState' }, | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
key: 'service.environment', | ||
negate: false, | ||
params: environment, | ||
type: 'phrases', | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { match_phrase: { 'service.environment': environment } }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
$state: { store: 'appState' }, | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
key: 'transaction.type', | ||
negate: false, | ||
params: transactionType, | ||
type: 'phrases', | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { match_phrase: { 'transaction.type': transactionType } }, | ||
}, | ||
}, | ||
}, | ||
{ | ||
$state: { store: 'appState' }, | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
key: 'transaction.name', | ||
negate: false, | ||
params: transactionName, | ||
type: 'phrases', | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { match_phrase: { 'transaction.name': transactionName } }, | ||
}, | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it('does not include filters when values are undefined', () => { | ||
expect( | ||
getGroupByCardinalityFilters({ | ||
// @ts-ignore | ||
serviceName: undefined, | ||
environment: undefined, | ||
transactionName: undefined, | ||
transactionType: undefined, | ||
}) | ||
).toEqual([]); | ||
}); | ||
|
||
it('does not include filters when values are ALL_VALUE', () => { | ||
expect( | ||
getGroupByCardinalityFilters({ | ||
serviceName: ALL_VALUE, | ||
environment: ALL_VALUE, | ||
transactionName: ALL_VALUE, | ||
transactionType: ALL_VALUE, | ||
}) | ||
).toEqual([]); | ||
}); | ||
}); |
135 changes: 135 additions & 0 deletions
135
...ution/slo/public/pages/slo_edit/components/apm_common/get_group_by_cardinality_filters.ts
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,135 @@ | ||
/* | ||
* 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 { ALL_VALUE, FiltersSchema } from '@kbn/slo-schema'; | ||
import { FilterStateStore } from '@kbn/es-query'; | ||
|
||
export const getGroupByCardinalityFilters = ({ | ||
serviceName, | ||
environment, | ||
transactionType, | ||
transactionName, | ||
}: { | ||
serviceName: string; | ||
environment?: string; | ||
transactionType?: string; | ||
transactionName?: string; | ||
}): FiltersSchema => { | ||
const serviceNameFilter = | ||
serviceName && serviceName !== ALL_VALUE | ||
? { | ||
meta: { | ||
disabled: false, | ||
negate: false, | ||
alias: null, | ||
key: 'service.name', | ||
params: serviceName, | ||
type: 'phrases', | ||
}, | ||
$state: { | ||
store: FilterStateStore.APP_STATE, | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { | ||
match_phrase: { | ||
'service.name': serviceName, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
: null; | ||
|
||
const environmentFilter = | ||
environment && environment !== ALL_VALUE | ||
? { | ||
meta: { | ||
disabled: false, | ||
negate: false, | ||
alias: null, | ||
key: 'service.environment', | ||
params: environment, | ||
type: 'phrases', | ||
}, | ||
$state: { | ||
store: FilterStateStore.APP_STATE, | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { | ||
match_phrase: { | ||
'service.environment': environment, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
: null; | ||
|
||
const transactionTypeFilter = | ||
transactionType && transactionType !== ALL_VALUE | ||
? { | ||
meta: { | ||
disabled: false, | ||
negate: false, | ||
alias: null, | ||
key: 'transaction.type', | ||
params: transactionType, | ||
type: 'phrases', | ||
}, | ||
$state: { | ||
store: FilterStateStore.APP_STATE, | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { | ||
match_phrase: { | ||
'transaction.type': transactionType, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
: null; | ||
|
||
const transactionNameFilter = | ||
transactionName && transactionName !== ALL_VALUE | ||
? { | ||
meta: { | ||
disabled: false, | ||
negate: false, | ||
alias: null, | ||
key: 'transaction.name', | ||
params: transactionName, | ||
type: 'phrases', | ||
}, | ||
$state: { | ||
store: FilterStateStore.APP_STATE, | ||
}, | ||
query: { | ||
bool: { | ||
minimum_should_match: 1, | ||
should: { | ||
match_phrase: { | ||
'transaction.name': transactionName, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
: null; | ||
|
||
return [ | ||
serviceNameFilter, | ||
environmentFilter, | ||
transactionTypeFilter, | ||
transactionNameFilter, | ||
].filter((value) => !!value) as FiltersSchema; | ||
}; |
Oops, something went wrong.