[APM] Refactor transaction types API to use RollupIntervals and Metrics (#167500)

## Summary

Resolves - https://github.com/elastic/kibana/issues/167020

This PR -
- [x] Add logic to use the RollupIntervals and Document Source from
TimeRange Metadata API to fetch Transaction Types instead of its own
logic.
- [x] Updates the Existing API test to use Synthtrace rather than
Archives
- [x] Renames the `getDocumentTypeFilterForTransactions` function to
something more readable and fancy (Ground work for future PRs)

## How to review

Better do it commit wise or only the commits from 28th September. The
last commit does a function rename which has caused so many files to
change.
This commit is contained in:
Achyut Jhunjhunwala 2023-10-03 09:55:22 +02:00 committed by GitHub
parent d1e13ef895
commit 355ec85134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 171 additions and 109 deletions

View file

@ -20,6 +20,7 @@ import { renderWithTheme } from '../../../utils/test_helpers';
import { fromQuery } from '../links/url_helpers';
import { CoreStart } from '@kbn/core/public';
import { SearchBar } from './search_bar';
import { ApmTimeRangeMetadataContextProvider } from '../../../context/time_range_metadata/time_range_metadata_context';
function setup({
urlParams,
@ -36,8 +37,12 @@ function setup({
});
const KibanaReactContext = createKibanaReactContext({
usageCollection: { reportUiCounter: () => {} },
dataViews: { get: async () => {} },
usageCollection: {
reportUiCounter: () => {},
},
dataViews: {
get: async () => {},
},
data: {
query: {
queryString: {
@ -75,9 +80,11 @@ function setup({
<KibanaReactContext.Provider>
<MockApmPluginContextWrapper history={history}>
<UrlParamsProvider>
<ApmServiceContextProvider>
<SearchBar showTransactionTypeSelector />
</ApmServiceContextProvider>
<ApmTimeRangeMetadataContextProvider>
<ApmServiceContextProvider>
<SearchBar showTransactionTypeSelector />
</ApmServiceContextProvider>
</ApmTimeRangeMetadataContextProvider>
</UrlParamsProvider>
</MockApmPluginContextWrapper>
</KibanaReactContext.Provider>

View file

@ -8,6 +8,7 @@
import React, { createContext, ReactNode } from 'react';
import { useHistory } from 'react-router-dom';
import { History } from 'history';
import { ApmDocumentType } from '../../../common/document_type';
import { getDefaultTransactionType } from '../../../common/transaction_types';
import { useServiceTransactionTypesFetcher } from './use_service_transaction_types_fetcher';
import { useServiceAgentFetcher } from './use_service_agent_fetcher';
@ -17,6 +18,7 @@ import { useFallbackToTransactionsFetcher } from '../../hooks/use_fallback_to_tr
import { replace } from '../../components/shared/links/url_helpers';
import { FETCH_STATUS } from '../../hooks/use_fetcher';
import { ServerlessType } from '../../../common/serverless';
import { usePreferredDataSourceAndBucketSize } from '../../hooks/use_preferred_data_source_and_bucket_size';
export interface APMServiceContextValue {
serviceName: string;
@ -67,11 +69,21 @@ export function ApmServiceContextProvider({
end,
});
const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
kuery,
type: ApmDocumentType.TransactionMetric,
numBuckets: 100,
});
const { transactionTypes, status: transactionTypeStatus } =
useServiceTransactionTypesFetcher({
serviceName,
start,
end,
documentType: preferred?.source.documentType,
rollupInterval: preferred?.source.rollupInterval,
});
const currentTransactionType = getOrRedirectToTransactionType({

View file

@ -6,6 +6,8 @@
*/
import { useFetcher } from '../../hooks/use_fetcher';
import { RollupInterval } from '../../../common/rollup';
import { ApmTransactionDocumentType } from '../../../common/document_type';
const INITIAL_DATA = { transactionTypes: [] };
@ -13,26 +15,30 @@ export function useServiceTransactionTypesFetcher({
serviceName,
start,
end,
documentType,
rollupInterval,
}: {
serviceName?: string;
start?: string;
end?: string;
documentType?: ApmTransactionDocumentType;
rollupInterval?: RollupInterval;
}) {
const { data = INITIAL_DATA, status } = useFetcher(
(callApmApi) => {
if (serviceName && start && end) {
if (serviceName && start && end && documentType && rollupInterval) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/transaction_types',
{
params: {
path: { serviceName },
query: { start, end },
query: { start, end, documentType, rollupInterval },
},
}
);
}
},
[serviceName, start, end]
[serviceName, start, end, documentType, rollupInterval]
);
return { transactionTypes: data.transactionTypes, status };

View file

@ -12,6 +12,12 @@ import { getBucketSize } from '../../common/utils/get_bucket_size';
import { getPreferredBucketSizeAndDataSource } from '../../common/utils/get_preferred_bucket_size_and_data_source';
import { useTimeRangeMetadata } from '../context/time_range_metadata/use_time_range_metadata_context';
/**
* Hook to get the source and interval based on Time Range Metadata API
*
* @param {number} numBuckets - The number of buckets. Should be 20 for SparkPlots or 100 for Other charts.
*/
export function usePreferredDataSourceAndBucketSize<
TDocumentType extends
| ApmDocumentType.ServiceTransactionMetric

View file

@ -15,7 +15,7 @@ import {
import { RollupInterval } from '../../../../common/rollup';
import { termQuery } from '../../../../common/utils/term_query';
import { getDocumentTypeFilterForServiceDestinationStatistics } from '../spans/get_is_using_service_destination_metrics';
import { getDocumentTypeFilterForTransactions } from '../transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../transactions';
const defaultRollupIntervals = [
RollupInterval.OneMinute,
@ -66,7 +66,7 @@ const documentTypeConfigMap: Record<
bool: {
filter:
rollupInterval === RollupInterval.OneMinute
? getDocumentTypeFilterForTransactions(true)
? getBackwardCompatibleDocumentTypeFilter(true)
: getDefaultFilter('transaction', rollupInterval),
},
}),

View file

@ -121,7 +121,8 @@ export function getDurationFieldForTransactions(
return TRANSACTION_DURATION;
}
export function getDocumentTypeFilterForTransactions(
// The function returns Document type filter for 1m Transaction Metrics
export function getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions: boolean
) {
return searchAggregatedTransactions

View file

@ -17,7 +17,7 @@ import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_pr
import { environmentQuery } from '../../../common/utils/environment_query';
import { Coordinate } from '../../../typings/timeseries';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../helpers/transactions';
import { getBucketSizeForAggregatedTransactions } from '../helpers/get_bucket_size_for_aggregated_transactions';
@ -66,7 +66,7 @@ export async function getColdstartRate({
{ exists: { field: FAAS_COLDSTART } },
...(transactionName ? termQuery(TRANSACTION_NAME, transactionName) : []),
...termQuery(TRANSACTION_TYPE, transactionType),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(searchAggregatedTransactions),
...rangeQuery(startWithOffset, endWithOffset),
...environmentQuery(environment),
...kqlQuery(kuery),

View file

@ -24,7 +24,7 @@ import { environmentQuery } from '../../../../../common/utils/environment_query'
import { AlertParams, PreviewChartResponse } from '../../route';
import {
getSearchTransactionsEvents,
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getDurationFieldForTransactions,
getProcessorEventForTransactions,
} from '../../../../lib/helpers/transactions';
@ -89,7 +89,9 @@ export async function getTransactionDurationChartPreview({
...termFilterQuery,
...getParsedFilterQuery(searchConfiguration?.query?.query as string),
...rangeQuery(start, end),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
] as QueryDslQueryContainer[],
},
};

View file

@ -50,7 +50,7 @@ import {
getDurationFormatter,
} from '../../../../../common/utils/formatters';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getDurationFieldForTransactions,
} from '../../../../lib/helpers/transactions';
import { apmActionVariables } from '../../action_variables';
@ -167,7 +167,7 @@ export function registerTransactionDurationRuleType({
},
},
},
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...termFilterQuery,

View file

@ -21,7 +21,7 @@ import { environmentQuery } from '../../../../../common/utils/environment_query'
import { AlertParams, PreviewChartResponse } from '../../route';
import {
getSearchTransactionsEvents,
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../../../../lib/helpers/transactions';
import { APMConfig } from '../../../..';
@ -96,7 +96,7 @@ export async function getTransactionErrorRateChartPreview({
searchConfiguration?.query?.query as string
),
...rangeQuery(start, end),
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
{

View file

@ -50,7 +50,7 @@ import {
asDecimalOrInteger,
getAlertUrlTransaction,
} from '../../../../../common/utils/formatters';
import { getDocumentTypeFilterForTransactions } from '../../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../../lib/helpers/transactions';
import { apmActionVariables } from '../../action_variables';
import { alertingEsClient } from '../../alerting_es_client';
import {
@ -169,7 +169,7 @@ export function registerTransactionErrorRateRuleType({
},
},
},
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
{

View file

@ -13,7 +13,7 @@ import { LatencyDistributionChartType } from '../../../../common/latency_distrib
import { getCommonCorrelationsQuery } from './get_common_correlations_query';
import { getDurationField, getEventType } from '../utils';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForTransactions } from '../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../lib/helpers/transactions';
const getHistogramRangeSteps = (min: number, max: number, steps: number) => {
// A d3 based scale function as a helper to get equally distributed bins on a log scale.
@ -66,7 +66,7 @@ export const fetchDurationHistogramRangeSteps = async ({
const filteredQuery = searchMetrics
? {
bool: {
filter: [query, ...getDocumentTypeFilterForTransactions(true)],
filter: [query, ...getBackwardCompatibleDocumentTypeFilter(true)],
},
}
: query;

View file

@ -11,7 +11,7 @@ import { getCommonCorrelationsQuery } from './get_common_correlations_query';
import { CommonCorrelationsQueryParams } from '../../../../common/correlations/types';
import { getDurationField, getEventType } from '../utils';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForTransactions } from '../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../lib/helpers/transactions';
export const fetchDurationPercentiles = async ({
chartType,
@ -36,7 +36,7 @@ export const fetchDurationPercentiles = async ({
const filteredQuery = searchMetrics
? {
bool: {
filter: [query, ...getDocumentTypeFilterForTransactions(true)],
filter: [query, ...getBackwardCompatibleDocumentTypeFilter(true)],
},
}
: query;

View file

@ -12,7 +12,7 @@ import { getCommonCorrelationsQuery } from './get_common_correlations_query';
import { Environment } from '../../../../common/environment_rt';
import { getDurationField, getEventType } from '../utils';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForTransactions } from '../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../lib/helpers/transactions';
export const fetchDurationRanges = async ({
rangeSteps,
@ -42,7 +42,7 @@ export const fetchDurationRanges = async ({
const filteredQuery = searchMetrics
? {
bool: {
filter: [query, ...getDocumentTypeFilterForTransactions(true)],
filter: [query, ...getBackwardCompatibleDocumentTypeFilter(true)],
},
}
: query;

View file

@ -9,7 +9,7 @@ import { rangeQuery } from '@kbn/observability-plugin/server';
import { isDefaultTransactionType } from '../../../common/transaction_types';
import { TRANSACTION_TYPE } from '../../../common/es_fields/apm';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../../lib/helpers/transactions';
import { calculateThroughputWithRange } from '../../lib/helpers/calculate_throughput';
@ -45,7 +45,7 @@ export async function getTransactionsPerMinute({
bool: {
filter: [
...rangeQuery(start, end),
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
],

View file

@ -19,7 +19,7 @@ import { environmentQuery } from '../../../common/utils/environment_query';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { getBucketSizeForAggregatedTransactions } from '../../lib/helpers/get_bucket_size_for_aggregated_transactions';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getDurationFieldForTransactions,
getProcessorEventForTransactions,
} from '../../lib/helpers/transactions';
@ -184,7 +184,7 @@ async function getTransactionStats({
bool: {
filter: [
...filter,
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
{

View file

@ -270,8 +270,11 @@ Array [
exports[`services queries fetches the service transaction types 1`] = `
Object {
"apm": Object {
"events": Array [
"transaction",
"sources": Array [
Object {
"documentType": "transactionMetric",
"rollupInterval": "1m",
},
],
},
"body": Object {

View file

@ -15,7 +15,7 @@ import {
} from '../../../../common/es_fields/apm';
import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../../../lib/helpers/transactions';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
@ -37,7 +37,7 @@ export async function getDerivedServiceAnnotations({
}) {
const filter: ESFilter[] = [
{ term: { [SERVICE_NAME]: serviceName } },
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(searchAggregatedTransactions),
...environmentQuery(environment),
];

View file

@ -14,7 +14,7 @@ import {
} from '../../../common/es_fields/apm';
import { maybe } from '../../../common/utils/maybe';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../../lib/helpers/transactions';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
@ -109,7 +109,9 @@ export async function getServiceInstanceMetadataDetails({
size: 1,
query: {
bool: {
filter: filter.concat(getDocumentTypeFilterForTransactions(true)),
filter: filter.concat(
getBackwardCompatibleDocumentTypeFilter(true)
),
},
},
},

View file

@ -17,7 +17,7 @@ import { SERVICE_NODE_NAME_MISSING } from '../../../../common/service_nodes';
import { Coordinate } from '../../../../typings/timeseries';
import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getDurationFieldForTransactions,
getProcessorEventForTransactions,
} from '../../../lib/helpers/transactions';
@ -114,11 +114,15 @@ export async function getServiceInstancesTransactionStatistics<
filter: [
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [TRANSACTION_TYPE]: transactionType } },
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...rangeQuery(startWithOffset, endWithOffset),
...environmentQuery(environment),
...kqlQuery(kuery),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...(isComparisonSearch && serviceNodeIds
? [{ terms: { [SERVICE_NODE_NAME]: serviceNodeIds } }]
: []),

View file

@ -6,12 +6,10 @@
*/
import { rangeQuery } from '@kbn/observability-plugin/server';
import { ApmServiceTransactionDocumentType } from '../../../common/document_type';
import { SERVICE_NAME, TRANSACTION_TYPE } from '../../../common/es_fields/apm';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import {
getDocumentTypeFilterForTransactions,
getProcessorEventForTransactions,
} from '../../lib/helpers/transactions';
import { RollupInterval } from '../../../common/rollup';
export interface ServiceTransactionTypesResponse {
transactionTypes: string[];
@ -20,19 +18,26 @@ export interface ServiceTransactionTypesResponse {
export async function getServiceTransactionTypes({
apmEventClient,
serviceName,
searchAggregatedTransactions,
start,
end,
documentType,
rollupInterval,
}: {
serviceName: string;
apmEventClient: APMEventClient;
searchAggregatedTransactions: boolean;
start: number;
end: number;
documentType: ApmServiceTransactionDocumentType;
rollupInterval: RollupInterval;
}): Promise<ServiceTransactionTypesResponse> {
const params = {
apm: {
events: [getProcessorEventForTransactions(searchAggregatedTransactions)],
sources: [
{
documentType,
rollupInterval,
},
],
},
body: {
track_total_hits: false,
@ -40,9 +45,6 @@ export async function getServiceTransactionTypes({
query: {
bool: {
filter: [
...getDocumentTypeFilterForTransactions(
searchAggregatedTransactions
),
{ term: { [SERVICE_NAME]: serviceName } },
...rangeQuery(start, end),
],

View file

@ -42,9 +42,10 @@ describe('services queries', () => {
getServiceTransactionTypes({
serviceName: 'foo',
apmEventClient: mockApmEventClient,
searchAggregatedTransactions: false,
start: 0,
end: 50000,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
})
);

View file

@ -328,27 +328,22 @@ const serviceTransactionTypesRoute = createApmServerRoute({
path: t.type({
serviceName: t.string,
}),
query: rangeRt,
query: t.intersection([rangeRt, serviceTransactionDataSourceRt]),
}),
options: { tags: ['access:apm'] },
handler: async (resources): Promise<ServiceTransactionTypesResponse> => {
const apmEventClient = await getApmEventClient(resources);
const { params, config } = resources;
const { params } = resources;
const { serviceName } = params.path;
const { start, end } = params.query;
const { start, end, documentType, rollupInterval } = params.query;
return getServiceTransactionTypes({
serviceName,
apmEventClient,
searchAggregatedTransactions: await getSearchTransactionsEvents({
apmEventClient,
config,
start,
end,
kuery: '',
}),
start,
end,
documentType,
rollupInterval,
});
},
});

View file

@ -25,7 +25,7 @@ import { RandomSampler } from '../../lib/helpers/get_random_sampler';
import { SERVICE_NAME, TIER, INDEX } from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
getDurationFieldForTransactions,
isRootTransaction,
@ -65,7 +65,7 @@ async function getTracesPerMinute({
query: {
bool: {
filter: [
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...environmentQuery(environment),

View file

@ -11,7 +11,7 @@ import {
} from '@kbn/observability-plugin/server';
import {
getProcessorEventForTransactions,
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
} from '../../lib/helpers/transactions';
import { SERVICE_NAME, TIER } from '../../../common/es_fields/apm';
import {
@ -55,7 +55,7 @@ export async function getTotalTransactionsPerService({
query: {
bool: {
filter: [
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...environmentQuery(environment),

View file

@ -19,7 +19,7 @@ import { calculateImpactBuilder } from './calculate_impact_builder';
import { calculateThroughputWithRange } from '../../lib/helpers/calculate_throughput';
import {
getDurationFieldForTransactions,
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
isRootTransaction,
} from '../../lib/helpers/transactions';
@ -87,7 +87,7 @@ export async function getTopTracesPrimaryStats({
bool: {
filter: [
...termQuery(TRANSACTION_NAME, transactionName),
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...rangeQuery(start, end),

View file

@ -117,7 +117,9 @@ export default function featureControlsTests({ getService }: FtrProviderContext)
expectResponse: expect200,
},
{
req: { url: `/internal/apm/services/foo/transaction_types?start=${start}&end=${end}` },
req: {
url: `/internal/apm/services/foo/transaction_types?start=${start}&end=${end}&documentType=transactionMetric&rollupInterval=1m`,
},
expectForbidden: expect403,
expectResponse: expect200,
},

View file

@ -6,31 +6,44 @@
*/
import expect from '@kbn/expect';
import archives from '../../common/fixtures/es_archiver/archives_metadata';
import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type';
import { RollupInterval } from '@kbn/apm-plugin/common/rollup';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { FtrProviderContext } from '../../common/ftr_provider_context';
export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const synthtrace = getService('synthtraceEsClient');
const archiveName = 'apm_8.0.0';
const { start, end } = archives[archiveName];
const start = '2023-10-28T00:00:00.000Z';
const end = '2023-10-28T00:14:59.999Z';
const serviceName = 'opbeans-node';
async function getTransactionTypes() {
const response = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/services/{serviceName}/transaction_types',
params: {
path: { serviceName },
query: {
start,
end,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
},
},
});
return response;
}
registry.when(
'Transaction types when data is not loaded',
{ config: 'basic', archives: [] },
() => {
it('handles empty state', async () => {
const response = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/services/{serviceName}/transaction_types',
params: {
path: { serviceName: 'opbeans-node' },
query: {
start,
end,
},
},
});
const response = await getTransactionTypes();
expect(response.status).to.be(200);
@ -39,34 +52,40 @@ export default function ApiTest({ getService }: FtrProviderContext) {
}
);
registry.when(
'Transaction types when data is loaded',
{ config: 'basic', archives: [archiveName] },
() => {
it('handles empty state', async () => {
const response = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/services/{serviceName}/transaction_types',
params: {
path: { serviceName: 'opbeans-node' },
query: {
start,
end,
},
},
});
registry.when('Transaction types when data is loaded', { config: 'basic', archives: [] }, () => {
before(async () => {
const interval = timerange(new Date(start).getTime(), new Date(end).getTime() - 1).interval(
'1m'
);
expect(response.status).to.be(200);
expect(response.body.transactionTypes.length).to.be.greaterThan(0);
const instance = apm.service(serviceName, 'production', 'node').instance('instance');
expectSnapshot(response.body).toMatchInline(`
Object {
"transactionTypes": Array [
"request",
"Worker",
],
}
`);
});
}
);
await synthtrace.index([
interval.rate(3).generator((timestamp) => {
return instance
.transaction({ transactionName: 'GET /api', transactionType: 'request' })
.duration(1000)
.outcome('success')
.timestamp(timestamp);
}),
interval.rate(1).generator((timestamp) => {
return instance
.transaction({ transactionName: 'rm -rf *', transactionType: 'worker' })
.duration(100)
.outcome('failure')
.timestamp(timestamp);
}),
]);
});
after(() => synthtrace.clean());
it('displays available tx types', async () => {
const response = await getTransactionTypes();
expect(response.status).to.be(200);
expect(response.body.transactionTypes.length).to.be.greaterThan(0);
expect(response.body.transactionTypes).to.eql(['request', 'worker']);
});
});
}