Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
[APM] Include error documents in fallback query for services (elastic…
Browse files Browse the repository at this point in the history
…#123554)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dgieselaar and kibanamachine authored Jan 24, 2022
1 parent e76cedb commit 650919c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { environmentQuery } from '../../../../common/utils/environment_query';
import { ProcessorEvent } from '../../../../common/processor_event';
import { Setup } from '../../../lib/helpers/setup_request';

export async function getServicesFromMetricDocuments({
export async function getServicesFromErrorAndMetricDocuments({
environment,
setup,
maxNumServices,
Expand All @@ -34,10 +34,10 @@ export async function getServicesFromMetricDocuments({
const { apmEventClient } = setup;

const response = await apmEventClient.search(
'get_services_from_metric_documents',
'get_services_from_error_and_metric_documents',
{
apm: {
events: [ProcessorEvent.metric],
events: [ProcessorEvent.metric, ProcessorEvent.error],
},
body: {
size: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Logger } from '@kbn/logging';
import { withApmSpan } from '../../../utils/with_apm_span';
import { Setup } from '../../../lib/helpers/setup_request';
import { getHealthStatuses } from './get_health_statuses';
import { getServicesFromMetricDocuments } from './get_services_from_metric_documents';
import { getServicesFromErrorAndMetricDocuments } from './get_services_from_error_and_metric_documents';
import { getServiceTransactionStats } from './get_service_transaction_stats';
import { mergeServiceStats } from './merge_service_stats';

Expand Down Expand Up @@ -45,19 +45,22 @@ export async function getServicesItems({
end,
};

const [transactionStats, servicesFromMetricDocuments, healthStatuses] =
await Promise.all([
getServiceTransactionStats(params),
getServicesFromMetricDocuments(params),
getHealthStatuses(params).catch((err) => {
logger.error(err);
return [];
}),
]);
const [
transactionStats,
servicesFromErrorAndMetricDocuments,
healthStatuses,
] = await Promise.all([
getServiceTransactionStats(params),
getServicesFromErrorAndMetricDocuments(params),
getHealthStatuses(params).catch((err) => {
logger.error(err);
return [];
}),
]);

return mergeServiceStats({
transactionStats,
servicesFromMetricDocuments,
servicesFromErrorAndMetricDocuments,
healthStatuses,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('mergeServiceStats', () => {
throughput: 4,
}),
],
servicesFromMetricDocuments: [
servicesFromErrorAndMetricDocuments: [
{
environments: ['production'],
serviceName: 'opbeans-java',
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('mergeServiceStats', () => {
environments: ['staging'],
}),
],
servicesFromMetricDocuments: [
servicesFromErrorAndMetricDocuments: [
{
environments: ['production'],
serviceName: 'opbeans-java',
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('mergeServiceStats', () => {
environments: ['staging'],
}),
],
servicesFromMetricDocuments: [],
servicesFromErrorAndMetricDocuments: [],
healthStatuses: [
{
healthStatus: ServiceHealthStatus.healthy,
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('mergeServiceStats', () => {
environments: ['staging'],
}),
],
servicesFromMetricDocuments: [
servicesFromErrorAndMetricDocuments: [
{
environments: ['production'],
serviceName: 'opbeans-java',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ import { uniq } from 'lodash';
import { asMutableArray } from '../../../../common/utils/as_mutable_array';
import { joinByKey } from '../../../../common/utils/join_by_key';
import { getHealthStatuses } from './get_health_statuses';
import { getServicesFromMetricDocuments } from './get_services_from_metric_documents';
import { getServicesFromErrorAndMetricDocuments } from './get_services_from_error_and_metric_documents';
import { getServiceTransactionStats } from './get_service_transaction_stats';

export function mergeServiceStats({
transactionStats,
servicesFromMetricDocuments,
servicesFromErrorAndMetricDocuments,
healthStatuses,
}: {
transactionStats: Awaited<ReturnType<typeof getServiceTransactionStats>>;
servicesFromMetricDocuments: Awaited<
ReturnType<typeof getServicesFromMetricDocuments>
servicesFromErrorAndMetricDocuments: Awaited<
ReturnType<typeof getServicesFromErrorAndMetricDocuments>
>;
healthStatuses: Awaited<ReturnType<typeof getHealthStatuses>>;
}) {
const foundServiceNames = transactionStats.map(
({ serviceName }) => serviceName
);

const servicesWithOnlyMetricDocuments = servicesFromMetricDocuments.filter(
({ serviceName }) => !foundServiceNames.includes(serviceName)
);
const servicesWithOnlyMetricDocuments =
servicesFromErrorAndMetricDocuments.filter(
({ serviceName }) => !foundServiceNames.includes(serviceName)
);

const allServiceNames = foundServiceNames.concat(
servicesWithOnlyMetricDocuments.map(({ serviceName }) => serviceName)
Expand All @@ -43,7 +44,7 @@ export function mergeServiceStats({
return joinByKey(
asMutableArray([
...transactionStats,
...servicesFromMetricDocuments,
...servicesFromErrorAndMetricDocuments,
...matchedHealthStatuses,
] as const),
'serviceName',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const transactionInterval = range.interval('1s');
const metricInterval = range.interval('30s');

const errorInterval = range.interval('5s');

const multipleEnvServiceProdInstance = apm
.service('multiple-env-service', 'production', 'go')
.instance('multiple-env-service-production');
Expand All @@ -76,6 +78,10 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.service('metric-only-service', 'production', 'java')
.instance('metric-only-production');

const errorOnlyInstance = apm
.service('error-only-service', 'production', 'java')
.instance('error-only-production');

const config = {
multiple: {
prod: {
Expand Down Expand Up @@ -132,6 +138,11 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.timestamp(timestamp)
.serialize(),
]),
...errorInterval
.rate(1)
.flatMap((timestamp) => [
...errorOnlyInstance.error('Foo').timestamp(timestamp).serialize(),
]),
]);
});

Expand Down Expand Up @@ -185,6 +196,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const serviceNames = response.body.items.map((item) => item.serviceName);

expect(serviceNames).to.contain('metric-only-service');

expect(serviceNames).to.contain('error-only-service');
});
});

Expand Down

0 comments on commit 650919c

Please sign in to comment.