Skip to content
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

[APM] switch get environment function to use terms_enum api #150175

Merged
merged 17 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c1bbce2
switch get environment function to use terms_enum api instead of aggr…
achyutjhunjhunwala Feb 2, 2023
ad1cd3e
pass service as empty string if unavailable
achyutjhunjhunwala Feb 2, 2023
274b7e6
Merge branch 'main' into switch_get_environments_to_terms_enum_api
achyutjhunjhunwala Feb 2, 2023
3f4323b
Merge branch 'main' into switch_get_environments_to_terms_enum_api
achyutjhunjhunwala Feb 6, 2023
9a66237
change environment fetcher logic to use suggestion api when no servic…
achyutjhunjhunwala Feb 6, 2023
9627da0
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 6, 2023
9ac0a17
adjusting environment fetching logic based on useFetcher
achyutjhunjhunwala Feb 6, 2023
b87d22d
Merge remote-tracking branch 'origin/switch_get_environments_to_terms…
achyutjhunjhunwala Feb 6, 2023
f00787e
remove any type to more specific type
achyutjhunjhunwala Feb 7, 2023
3d0f71a
Merge branch 'main' into switch_get_environments_to_terms_enum_api
achyutjhunjhunwala Feb 7, 2023
8758f45
fix logic which broke the inspector component
achyutjhunjhunwala Feb 7, 2023
0a1e907
simplified type for getEnvironments on the server side
achyutjhunjhunwala Feb 7, 2023
122dcaf
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Feb 7, 2023
315ec23
fix final code reviews
achyutjhunjhunwala Feb 7, 2023
4e723d1
add api tests for getEnvironments
achyutjhunjhunwala Feb 7, 2023
f413e8d
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Feb 7, 2023
b05a3a2
Merge branch 'main' into switch_get_environments_to_terms_enum_api
achyutjhunjhunwala Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 19 additions & 34 deletions x-pack/plugins/apm/server/routes/environments/get_environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
* 2.0.
*/

import { rangeQuery, termQuery } from '@kbn/observability-plugin/server';
import { rangeQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
SERVICE_ENVIRONMENT,
SERVICE_NAME,
} from '../../../common/es_fields/apm';
import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
import { SERVICE_ENVIRONMENT } from '../../../common/es_fields/apm';
import { getProcessorEventForTransactions } from '../../lib/helpers/transactions';
import { Environment } from '../../../common/environment_rt';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import {
APMEventClient,
APMEventESTermsEnumRequest,
} from '../../lib/helpers/create_es_client/create_apm_event_client';

/**
* This is used for getting the list of environments for the environments selector,
* This is used for getting the list of environments for the environment's selector,
* filtered by range.
*/

export async function getEnvironments({
searchAggregatedTransactions,
serviceName,
Expand All @@ -39,44 +39,29 @@ export async function getEnvironments({
? 'get_environments_for_service'
: 'get_environments';

const params = {
const params: APMEventESTermsEnumRequest = {
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
apm: {
events: [
getProcessorEventForTransactions(searchAggregatedTransactions),
ProcessorEvent.metric,
ProcessorEvent.error,
],
},
body: {
track_total_hits: false,
size: 0,
query: {
bool: {
filter: [
...rangeQuery(start, end),
...termQuery(SERVICE_NAME, serviceName),
],
},
},
aggs: {
environments: {
terms: {
field: SERVICE_ENVIRONMENT,
missing: ENVIRONMENT_NOT_DEFINED.value,
size,
},
},
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
size,
field: SERVICE_ENVIRONMENT,
index_filter: {
bool: {
filter: [...rangeQuery(start, end)],
},
},
};

const resp = await apmEventClient.search(operationName, params);
const aggs = resp.aggregations;
const environmentsBuckets = aggs?.environments.buckets || [];
if (serviceName) {
params.string = serviceName;
}
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved

const environments = environmentsBuckets.map(
(environmentBucket) => environmentBucket.key as string
);
const resp = await apmEventClient.termsEnum(operationName, params);
const environments = resp.terms || [];

return environments as Environment[];
}