[ObsUX] Update APM api to pass preferred documentType and rollupInterval (#170749)

Part of https://github.com/elastic/kibana/issues/167020

---------

Co-authored-by: achyutjhunjhunwala <achyut.jhunjhunwala@elastic.co>
This commit is contained in:
Miriam 2023-11-24 05:59:13 +00:00 committed by GitHub
parent e40f79095e
commit 97b1851f00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 304 additions and 135 deletions

View file

@ -14,7 +14,8 @@ type AnyApmDocumentType =
| ApmDocumentType.TransactionEvent
| ApmDocumentType.ServiceDestinationMetric
| ApmDocumentType.ServiceSummaryMetric
| ApmDocumentType.ErrorEvent;
| ApmDocumentType.ErrorEvent
| ApmDocumentType.SpanEvent;
export interface ApmDataSource<
TDocumentType extends AnyApmDocumentType = AnyApmDocumentType

View file

@ -12,6 +12,7 @@ export enum ApmDocumentType {
ServiceDestinationMetric = 'serviceDestinationMetric',
ServiceSummaryMetric = 'serviceSummaryMetric',
ErrorEvent = 'error',
SpanEvent = 'span',
}
export type ApmServiceTransactionDocumentType =

View file

@ -22,6 +22,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import React from 'react';
import { ApmDocumentType } from '../../../../../common/document_type';
import {
getServiceNodeName,
SERVICE_NODE_NAME_MISSING,
@ -33,6 +34,7 @@ import { ChartPointerEventContextProvider } from '../../../../context/chart_poin
import { useApmParams } from '../../../../hooks/use_apm_params';
import { useApmRouter } from '../../../../hooks/use_apm_router';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';
import { usePreferredDataSourceAndBucketSize } from '../../../../hooks/use_preferred_data_source_and_bucket_size';
import { useServiceMetricChartsFetcher } from '../../../../hooks/use_service_metric_charts_fetcher';
import { useTimeRange } from '../../../../hooks/use_time_range';
import { truncate, unit } from '../../../../utils/style';
@ -83,9 +85,17 @@ export function ServiceNodeMetrics({ serviceNodeName }: Props) {
environment,
});
const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
kuery,
type: ApmDocumentType.ServiceTransactionMetric,
numBuckets: 100,
});
const { data: { host, containerId } = INITIAL_DATA, status } = useFetcher(
(callApmApi) => {
if (start && end) {
if (start && end && preferred) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/node/{serviceNodeName}/metadata',
{
@ -96,13 +106,15 @@ export function ServiceNodeMetrics({ serviceNodeName }: Props) {
start,
end,
environment,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
},
},
}
);
}
},
[kuery, serviceName, serviceNodeName, start, end, environment]
[kuery, serviceName, serviceNodeName, start, end, environment, preferred]
);
const { docLinks } = useApmPluginContext().core;

View file

