Skip to content
/ kibana Public
forked from elastic/kibana

Commit

Permalink
Show ML jobs on chart when only one environment
Browse files Browse the repository at this point in the history
Make it so if you're looking at the latency chart for a service with only one environment, while the environment selector is set to "All", it uses the single environment so the ML will be shown.

It does this by overriding the uiFilters in this case.

Rename the exported function from use_transaction_latency_chart_fetcher to match the file name.

Fixes elastic#86775.
  • Loading branch information
smith committed Jan 5, 2021
1 parent ff94674 commit 510acdd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LatencyAggregationType } from '../../../../../common/latency_aggregatio
import { getDurationFormatter } from '../../../../../common/utils/formatters';
import { useLicenseContext } from '../../../../context/license/use_license_context';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { useTransactionLatencyChartsFetcher } from '../../../../hooks/use_transaction_latency_chart_fetcher';
import { useTransactionLatencyChartFetcher } from '../../../../hooks/use_transaction_latency_chart_fetcher';
import { TimeseriesChart } from '../../../shared/charts/timeseries_chart';
import {
getMaxY,
Expand Down Expand Up @@ -40,7 +40,7 @@ export function LatencyChart({ height }: Props) {
const {
latencyChartsData,
latencyChartsStatus,
} = useTransactionLatencyChartsFetcher();
} = useTransactionLatencyChartFetcher();

const { latencyTimeseries, anomalyTimeseries, mlJobId } = latencyChartsData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

import { useMemo } from 'react';
import { useParams } from 'react-router-dom';
import { useFetcher } from './use_fetcher';
import { useUrlParams } from '../context/url_params_context/use_url_params';
import { useApmServiceContext } from '../context/apm_service/use_apm_service_context';
import { useUrlParams } from '../context/url_params_context/use_url_params';
import { getLatencyChartSelector } from '../selectors/latency_chart_selectors';
import { useTheme } from './use_theme';
import { useEnvironmentsFetcher } from './use_environments_fetcher';
import { useFetcher } from './use_fetcher';
import { useLatencyAggregationType } from './use_latency_Aggregation_type';
import { useTheme } from './use_theme';

export function useTransactionLatencyChartsFetcher() {
export function useTransactionLatencyChartFetcher() {
const { serviceName } = useParams<{ serviceName?: string }>();
const { transactionType } = useApmServiceContext();
const latencyAggregationType = useLatencyAggregationType();
Expand All @@ -22,15 +23,30 @@ export function useTransactionLatencyChartsFetcher() {
urlParams: { start, end, transactionName },
uiFilters,
} = useUrlParams();
const { environments } = useEnvironmentsFetcher({ start, end, serviceName });

const { data, error, status } = useFetcher(
(callApmApi) => {
// If we have "All" selected in the environment selector, there won't be
// any ML jobs for the "All" environment. If we have a single environment
// (fetched with the `useEnvironmentsFetcher`) we can safely assume the
// user would want to see ML data for that single environment.
//
// We modify the uiFilters here, which is not advised, but the uiFilters
// are what's used to specify the environment when using this endpoint.
const environmentCount = environments.length;
const modifiedUiFilters =
environmentCount === 1
? { ...uiFilters, environment: environments[0] }
: uiFilters;

if (
serviceName &&
start &&
end &&
transactionType &&
latencyAggregationType
latencyAggregationType &&
environmentCount > 0
) {
return callApmApi({
endpoint:
Expand All @@ -42,14 +58,15 @@ export function useTransactionLatencyChartsFetcher() {
end,
transactionType,
transactionName,
uiFilters: JSON.stringify(uiFilters),
uiFilters: JSON.stringify(modifiedUiFilters),
latencyAggregationType,
},
},
});
}
},
[
environments,
serviceName,
start,
end,
Expand Down

0 comments on commit 510acdd

Please sign in to comment.