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

[User Experience App] Update to make sure env filter is being used #102063

Merged
merged 3 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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.

45 changes: 27 additions & 18 deletions x-pack/plugins/apm/server/lib/rum_client/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getRumServices } from './get_rum_services';
import { getLongTaskMetrics } from './get_long_task_metrics';
import { getWebCoreVitals } from './get_web_core_vitals';
import { getJSErrors } from './get_js_errors';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';

describe('rum client dashboard queries', () => {
let mock: SearchParamsMock;
Expand All @@ -25,32 +26,38 @@ describe('rum client dashboard queries', () => {
});

it('fetches client metrics', async () => {
mock = await inspectSearchParams((setup) =>
getClientMetrics({
setup,
})
mock = await inspectSearchParams(
(setup) =>
getClientMetrics({
setup,
}),
{ uiFilters: { environment: 'staging' } }
);

expect(mock.params).toMatchSnapshot();
});

it('fetches page view trends', async () => {
mock = await inspectSearchParams((setup) =>
getPageViewTrends({
setup,
})
mock = await inspectSearchParams(
(setup) =>
getPageViewTrends({
setup,
}),
{ uiFilters: { environment: 'staging' } }
);

expect(mock.params).toMatchSnapshot();
});

it('fetches page load distribution', async () => {
mock = await inspectSearchParams((setup) =>
getPageLoadDistribution({
setup,
minPercentile: '0',
maxPercentile: '99',
})
mock = await inspectSearchParams(
(setup) =>
getPageLoadDistribution({
setup,
minPercentile: '0',
maxPercentile: '99',
}),
{ uiFilters: { environment: 'staging' } }
);
expect(mock.params).toMatchSnapshot();
});
Expand All @@ -65,10 +72,12 @@ describe('rum client dashboard queries', () => {
});

it('fetches rum core vitals', async () => {
mock = await inspectSearchParams((setup) =>
getWebCoreVitals({
setup,
})
mock = await inspectSearchParams(
(setup) =>
getWebCoreVitals({
setup,
}),
{ uiFilters: { environment: ENVIRONMENT_ALL.value } }
);
expect(mock.params).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { ESFilter } from '../../../../../../../typings/elasticsearch';
import { UIFilters } from '../../../../typings/ui_filters';
import { localUIFilters, localUIFilterNames } from './local_ui_filters/config';
import { SERVICE_ENVIRONMENT } from '../../../../common/elasticsearch_fieldnames';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';

export function getEsFilter(uiFilters: UIFilters) {
const localFilterValues = uiFilters;
Expand All @@ -23,5 +25,16 @@ export function getEsFilter(uiFilters: UIFilters) {
};
}) as ESFilter[];

if (
uiFilters.environment &&
uiFilters.environment !== ENVIRONMENT_ALL.value
) {
mappedFilters.push({
term: {
[SERVICE_ENVIRONMENT]: uiFilters.environment,
},
});
}

return mappedFilters;
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/utils/test_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Options {
mockResponse?: (
request: ESSearchRequest
) => ESSearchResponse<unknown, ESSearchRequest>;
uiFilters?: Record<string, string>;
}

interface MockSetup {
Expand Down Expand Up @@ -86,7 +87,7 @@ export async function inspectSearchParams(
},
}
) as APMConfig,
uiFilters: {},
uiFilters: options?.uiFilters ?? {},
indices: {
/* eslint-disable @typescript-eslint/naming-convention */
'apm_oss.sourcemapIndices': 'myIndex',
Expand Down