Skip to content

Commit

Permalink
Remove environment from uiFilters (#89647)
Browse files Browse the repository at this point in the history
  • Loading branch information
smith authored Feb 17, 2021
1 parent a3dfecb commit f650c38
Show file tree
Hide file tree
Showing 122 changed files with 757 additions and 528 deletions.
33 changes: 33 additions & 0 deletions x-pack/plugins/apm/common/utils/queries.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { SERVICE_ENVIRONMENT } from '../elasticsearch_fieldnames';
import { ENVIRONMENT_NOT_DEFINED } from '../environment_filter_values';
import { environmentQuery } from './queries';

describe('environmentQuery', () => {
describe('when environment is undefined', () => {
it('returns an empty query', () => {
expect(environmentQuery()).toEqual([]);
});
});

it('creates a query for a service environment', () => {
expect(environmentQuery('test')).toEqual([
{
term: { [SERVICE_ENVIRONMENT]: 'test' },
},
]);
});

it('creates a query for missing service environments', () => {
expect(environmentQuery(ENVIRONMENT_NOT_DEFINED.value)[0]).toHaveProperty(
['bool', 'must_not', 'exists', 'field'],
SERVICE_ENVIRONMENT
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,41 @@
* 2.0.
*/

import { ESFilter } from '../../../../../../typings/elasticsearch';
import { ESFilter } from '../../../../typings/elasticsearch';
import {
ENVIRONMENT_NOT_DEFINED,
ENVIRONMENT_ALL,
} from '../../../../common/environment_filter_values';
import { SERVICE_ENVIRONMENT } from '../../../../common/elasticsearch_fieldnames';
} from '../environment_filter_values';
import { SERVICE_ENVIRONMENT } from '../elasticsearch_fieldnames';

export function getEnvironmentUiFilterES(environment?: string): ESFilter[] {
type QueryContainer = ESFilter;

export function environmentQuery(environment?: string): QueryContainer[] {
if (!environment || environment === ENVIRONMENT_ALL.value) {
return [];
}

if (environment === ENVIRONMENT_NOT_DEFINED.value) {
return [{ bool: { must_not: { exists: { field: SERVICE_ENVIRONMENT } } } }];
}

return [{ term: { [SERVICE_ENVIRONMENT]: environment } }];
}

export function rangeQuery(
start: number,
end: number,
field = '@timestamp'
): QueryContainer[] {
return [
{
range: {
[field]: {
gte: start,
lte: end,
format: 'epoch_millis',
},
},
},
];
}
16 changes: 0 additions & 16 deletions x-pack/plugins/apm/common/utils/range_filter.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type ErrorGroupDetailsProps = RouteComponentProps<{
export function ErrorGroupDetails({ location, match }: ErrorGroupDetailsProps) {
const { serviceName, groupId } = match.params;
const { urlParams, uiFilters } = useUrlParams();
const { start, end } = urlParams;
const { environment, start, end } = urlParams;

const { data: errorGroupData } = useFetcher(
(callApmApi) => {
Expand All @@ -81,6 +81,7 @@ export function ErrorGroupDetails({ location, match }: ErrorGroupDetailsProps) {
groupId,
},
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
Expand All @@ -89,7 +90,7 @@ export function ErrorGroupDetails({ location, match }: ErrorGroupDetailsProps) {
});
}
},
[serviceName, start, end, groupId, uiFilters]
[environment, serviceName, start, end, groupId, uiFilters]
);

const { errorDistributionData } = useErrorGroupDistributionFetcher({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ export function ErrorCorrelations({ onClose }: Props) {

const { serviceName } = useParams<{ serviceName?: string }>();
const { urlParams, uiFilters } = useUrlParams();
const { transactionName, transactionType, start, end } = urlParams;
const {
environment,
transactionName,
transactionType,
start,
end,
} = urlParams;
const { defaultFieldNames } = useFieldNames();
const [fieldNames, setFieldNames] = useLocalStorage(
`apm.correlations.errors.fields:${serviceName}`,
Expand All @@ -65,6 +71,7 @@ export function ErrorCorrelations({ onClose }: Props) {
endpoint: 'GET /api/apm/correlations/failed_transactions',
params: {
query: {
environment,
serviceName,
transactionName,
transactionType,
Expand All @@ -78,6 +85,7 @@ export function ErrorCorrelations({ onClose }: Props) {
}
},
[
environment,
serviceName,
start,
end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export function LatencyCorrelations({ onClose }: Props) {

const { serviceName } = useParams<{ serviceName?: string }>();
const { urlParams, uiFilters } = useUrlParams();
const { transactionName, transactionType, start, end } = urlParams;
const {
environment,
transactionName,
transactionType,
start,
end,
} = urlParams;
const { defaultFieldNames } = useFieldNames();
const [fieldNames, setFieldNames] = useLocalStorage(
`apm.correlations.latency.fields:${serviceName}`,
Expand All @@ -70,6 +76,7 @@ export function LatencyCorrelations({ onClose }: Props) {
endpoint: 'GET /api/apm/correlations/slow_transactions',
params: {
query: {
environment,
serviceName,
transactionName,
transactionType,
Expand All @@ -84,6 +91,7 @@ export function LatencyCorrelations({ onClose }: Props) {
}
},
[
environment,
serviceName,
start,
end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ErrorGroupOverviewProps {

export function ErrorGroupOverview({ serviceName }: ErrorGroupOverviewProps) {
const { urlParams, uiFilters } = useUrlParams();
const { start, end, sortField, sortDirection } = urlParams;
const { environment, start, end, sortField, sortDirection } = urlParams;
const { errorDistributionData } = useErrorGroupDistributionFetcher({
serviceName,
groupId: undefined,
Expand All @@ -46,6 +46,7 @@ export function ErrorGroupOverview({ serviceName }: ErrorGroupOverviewProps) {
serviceName,
},
query: {
environment,
start,
end,
sortField,
Expand All @@ -56,7 +57,7 @@ export function ErrorGroupOverview({ serviceName }: ErrorGroupOverviewProps) {
});
}
},
[serviceName, start, end, sortField, sortDirection, uiFilters]
[environment, serviceName, start, end, sortField, sortDirection, uiFilters]
);

useTrackPageview({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@ function useServicesFetcher() {
const { urlParams, uiFilters } = useUrlParams();
const { core } = useApmPluginContext();
const upgradeAssistantHref = useUpgradeAssistantHref();
const { start, end } = urlParams;
const { environment, start, end } = urlParams;
const { data = initialData, status } = useFetcher(
(callApmApi) => {
if (start && end) {
return callApmApi({
endpoint: 'GET /api/apm/services',
params: {
query: { start, end, uiFilters: JSON.stringify(uiFilters) },
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
},
},
});
}
},
[start, end, uiFilters]
[environment, start, end, uiFilters]
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import {
ENVIRONMENT_ALL,
getNextEnvironmentUrlParam,
} from '../../../../../common/environment_filter_values';
import { getNextEnvironmentUrlParam } from '../../../../../common/environment_filter_values';
import {
asMillisecondDuration,
asPercent,
Expand Down Expand Up @@ -182,7 +179,7 @@ export function ServiceOverviewDependenciesTable({ serviceName }: Props) {
query: {
start,
end,
environment: environment || ENVIRONMENT_ALL.value,
environment,
numBuckets: 20,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const DEFAULT_SORT = {

export function ServiceOverviewErrorsTable({ serviceName }: Props) {
const {
urlParams: { start, end },
urlParams: { environment, start, end },
uiFilters,
} = useUrlParams();
const { transactionType } = useApmServiceContext();
Expand Down Expand Up @@ -152,6 +152,7 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
params: {
path: { serviceName },
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
Expand All @@ -178,6 +179,7 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
});
},
[
environment,
start,
end,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function ServiceOverviewInstancesChartAndTable({
const { transactionType } = useApmServiceContext();

const {
urlParams: { start, end },
urlParams: { environment, start, end },
uiFilters,
} = useUrlParams();

Expand All @@ -43,6 +43,7 @@ export function ServiceOverviewInstancesChartAndTable({
serviceName,
},
query: {
environment,
start,
end,
transactionType,
Expand All @@ -52,7 +53,7 @@ export function ServiceOverviewInstancesChartAndTable({
},
});
},
[start, end, serviceName, transactionType, uiFilters]
[environment, start, end, serviceName, transactionType, uiFilters]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function ServiceOverviewThroughputChart({
const { serviceName } = useParams<{ serviceName?: string }>();
const { urlParams, uiFilters } = useUrlParams();
const { transactionType } = useApmServiceContext();
const { start, end } = urlParams;
const { environment, start, end } = urlParams;

const { data = INITIAL_STATE, status } = useFetcher(
(callApmApi) => {
Expand All @@ -42,6 +42,7 @@ export function ServiceOverviewThroughputChart({
serviceName,
},
query: {
environment,
start,
end,
transactionType,
Expand All @@ -51,7 +52,7 @@ export function ServiceOverviewThroughputChart({
});
}
},
[serviceName, start, end, uiFilters, transactionType]
[environment, serviceName, start, end, uiFilters, transactionType]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
const { transactionType } = useApmServiceContext();
const {
uiFilters,
urlParams: { start, end, latencyAggregationType },
urlParams: { environment, start, end, latencyAggregationType },
} = useUrlParams();

const { data = INITIAL_STATE, status } = useFetcher(
Expand All @@ -72,6 +72,7 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
params: {
path: { serviceName },
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
Expand All @@ -87,6 +88,7 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
});
},
[
environment,
serviceName,
start,
end,
Expand Down Expand Up @@ -125,6 +127,7 @@ export function ServiceOverviewTransactionsTable({ serviceName }: Props) {
params: {
path: { serviceName },
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ const DEFAULT_RESPONSE: TracesAPIResponse = {

export function TraceOverview() {
const { urlParams, uiFilters } = useUrlParams();
const { start, end } = urlParams;
const { environment, start, end } = urlParams;
const { status, data = DEFAULT_RESPONSE } = useFetcher(
(callApmApi) => {
if (start && end) {
return callApmApi({
endpoint: 'GET /api/apm/traces',
params: {
query: {
environment,
start,
end,
uiFilters: JSON.stringify(uiFilters),
Expand All @@ -39,7 +40,7 @@ export function TraceOverview() {
});
}
},
[start, end, uiFilters]
[environment, start, end, uiFilters]
);

useTrackPageview({ app: 'apm', path: 'traces_overview' });
Expand Down
Loading

0 comments on commit f650c38

Please sign in to comment.