@ -327,6 +327,7 @@ export function ServiceList({
} = useApmParams('/services');
const { kuery } = query;
const { fallbackToTransactions } = useFallbackToTransactionsFetcher({
kuery,
});

View file

@ -19,12 +19,12 @@ export function TopTracesOverview() {
const {
query: { environment, kuery, rangeFrom, rangeTo },
} = useApmParams('/traces');
const { start, end } = useTimeRange({ rangeFrom, rangeTo });
const { fallbackToTransactions } = useFallbackToTransactionsFetcher({
kuery,
});
const { start, end } = useTimeRange({ rangeFrom, rangeTo });
const response = useProgressiveFetcher(
(callApmApi) => {
if (start && end) {

View file

@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getKueryWithMobileFilters } from '../../common/utils/get_kuery_with_mobile_filters';
import { useApmParams } from './use_apm_params';
import { useFetcher } from './use_fetcher';
@ -33,11 +34,17 @@ export function useFallbackToTransactionsFetcher({ kuery }: { kuery: string }) {
const { data = { fallbackToTransactions: false } } = useFetcher(
(callApmApi) => {
return callApmApi('GET /internal/apm/fallback_to_transactions', {
params: {
query: { kuery: kueryWithFilters, start, end },
},
});
if (start && end) {
return callApmApi('GET /internal/apm/fallback_to_transactions', {
params: {
query: {
kuery: kueryWithFilters,
start,
end,
},
},
});
}
},
[kueryWithFilters, start, end]
);

View file

@ -9,7 +9,6 @@ import { sum } from 'lodash';
import objectHash from 'object-hash';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { rangeQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
import { getOffsetInMs } from '../../../../common/utils/get_offset_in_ms';
import { ENVIRONMENT_NOT_DEFINED } from '../../../../common/environment_filter_values';
@ -28,6 +27,8 @@ import {
import { getBucketSize } from '../../../../common/utils/get_bucket_size';
import { EventOutcome } from '../../../../common/event_outcome';
import { NodeType } from '../../../../common/connections';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
import { excludeRumExitSpansQuery } from '../exclude_rum_exit_spans_query';
import { APMEventClient } from '../../helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForServiceDestinationStatistics } from '../../helpers/spans/get_is_using_service_destination_metrics';
@ -55,7 +56,12 @@ export const getStats = async ({
const response = await apmEventClient.search('get_connection_stats', {
apm: {
events: [ProcessorEvent.metric],
sources: [
{
documentType: ApmDocumentType.ServiceDestinationMetric,
rollupInterval: RollupInterval.OneMinute,
},
],
},
body: {
track_total_hits: true,

View file

@ -57,9 +57,9 @@ export function getRequestBase(options: {
if ('sources' in options.apm) {
options.apm.sources.forEach((source) => {
const { getQuery } = getConfigForDocumentType(source.documentType);
if (getQuery) {
filters.push(getQuery(source.rollupInterval));
const documentTypeConfig = getConfigForDocumentType(source.documentType);
if ('getQuery' in documentTypeConfig) {
filters.push(documentTypeConfig.getQuery(source.rollupInterval));
}
});
}

View file

@ -62,13 +62,11 @@ type APMEventTermsEnumRequest = APMEventWrapper<TermsEnumRequest>;
type APMEventEqlSearchRequest = APMEventWrapper<EqlSearchRequest>;
type APMEventFieldCapsRequest = APMEventWrapper<FieldCapsRequest>;
// These keys shoul all be `ProcessorEvent.x`, but until TypeScript 4.2 we're inlining them here.
// See https://github.com/microsoft/TypeScript/issues/37888
type TypeOfProcessorEvent<T extends ProcessorEvent> = {
error: APMError;
transaction: Transaction;
span: Span;
metric: Metric;
[ProcessorEvent.error]: APMError;
[ProcessorEvent.transaction]: Transaction;
[ProcessorEvent.span]: Span;
[ProcessorEvent.metric]: Metric;
}[T];
type TypedLogEventSearchResponse<TParams extends APMLogEventESSearchRequest> =
@ -77,15 +75,13 @@ type TypedLogEventSearchResponse<TParams extends APMLogEventESSearchRequest> =
type TypedSearchResponse<TParams extends APMEventESSearchRequest> =
InferSearchResponseOf<
TypeOfProcessorEvent<
ValuesType<
TParams['apm'] extends { events: ProcessorEvent[] }
? TParams['apm']['events']
: TParams['apm'] extends { sources: ApmDataSource[] }
? ProcessorEventOfDocumentType<
ValuesType<TParams['apm']['sources']>['documentType']
>
: never
>
TParams['apm'] extends { events: ProcessorEvent[] }
? ValuesType<TParams['apm']['events']>
: TParams['apm'] extends { sources: ApmDataSource[] }
? ProcessorEventOfDocumentType<
ValuesType<TParams['apm']['sources']>['documentType']
>
: never
>,
TParams
>;

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { ApmDocumentType } from '../../../../common/document_type';
import {
@ -33,18 +32,11 @@ function getDefaultFilter(
];
}
const documentTypeConfigMap: Record<
ApmDocumentType,
{
processorEvent: ProcessorEvent;
getQuery?: (rollupInterval: RollupInterval) => QueryDslQueryContainer;
rollupIntervals: RollupInterval[];
}
> = {
const documentTypeConfigMap = {
[ApmDocumentType.ServiceTransactionMetric]: {
processorEvent: ProcessorEvent.metric,
getQuery: (rollupInterval) => ({
getQuery: (rollupInterval: RollupInterval) => ({
bool: {
filter: getDefaultFilter('service_transaction', rollupInterval),
},
@ -53,7 +45,7 @@ const documentTypeConfigMap: Record<
},
[ApmDocumentType.ServiceSummaryMetric]: {
processorEvent: ProcessorEvent.metric,
getQuery: (rollupInterval) => ({
getQuery: (rollupInterval: RollupInterval) => ({
bool: {
filter: getDefaultFilter('service_summary', rollupInterval),
},
@ -62,7 +54,7 @@ const documentTypeConfigMap: Record<
},
[ApmDocumentType.TransactionMetric]: {
processorEvent: ProcessorEvent.metric,
getQuery: (rollupInterval) => ({
getQuery: (rollupInterval: RollupInterval) => ({
bool: {
filter:
rollupInterval === RollupInterval.OneMinute
@ -79,7 +71,7 @@ const documentTypeConfigMap: Record<
[ApmDocumentType.ServiceDestinationMetric]: {
processorEvent: ProcessorEvent.metric,
rollupIntervals: defaultRollupIntervals,
getQuery: (rollupInterval) => ({
getQuery: (rollupInterval: RollupInterval) => ({
bool: {
filter:
rollupInterval === RollupInterval.OneMinute
@ -92,7 +84,11 @@ const documentTypeConfigMap: Record<
processorEvent: ProcessorEvent.error,
rollupIntervals: [RollupInterval.None],
},
};
[ApmDocumentType.SpanEvent]: {
processorEvent: ProcessorEvent.span,
rollupIntervals: [RollupInterval.None],
},
} as const;
type DocumentTypeConfigOf<TApmDocumentType extends ApmDocumentType> =
typeof documentTypeConfigMap[TApmDocumentType];

View file

@ -96,8 +96,11 @@ Array [
"get_has_transactions",
Object {
"apm": Object {
"events": Array [
"transaction",
"sources": Array [
Object {
"documentType": "transactionEvent",
"rollupInterval": "none",
},
],
},
"body": Object {

View file

@ -6,10 +6,11 @@
*/
import { kqlQuery, rangeQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { getSearchTransactionsEvents } from '.';
import { APMEventClient } from '../create_es_client/create_apm_event_client';
import { SearchAggregatedTransactionSetting } from '../../../../common/aggregated_transactions';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
import { APMConfig } from '../../..';
export async function getIsUsingTransactionEvents({
@ -63,7 +64,12 @@ async function getHasTransactions({
}) {
const response = await apmEventClient.search('get_has_transactions', {
apm: {
events: [ProcessorEvent.transaction],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: 1,

View file

@ -6,8 +6,11 @@ Array [
"get_error_distribution_buckets",
Object {
"apm": Object {
"events": Array [
"error",
"sources": Array [
Object {
"documentType": "error",
"rollupInterval": "none",
},
],
},
"body": Object {

View file

@ -3,8 +3,11 @@
exports[`error distribution queries fetches an error distribution 1`] = `
Object {
"apm": Object {
"events": Array [
"error",
"sources": Array [
Object {
"documentType": "error",
"rollupInterval": "none",
},
],
},
"body": Object {
@ -50,8 +53,11 @@ Object {
exports[`error distribution queries fetches an error distribution with a group id 1`] = `
Object {
"apm": Object {
"events": Array [
"error",
"sources": Array [
Object {
"documentType": "error",
"rollupInterval": "none",
},
],
},
"body": Object {

View file

@ -6,7 +6,8 @@
*/
import { getBuckets } from './get_buckets';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
describe('get buckets', () => {
let clientSpy: jest.Mock;
@ -42,6 +43,11 @@ describe('get buckets', () => {
it('should limit query results to error documents', () => {
const query = clientSpy.mock.calls[0][1];
expect(query.apm.events).toEqual([ProcessorEvent.error]);
expect(query.apm.sources).toEqual([
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
]);
});
});

View file

@ -10,8 +10,9 @@ import {
kqlQuery,
termQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { ApmDocumentType } from '../../../../common/document_type';
import { ERROR_GROUP_ID, SERVICE_NAME } from '../../../../common/es_fields/apm';
import { RollupInterval } from '../../../../common/rollup';
import { environmentQuery } from '../../../../common/utils/environment_query';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
@ -36,7 +37,12 @@ export async function getBuckets({
}) {
const params = {
apm: {
events: [ProcessorEvent.error],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -17,7 +17,6 @@ import {
kqlQuery,
termQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { keyBy } from 'lodash';
import {
ERROR_GROUP_ID,
@ -28,6 +27,8 @@ import {
import { environmentQuery } from '../../../../common/utils/environment_query';
import { getBucketSize } from '../../../../common/utils/get_bucket_size';
import { getOffsetInMs } from '../../../../common/utils/get_offset_in_ms';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
async function getTopErroneousTransactions({
@ -65,7 +66,12 @@ async function getTopErroneousTransactions({
const res = await apmEventClient.search('get_top_erroneous_transactions', {
apm: {
events: [ProcessorEvent.error],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,
@ -112,17 +118,19 @@ async function getTopErroneousTransactions({
return (
res.aggregations?.top_five_transactions.buckets.map(
({ key, doc_count: docCount, sample, timeseries }) => ({
transactionName: key as string,
transactionType: sample.hits.hits[0]._source.transaction?.type,
occurrences: docCount,
timeseries: timeseries.buckets.map((timeseriesBucket) => {
return {
x: timeseriesBucket.key + offsetInMs,
y: timeseriesBucket.doc_count,
};
}),
})
({ key, doc_count: docCount, sample, timeseries }) => {
return {
transactionName: key as string,
transactionType: sample.hits.hits[0]._source.transaction?.type,
occurrences: docCount,
timeseries: timeseries.buckets.map((timeseriesBucket) => {
return {
x: timeseriesBucket.key + offsetInMs,
y: timeseriesBucket.doc_count,
};
}),
};
}
) ?? []
);
}

View file

@ -11,7 +11,6 @@ import {
rangeQuery,
termQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
ERROR_CULPRIT,
ERROR_EXC_HANDLED,
@ -26,6 +25,8 @@ import {
import { environmentQuery } from '../../../../common/utils/environment_query';
import { getErrorName } from '../../../lib/helpers/get_error_name';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
export type ErrorGroupMainStatisticsResponse = Array<{
groupId: string;
@ -75,7 +76,12 @@ export async function getErrorGroupMainStatistics({
'get_error_group_main_statistics',
{
apm: {
events: [ProcessorEvent.error],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,
@ -128,16 +134,19 @@ export async function getErrorGroupMainStatistics({
);
return (
response.aggregations?.error_groups.buckets.map((bucket) => ({
groupId: bucket.key as string,
name: getErrorName(bucket.sample.hits.hits[0]._source),
lastSeen: new Date(
bucket.sample.hits.hits[0]?._source['@timestamp']
).getTime(),
occurrences: bucket.doc_count,
culprit: bucket.sample.hits.hits[0]?._source.error.culprit,
handled: bucket.sample.hits.hits[0]?._source.error.exception?.[0].handled,
type: bucket.sample.hits.hits[0]?._source.error.exception?.[0].type,
})) ?? []
response.aggregations?.error_groups.buckets.map((bucket) => {
return {
groupId: bucket.key as string,
name: getErrorName(bucket.sample.hits.hits[0]._source),
lastSeen: new Date(
bucket.sample.hits.hits[0]._source['@timestamp']
).getTime(),
occurrences: bucket.doc_count,
culprit: bucket.sample.hits.hits[0]._source.error.culprit,
handled:
bucket.sample.hits.hits[0]._source.error.exception?.[0].handled,
type: bucket.sample.hits.hits[0]._source.error.exception?.[0].type,
};
}) ?? []
);
}

View file

@ -6,7 +6,6 @@
*/
import { rangeQuery, kqlQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import {
ERROR_GROUP_ID,
@ -16,6 +15,8 @@ import {
} from '../../../../common/es_fields/apm';
import { environmentQuery } from '../../../../common/utils/environment_query';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
const ERROR_SAMPLES_SIZE = 10000;
@ -41,9 +42,14 @@ export async function getErrorGroupSampleIds({
start: number;
end: number;
}): Promise<ErrorGroupSampleIdsResponse> {
const params = {
const resp = await apmEventClient.search('get_error_group_sample_ids', {
apm: {
events: [ProcessorEvent.error as const],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: ERROR_SAMPLES_SIZE,
@ -66,13 +72,11 @@ export async function getErrorGroupSampleIds({
{ '@timestamp': { order: 'desc' } }, // sort by timestamp to get the most recent error
] as const),
},
};
const resp = await apmEventClient.search(
'get_error_group_sample_ids',
params
);
const errorSampleIds = resp.hits.hits.map((item) => item._source.error.id);
});
const errorSampleIds = resp.hits.hits.map((item) => {
const source = item._source;
return source.error.id;
});
return {
errorSampleIds,

View file

@ -6,9 +6,10 @@
*/
import { rangeQuery, kqlQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { ERROR_ID, SERVICE_NAME } from '../../../../common/es_fields/apm';
import { environmentQuery } from '../../../../common/utils/environment_query';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getTransaction } from '../../transactions/get_transaction';
import { Transaction } from '../../../../typings/es_schemas/ui/transaction';
@ -38,7 +39,12 @@ export async function getErrorSampleDetails({
}): Promise<ErrorSampleDetailsResponse> {
const params = {
apm: {
events: [ProcessorEvent.error as const],
sources: [
{
documentType: ApmDocumentType.ErrorEvent as const,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -10,6 +10,7 @@ import {
kqlQuery,
rangeQuery,
} from '@kbn/observability-plugin/server';
import { ApmDocumentType } from '../../../../common/document_type';
import {
FAAS_BILLED_DURATION,
FAAS_DURATION,
@ -20,6 +21,7 @@ import {
METRIC_SYSTEM_TOTAL_MEMORY,
SERVICE_NAME,
} from '../../../../common/es_fields/apm';
import { RollupInterval } from '../../../../common/rollup';
import { environmentQuery } from '../../../../common/utils/environment_query';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { computeUsageAvgScript } from './get_compute_usage_chart';
@ -52,7 +54,12 @@ async function getServerlessTransactionThroughput({
}) {
const params = {
apm: {
events: [ProcessorEvent.transaction],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: true,

View file

@ -10,7 +10,6 @@ import {
kqlQuery,
rangeQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
DEVICE_MODEL_IDENTIFIER,
HOST_OS_VERSION,
@ -19,6 +18,8 @@ import {
TRANSACTION_TYPE,
} from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
export async function getDeviceOSApp({
@ -42,7 +43,12 @@ export async function getDeviceOSApp({
}) {
return await apmEventClient.search('get_mobile_device_os_app', {
apm: {
events: [ProcessorEvent.transaction],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
kqlQuery,
rangeQuery,
@ -23,6 +22,8 @@ import {
import { environmentQuery } from '../../../common/utils/environment_query';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
export interface CrashRateTimeseries {
currentPeriod: { timeseries: Coordinate[]; value: Maybe<number> };
@ -70,7 +71,12 @@ async function getMobileCrashTimeseries({
const response = await apmEventClient.search('get_mobile_crash_rate', {
apm: {
events: [ProcessorEvent.error],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
kqlQuery,
rangeQuery,
@ -16,6 +15,8 @@ import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_ev
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { getBucketSize } from '../../../common/utils/get_bucket_size';
import { environmentQuery } from '../../../common/utils/environment_query';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
interface Props {
kuery: string;
@ -64,7 +65,12 @@ export async function getCrashesByLocation({
};
const response = await apmEventClient.search('get_mobile_location_crashes', {
apm: {
events: [ProcessorEvent.error],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
kqlQuery,
rangeQuery,
@ -23,6 +22,8 @@ import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_ev
import { getBucketSize } from '../../../common/utils/get_bucket_size';
import { Coordinate } from '../../../typings/timeseries';
import { Maybe } from '../../../typings/common';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
export interface SessionsTimeseries {
currentPeriod: { timeseries: Coordinate[]; value: Maybe<number> };
@ -70,7 +71,12 @@ async function getSessionTimeseries({
const response = await apmEventClient.search('get_mobile_sessions', {
apm: {
events: [ProcessorEvent.transaction],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -10,12 +10,13 @@ import {
kqlQuery,
rangeQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { SERVICE_NAME, SESSION_ID } from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { getBucketSize } from '../../../common/utils/get_bucket_size';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
interface Props {
kuery: string;
@ -65,7 +66,12 @@ export async function getSessionsByLocation({
const response = await apmEventClient.search('get_mobile_location_sessions', {
apm: {
events: [ProcessorEvent.transaction],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -10,12 +10,13 @@ import {
kqlQuery,
rangeQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
NETWORK_CONNECTION_TYPE,
SERVICE_NAME,
} from '../../../common/es_fields/apm';
import { environmentQuery } from '../../../common/utils/environment_query';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
export async function getNCT({
@ -38,7 +39,12 @@ export async function getNCT({
}) {
return await apmEventClient.search('get_mobile_nct', {
apm: {
events: [ProcessorEvent.span],
sources: [
{
documentType: ApmDocumentType.SpanEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -6,7 +6,6 @@
*/
import { kqlQuery, rangeQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { HOST_NAME, CONTAINER_ID } from '../../../common/es_fields/apm';
import { NOT_AVAILABLE_LABEL } from '../../../common/i18n';
import { SERVICE_NAME, SERVICE_NODE_NAME } from '../../../common/es_fields/apm';
@ -15,6 +14,8 @@ import {
serviceNodeNameQuery,
} from '../../../common/utils/environment_query';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { ApmServiceTransactionDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
export interface ServiceNodeMetadataResponse {
host: string | number;
@ -29,6 +30,8 @@ export async function getServiceNodeMetadata({
start,
end,
environment,
documentType,
rollupInterval,
}: {
kuery: string;
serviceName: string;
@ -37,10 +40,17 @@ export async function getServiceNodeMetadata({
start: number;
end: number;
environment: string;
documentType: ApmServiceTransactionDocumentType;
rollupInterval: RollupInterval;
}): Promise<ServiceNodeMetadataResponse> {
const params = {
apm: {
events: [ProcessorEvent.metric],
sources: [
{
documentType,
rollupInterval,
},
],
},
body: {
track_total_hits: false,
@ -78,14 +88,14 @@ export async function getServiceNodeMetadata({
},
};
const response = await apmEventClient.search(
const { aggregations } = await apmEventClient.search(
'get_service_node_metadata',
params
);
return {
host: response.aggregations?.host.buckets[0]?.key || NOT_AVAILABLE_LABEL,
host: aggregations?.host.buckets[0]?.key || NOT_AVAILABLE_LABEL,
containerId:
response.aggregations?.containerId.buckets[0]?.key || NOT_AVAILABLE_LABEL,
aggregations?.containerId.buckets[0]?.key || NOT_AVAILABLE_LABEL,
};
}

View file

@ -368,14 +368,20 @@ const serviceNodeMetadataRoute = createApmServerRoute({
serviceName: t.string,
serviceNodeName: t.string,
}),
query: t.intersection([kueryRt, rangeRt, environmentRt]),
query: t.intersection([
kueryRt,
rangeRt,
environmentRt,
serviceTransactionDataSourceRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async (resources): Promise<ServiceNodeMetadataResponse> => {
const apmEventClient = await getApmEventClient(resources);
const { params } = resources;
const { serviceName, serviceNodeName } = params.path;
const { kuery, start, end, environment } = params.query;
const { kuery, start, end, environment, documentType, rollupInterval } =
params.query;
return getServiceNodeMetadata({
kuery,
@ -385,6 +391,8 @@ const serviceNodeMetadataRoute = createApmServerRoute({
start,
end,
environment,
documentType,
rollupInterval,
});
},
});

View file

@ -3,8 +3,11 @@
exports[`custom link get transaction fetches with all filter 1`] = `
Object {
"apm": Object {
"events": Array [
"transaction",
"sources": Array [
Object {
"documentType": "transactionEvent",
"rollupInterval": "none",
},
],
},
"body": Object {
@ -52,8 +55,11 @@ Object {
exports[`custom link get transaction fetches without filter 1`] = `
Object {
"apm": Object {
"events": Array [
"transaction",
"sources": Array [
Object {
"documentType": "transactionEvent",
"rollupInterval": "none",
},
],
},
"body": Object {

View file

@ -7,7 +7,8 @@
import * as t from 'io-ts';
import { compact } from 'lodash';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
import { filterOptionsRt } from './custom_link_types';
import { splitFilterValueByComma } from './helper';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
@ -29,10 +30,15 @@ export async function getTransaction({
})
);
const params = {
const resp = await apmEventClient.search('get_transaction_for_custom_link', {
terminate_after: 1,
apm: {
events: [ProcessorEvent.transaction as const],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,
@ -43,10 +49,6 @@ export async function getTransaction({
},
},
},
};
const resp = await apmEventClient.search(
'get_transaction_for_custom_link',
params
);
});
return resp.hits.hits[0]?._source;
}

View file

@ -3,8 +3,11 @@
exports[`trace queries fetches a trace 1`] = `
Object {
"apm": Object {
"events": Array [
"error",
"sources": Array [
Object {
"documentType": "error",
"rollupInterval": "none",
},
],
},
"body": Object {

View file

@ -55,6 +55,8 @@ import {
} from '../../../common/waterfall/typings';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';
import { getSpanLinksCountById } from '../span_links/get_linked_children';
import { ApmDocumentType } from '../../../common/document_type';
import { RollupInterval } from '../../../common/rollup';
export interface TraceItems {
exceedsMax: boolean;
@ -87,7 +89,12 @@ export async function getTraceItems({
const errorResponsePromise = apmEventClient.search('get_errors_docs', {
apm: {
events: [ProcessorEvent.error],
sources: [
{
documentType: ApmDocumentType.ErrorEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -3,8 +3,11 @@
exports[`transaction queries fetches a transaction 1`] = `
Object {
"apm": Object {
"events": Array [
"transaction",
"sources": Array [
Object {
"documentType": "transactionEvent",
"rollupInterval": "none",
},
],
},
"body": Object {

View file

@ -6,10 +6,11 @@
*/
import { rangeQuery, termQuery } from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { TRACE_ID, TRANSACTION_ID } from '../../../../common/es_fields/apm';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { ApmDocumentType } from '../../../../common/document_type';
import { RollupInterval } from '../../../../common/rollup';
export async function getTransaction({
transactionId,
@ -26,7 +27,12 @@ export async function getTransaction({
}) {
const resp = await apmEventClient.search('get_transaction', {
apm: {
events: [ProcessorEvent.transaction],
sources: [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
},
],
},
body: {
track_total_hits: false,

View file

@ -7,6 +7,8 @@
import expect from '@kbn/expect';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type';
import { RollupInterval } from '@kbn/apm-plugin/common/rollup';
import { FtrProviderContext } from '../../common/ftr_provider_context';
export default function ApiTest({ getService }: FtrProviderContext) {
@ -29,6 +31,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {
end: new Date(end).toISOString(),
kuery: '',
environment: 'production',
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
},
},
});