Skip to content

Commit

Permalink
[APM] Migrate remaining tx-based visualisations (#153375)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar authored Mar 29, 2023
1 parent 0ee2368 commit 01098bc
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { APIReturnType } from '../../../../services/rest/create_call_apm_api';
import { errorRateI18n } from '../../../shared/charts/failed_transaction_rate_chart';
import { TimeseriesChart } from '../../../shared/charts/timeseries_chart';
import { yLabelFormat } from './helpers';
import { usePreferredDataSourceAndBucketSize } from '../../../../hooks/use_preferred_data_source_and_bucket_size';
import { ApmDocumentType } from '../../../../../common/document_type';

type ErrorRate =
APIReturnType<'GET /internal/apm/services/{serviceName}/transactions/charts/error_rate'>;
Expand Down Expand Up @@ -59,9 +61,17 @@ function FailedTransactionChart({
const { currentPeriodColor: currentPeriodColorErrorRate } =
get_timeseries_color.getTimeSeriesColor(ChartType.FAILED_TRANSACTION_RATE);

const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
kuery: '',
numBuckets: 100,
type: ApmDocumentType.ServiceTransactionMetric,
});

const { data: dataErrorRate = INITIAL_STATE_ERROR_RATE, status } = useFetcher(
(callApmApi) => {
if (transactionType && serviceName && start && end) {
if (transactionType && serviceName && start && end && preferred) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/transactions/charts/error_rate',
{
Expand All @@ -76,13 +86,16 @@ function FailedTransactionChart({
end,
transactionType,
transactionName: undefined,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
},
},
}
);
}
},
[environment, serviceName, start, end, transactionType]
[environment, serviceName, start, end, transactionType, preferred]
);
const timeseriesErrorRate = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
import { useFetcher } from '../../../../hooks/use_fetcher';
import { TimeseriesChart } from '../../../shared/charts/timeseries_chart';
import { getResponseTimeTickFormatter } from '../../../shared/charts/transaction_charts/helper';
import { usePreferredDataSourceAndBucketSize } from '../../../../hooks/use_preferred_data_source_and_bucket_size';
import { ApmDocumentType } from '../../../../../common/document_type';

const INITIAL_STATE = {
currentPeriod: [],
Expand Down Expand Up @@ -54,10 +56,19 @@ function ThroughputChart({
timeZone: string;
}) {
/* Throughput Chart */

const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
numBuckets: 100,
kuery: '',
type: ApmDocumentType.ServiceTransactionMetric,
});

const { data: dataThroughput = INITIAL_STATE, status: statusThroughput } =
useFetcher(
(callApmApi) => {
if (serviceName && transactionType && start && end) {
if (serviceName && transactionType && start && end && preferred) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/throughput',
{
Expand All @@ -72,13 +83,16 @@ function ThroughputChart({
end,
transactionType,
transactionName: undefined,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
},
},
}
);
}
},
[environment, serviceName, start, end, transactionType]
[environment, serviceName, start, end, transactionType, preferred]
);
const { currentPeriodColor, previousPeriodColor } = getTimeSeriesColor(
ChartType.THROUGHPUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
ChartType,
getTimeSeriesColor,
} from '../../shared/charts/helper/get_timeseries_color';
import { usePreferredDataSourceAndBucketSize } from '../../../hooks/use_preferred_data_source_and_bucket_size';
import { ApmDocumentType } from '../../../../common/document_type';

