Skip to content

Commit

Permalink
[ML] More fine grained latency range selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Aug 4, 2021
1 parent 69b38d2 commit a26728a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,30 @@ export function TransactionDetails() {
}),
});

const selectedSample = flatten(
distributionData.buckets.map((bucket) => bucket.samples)
).find(
(sample) =>
sample.transactionId === urlParams.transactionId &&
sample.traceId === urlParams.traceId
);

const bucketWithSample =
selectedSample &&
distributionData.buckets.find((bucket) =>
bucket.samples.includes(selectedSample)
);

const traceSamples = bucketWithSample?.samples ?? [];
const bucketIndex = bucketWithSample
? distributionData.buckets.indexOf(bucketWithSample)
: -1;
const { sampleRangeFrom, sampleRangeTo } = urlParams;

const selectionFrom = bucketWithSample?.key;
const bucketTo = distributionData.buckets[bucketIndex + 1];
const selectionTo = bucketTo?.key;
const traceSamples: Sample[] =
sampleRangeFrom !== undefined && sampleRangeTo !== undefined
? flatten(
distributionData.buckets
.filter((b) => b.key >= sampleRangeFrom && b.key <= sampleRangeTo)
.map((bucket) => bucket.samples)
)
: flatten(distributionData.buckets.map((bucket) => bucket.samples));

const selectSampleFromChartSelection = (selection: XYBrushArea) => {
if (selection !== undefined) {
const { x } = selection;
if (x !== undefined) {
if (Array.isArray(x)) {
history.push({
...history.location,
search: fromQuery({
...toQuery(history.location.search),
sampleRangeFrom: Math.round(x[0]),
sampleRangeTo: Math.round(x[1]),
}),
});

const filteredSamples: Sample[] = flatten(
distributionData.buckets
.filter((b) => b.key > x[0] && b.key < x[1])
Expand Down Expand Up @@ -132,8 +129,8 @@ export function TransactionDetails() {
<MlLatencyCorrelations
onChartSelection={selectSampleFromChartSelection}
selection={
selectionFrom !== undefined && selectionTo !== undefined
? [selectionFrom, selectionTo]
sampleRangeFrom !== undefined && sampleRangeTo !== undefined
? [sampleRangeFrom, sampleRangeTo]
: undefined
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export function createHref(
}

export type APMQueryParams = {
sampleRangeFrom?: number;
sampleRangeTo?: number;
transactionId?: string;
transactionName?: string;
transactionType?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function resolveUrlParams(location: Location, state: TimeUrlParams) {
const query = toQuery(location.search);

const {
sampleRangeFrom,
sampleRangeTo,
traceId,
transactionId,
transactionName,
Expand Down Expand Up @@ -73,6 +75,8 @@ export function resolveUrlParams(location: Location, state: TimeUrlParams) {
pageSize: pageSize ? toNumber(pageSize) : undefined,
transactionId: toString(transactionId),
traceId: toString(traceId),
sampleRangeFrom: toNumber(sampleRangeFrom),
sampleRangeTo: toNumber(sampleRangeTo),
waterfallItemId: toString(waterfallItemId),
detailTab: toString(detailTab),
flyoutDetailTab: toString(flyoutDetailTab),
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/public/context/url_params_context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type IUrlParams = {
sortDirection?: string;
sortField?: string;
start?: string;
sampleRangeFrom?: number;
sampleRangeTo?: number;
traceId?: string;
transactionId?: string;
transactionName?: string;
Expand Down

0 comments on commit a26728a

Please sign in to comment.