Skip to content

Commit

Permalink
[ML] Fix waterfall message if no trace samples can be found. Fix clea…
Browse files Browse the repository at this point in the history
…r selection to display correct annotation and first sample.
  • Loading branch information
walterra committed Aug 16, 2021
1 parent ca6b687 commit 3d80d2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import { omit } from 'lodash';
import { useHistory } from 'react-router-dom';

import { XYBrushArea } from '@elastic/charts';
Expand All @@ -16,6 +17,7 @@ import { useUrlParams } from '../../../context/url_params_context/use_url_params
import { useApmParams } from '../../../hooks/use_apm_params';
import { useTransactionTraceSamplesFetcher } from '../../../hooks/use_transaction_trace_samples_fetcher';

import { maybe } from '../../../../common/utils/maybe';
import { HeightRetainer } from '../../shared/HeightRetainer';
import { fromQuery, push, toQuery } from '../../shared/Links/url_helpers';

Expand Down Expand Up @@ -62,22 +64,46 @@ export function TransactionDetailsTabs() {
}
};

const { sampleRangeFrom, sampleRangeTo } = urlParams;
const { sampleRangeFrom, sampleRangeTo, transactionId, traceId } = urlParams;
const { traceSamples } = traceSamplesData;

const clearChartSelection = () => {
const firstSample = traceSamples[0];

// enforces a reset of the current sample to be highlighted in the chart
// and selected in waterfall section below, otherwise we end up with
// stale data for the selected sample
push(history, {
query: {
sampleRangeFrom: '',
sampleRangeTo: '',
transactionId: firstSample?.transactionId,
traceId: firstSample?.traceId,
traceId: '',
transactionId: '',
},
});
};

useEffect(() => {
const selectedSample = traceSamples.find(
(sample) =>
sample.transactionId === transactionId && sample.traceId === traceId
);

if (!selectedSample) {
// selected sample was not found. select a new one:
const preferredSample = maybe(traceSamples[0]);

history.replace({
...history.location,
search: fromQuery({
...omit(toQuery(history.location.search), [
'traceId',
'transactionId',
]),
...preferredSample,
}),
});
}
}, [history, traceSamples, transactionId, traceId]);

return (
<>
<EuiTabs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
* 2.0.
*/

import { omit } from 'lodash';
import { useHistory } from 'react-router-dom';
import { useFetcher } from './use_fetcher';
import { toQuery, fromQuery } from '../components/shared/Links/url_helpers';
import { maybe } from '../../common/utils/maybe';
import { useUrlParams } from '../context/url_params_context/use_url_params';
import { useApmServiceContext } from '../context/apm_service/use_apm_service_context';

Expand Down Expand Up @@ -45,7 +41,6 @@ export function useTransactionTraceSamplesFetcher({
},
} = useUrlParams();

const history = useHistory();
const { data = INITIAL_DATA, status, error } = useFetcher(
async (callApmApi) => {
if (serviceName && start && end && transactionType && transactionName) {
Expand Down Expand Up @@ -77,27 +72,6 @@ export function useTransactionTraceSamplesFetcher({

const { traceSamples } = response;

const selectedSample = traceSamples.find(
(sample) =>
sample.transactionId === transactionId && sample.traceId === traceId
);

if (!selectedSample) {
// selected sample was not found. select a new one:
const preferredSample = maybe(traceSamples[0]);

history.replace({
...history.location,
search: fromQuery({
...omit(toQuery(history.location.search), [
'traceId',
'transactionId',
]),
...preferredSample,
}),
});
}

return {
noHits: false,
traceSamples,
Expand Down

0 comments on commit 3d80d2d

Please sign in to comment.