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 13 commits
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
33 changes: 27 additions & 6 deletions x-pack/plugins/apm/public/hooks/use_environments_fetcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* 2.0.
*/

import { SERVICE_ENVIRONMENT } from '../../common/es_fields/apm';
import { useFetcher } from './use_fetcher';

const INITIAL_DATA = { environments: [] };
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved

import { Environment } from '../../common/environment_rt';
export function useEnvironmentsFetcher({
serviceName,
start,
Expand All @@ -18,9 +17,13 @@ export function useEnvironmentsFetcher({
start?: string;
end?: string;
}) {
const { data = INITIAL_DATA, status } = useFetcher(
const { data, status } = useFetcher(
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
(callApmApi) => {
if (start && end) {
if (!start || !end) {
return;
}

if (serviceName) {
return callApmApi('GET /internal/apm/environments', {
params: {
query: {
Expand All @@ -29,11 +32,29 @@ export function useEnvironmentsFetcher({
serviceName,
},
},
}).then((response) => {
// Spreading of original response is needed in order to display the api call in the inspector
return { ...response, environments: response.environments };
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
});
}
return callApmApi('GET /internal/apm/suggestions', {
params: {
query: {
start,
end,
fieldName: SERVICE_ENVIRONMENT,
fieldValue: '',
},
},
}).then((response) => {
return { ...response, environments: response.terms };
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
});
},
[start, end, serviceName]
);

return { environments: data.environments, status };
return {
environments: (data?.environments ?? []) as Environment[],
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
status,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Environment } from '../../../common/environment_rt';
import { APMEventClient } 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 selector,
* filtered by range.
*/
export async function getEnvironments({
Expand Down
7 changes: 2 additions & 5 deletions x-pack/plugins/apm/server/routes/environments/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import * as t from 'io-ts';
import { maxSuggestions } from '@kbn/observability-plugin/common';
import { Environment } from '../../../common/environment_rt';
import { getSearchTransactionsEvents } from '../../lib/helpers/transactions';
import { getEnvironments } from './get_environments';
import { rangeRt } from '../default_api_types';
Expand All @@ -27,11 +28,7 @@ const environmentsRoute = createApmServerRoute({
handler: async (
resources
): Promise<{
environments: Array<
| 'ENVIRONMENT_NOT_DEFINED'
| 'ENVIRONMENT_ALL'
| t.Branded<string, import('@kbn/io-ts-utils').NonEmptyStringBrand>
>;
environments: Environment[];
}> => {
const apmEventClient = await getApmEventClient(resources);
const { context, params, config } = resources;
Expand Down