const INITIAL_STATE = {
currentPeriod: [],
Expand Down Expand Up @@ -60,6 +62,14 @@ export function ServiceOverviewThroughputChart({

const { start, end } = useTimeRange({ rangeFrom, rangeTo });

const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
numBuckets: 100,
kuery,
type: ApmDocumentType.ServiceTransactionMetric,
});

const { transactionType, serviceName, transactionTypeStatus } =
useApmServiceContext();

Expand All @@ -71,7 +81,7 @@ export function ServiceOverviewThroughputChart({
return Promise.resolve(INITIAL_STATE);
}

if (serviceName && transactionType && start && end) {
if (serviceName && transactionType && start && end && preferred) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/throughput',
{
Expand All @@ -90,6 +100,9 @@ export function ServiceOverviewThroughputChart({
? offset
: undefined,
transactionName,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
},
},
}
Expand All @@ -107,6 +120,7 @@ export function ServiceOverviewThroughputChart({
offset,
transactionName,
comparisonEnabled,
preferred,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { useEnvironmentsContext } from '../../../../context/environments_context
import { ApmMlDetectorType } from '../../../../../common/anomaly_detection/apm_ml_detectors';
import { usePreferredServiceAnomalyTimeseries } from '../../../../hooks/use_preferred_service_anomaly_timeseries';
import { ChartType, getTimeSeriesColor } from '../helper/get_timeseries_color';
import { usePreferredDataSourceAndBucketSize } from '../../../../hooks/use_preferred_data_source_and_bucket_size';
import { ApmDocumentType } from '../../../../../common/document_type';

function yLabelFormat(y?: number | null) {
return asPercent(y || 0, 1);
Expand Down Expand Up @@ -71,6 +73,14 @@ export function FailedTransactionRateChart({

const { start, end } = useTimeRange({ rangeFrom, rangeTo });

const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
numBuckets: 100,
kuery,
type: ApmDocumentType.ServiceTransactionMetric,
});

const { environment } = useEnvironmentsContext();

const preferredAnomalyTimeseries = usePreferredServiceAnomalyTimeseries(
Expand All @@ -88,7 +98,7 @@ export function FailedTransactionRateChart({
return Promise.resolve(INITIAL_STATE);
}

if (transactionType && serviceName && start && end) {
if (transactionType && serviceName && start && end && preferred) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/transactions/charts/error_rate',
{
Expand All @@ -107,6 +117,9 @@ export function FailedTransactionRateChart({
comparisonEnabled && isTimeComparison(offset)
? offset
: undefined,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
},
},
}
Expand All @@ -124,6 +137,7 @@ export function FailedTransactionRateChart({
transactionName,
offset,
comparisonEnabled,
preferred,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@ import {
rangeQuery,
termQuery,
} from '@kbn/observability-plugin/server';
import { ApmServiceTransactionDocumentType } from '../../../common/document_type';
import {
EVENT_OUTCOME,
SERVICE_NAME,
TRANSACTION_NAME,
TRANSACTION_TYPE,
} from '../../../common/es_fields/apm';
import { EventOutcome } from '../../../common/event_outcome';
import { RollupInterval } from '../../../common/rollup';
import { environmentQuery } from '../../../common/utils/environment_query';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { Coordinate } from '../../../typings/timeseries';
import {
getDocumentTypeFilterForTransactions,
getProcessorEventForTransactions,
} from '../helpers/transactions';
import { getBucketSizeForAggregatedTransactions } from '../helpers/get_bucket_size_for_aggregated_transactions';
import { APMEventClient } from '../helpers/create_es_client/create_apm_event_client';
import {
calculateFailedTransactionRate,
getOutcomeAggregation,
getFailedTransactionRateTimeSeries,
getOutcomeAggregation,
} from '../helpers/transaction_error_rate';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { APMEventClient } from '../helpers/create_es_client/create_apm_event_client';
import { ApmDocumentType } from '../../../common/document_type';

export async function getFailedTransactionRate({
environment,
Expand All @@ -40,23 +34,25 @@ export async function getFailedTransactionRate({
transactionTypes,
transactionName,
apmEventClient,
searchAggregatedTransactions,
start,
end,
numBuckets,
offset,
documentType,
rollupInterval,
bucketSizeInSeconds,
}: {
environment: string;
kuery: string;
serviceName: string;
transactionTypes: string[];
transactionName?: string;
apmEventClient: APMEventClient;
searchAggregatedTransactions: boolean;
start: number;
end: number;
numBuckets?: number;
offset?: string;
documentType: ApmServiceTransactionDocumentType;
rollupInterval: RollupInterval;
bucketSizeInSeconds: number;
}): Promise<{
timeseries: Coordinate[];
average: number | null;
Expand All @@ -69,28 +65,18 @@ export async function getFailedTransactionRate({

const filter = [
{ term: { [SERVICE_NAME]: serviceName } },
{
terms: {
[EVENT_OUTCOME]: [EventOutcome.failure, EventOutcome.success],
},
},
{ terms: { [TRANSACTION_TYPE]: transactionTypes } },
...termQuery(TRANSACTION_NAME, transactionName),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...rangeQuery(startWithOffset, endWithOffset),
...environmentQuery(environment),
...kqlQuery(kuery),
];

const outcomes = getOutcomeAggregation(
searchAggregatedTransactions
? ApmDocumentType.TransactionMetric
: ApmDocumentType.TransactionEvent
);
const outcomes = getOutcomeAggregation(documentType);

const params = {
apm: {
events: [getProcessorEventForTransactions(searchAggregatedTransactions)],
sources: [{ documentType, rollupInterval }],
},
body: {
track_total_hits: false,
Expand All @@ -101,12 +87,7 @@ export async function getFailedTransactionRate({
timeseries: {
date_histogram: {
field: '@timestamp',
fixed_interval: getBucketSizeForAggregatedTransactions({
start: startWithOffset,
end: endWithOffset,
searchAggregatedTransactions,
numBuckets,
}).intervalString,
fixed_interval: `${bucketSizeInSeconds}s`,
min_doc_count: 0,
extended_bounds: { min: startWithOffset, max: endWithOffset },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
percentSystemMemoryUsedScript,
} from '../metrics/by_agent/shared/memory';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';

interface Options {
apmEventClient: APMEventClient;
Expand Down Expand Up @@ -136,12 +138,25 @@ async function getFailedTransactionsRateStats({
environment,
apmEventClient,
serviceName,
searchAggregatedTransactions,
start,
end,
kuery: '',
numBuckets,
transactionTypes: defaultTransactionTypes,
bucketSizeInSeconds: getBucketSizeForAggregatedTransactions({
start,
end,
numBuckets,
searchAggregatedTransactions,
}).bucketSize,
...(searchAggregatedTransactions
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
}),
});
return {
value: average,
Expand Down
Loading

0 comments on commit 01098bc

Please sign in to comment.