Skip to content

Commit

Permalink
[APM] Add table search to services, transactions and errors (elastic#…
Browse files Browse the repository at this point in the history
…174490)

Closes: elastic#127036

This adds the ability to easily search for data in tables. The search
will be performed server side if there are more results than initially
returned by Elasticsearch. If all results were returned the search is
performed client side to provide a more snappy experience.
The feature is guarded by a feature flag (disabled by default) and only
available for services, transactions and errors table.

# Transactions


![quick-filtering](https://github.com/elastic/kibana/assets/209966/20684b88-a103-4000-a012-ee6e35479b44)

# Errors


![error3](https://github.com/elastic/kibana/assets/209966/c7f09dd9-24a5-482a-ae72-4c4477f65d3a)


**Dependencies:**

- elastic#173973
- elastic#174746
- elastic#174750

---------

Co-authored-by: Caue Marcondes <caue.marcondes@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people authored and CoenWarmer committed Feb 15, 2024
1 parent 0ecba9b commit 4e6c910
Show file tree
Hide file tree
Showing 65 changed files with 1,778 additions and 1,520 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type ApmFields = Fields<{
'error.grouping_name': string;
'error.id': string;
'error.type': string;
'error.culprit': string;
'event.ingested': number;
'event.name': string;
'event.action': string;
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-apm-synthtrace-client/src/lib/apm/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ export class Instance extends Entity<ApmFields> {
'error.grouping_name': getErrorGroupingKey(message),
});
}
error({ message, type }: { message: string; type?: string }) {
error({ message, type, culprit }: { message: string; type?: string; culprit?: string }) {
return new ApmError({
...this.fields,
'error.exception': [{ message, ...(type ? { type } : {}) }],
'error.grouping_name': getErrorGroupingKey(message),
'error.culprit': culprit,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export const exceptionTypes = [
'ProgrammingError',
'ProtocolError',
'RangeError',
'ReadTimeout',
'ReadTimeoutError',
'ReferenceError',
'RemoteDisconnected',
'RequestAbortedError',
'ResponseError (action_request_validation_exception)',
'ResponseError (illegal_argument_exception)',
'ResponseError (index_not_found_exception)',
'ResponseError (index_template_missing_exception)',
'ResponseError (resource_already_exists_exception)',
'ResponseError (resource_not_found_exception)',
'ResponseError (search_phase_execution_exception)',
'ResponseError (security_exception)',
'ResponseError (transport_serialization_exception)',
'ResponseError (version_conflict_engine_exception)',
'ResponseError (x_content_parse_exception)',
'ResponseError',
'SIGTRAP',
'SocketError',
'SpawnError',
'SyntaxError',
'SyscallError',
'TimeoutError',
'TimeoutError',
'TypeError',
];

export function getExceptionTypeForIndex(index: number) {
return exceptionTypes[index % exceptionTypes.length];
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ const scenario: Scenario<LogDocument> = async (runOptions) => {
.failure()
.errors(
instance
.error({ message: '[ResponseError] index_not_found_exception' })
.error({
message: '[ResponseError] index_not_found_exception',
type: 'ResponseError',
})
.timestamp(timestamp + 50)
)
);
Expand Down
73 changes: 73 additions & 0 deletions packages/kbn-apm-synthtrace/src/scenarios/many_dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ApmFields, Instance } from '@kbn/apm-synthtrace-client';
import { service } from '@kbn/apm-synthtrace-client/src/lib/apm/service';
import { random, times } from 'lodash';
import { Scenario } from '../cli/scenario';
import { RunOptions } from '../cli/utils/parse_run_cli_flags';
import { getSynthtraceEnvironment } from '../lib/utils/get_synthtrace_environment';
import { withClient } from '../lib/utils/with_client';

const ENVIRONMENT = getSynthtraceEnvironment(__filename);
const NUMBER_OF_DEPENDENCIES_PER_SERVICE = 2000;
const NUMBER_OF_SERVICES = 1;

const scenario: Scenario<ApmFields> = async (runOptions: RunOptions) => {
return {
generate: ({ range, clients: { apmEsClient } }) => {
const instances = times(NUMBER_OF_SERVICES).map((index) =>
service({
name: `synthtrace-high-cardinality-${index}`,
environment: ENVIRONMENT,
agentName: 'java',
}).instance(`java-instance-${index}`)
);

const instanceDependencies = (instance: Instance, id: string) => {
const throughput = random(1, 60);
const childLatency = random(10, 100_000);
const parentLatency = childLatency + random(10, 10_000);

const failureRate = random(0, 100);

return range.ratePerMinute(throughput).generator((timestamp) => {
const child = instance
.span({
spanName: 'GET apm-*/_search',
spanType: 'db',
spanSubtype: 'elasticsearch',
})
.destination(`elasticsearch/${id}`)
.timestamp(timestamp)
.duration(childLatency);

const span = instance
.transaction({ transactionName: 'GET /java' })
.timestamp(timestamp)
.duration(parentLatency)
.success()
.children(Math.random() * 100 > failureRate ? child.success() : child.failure());

return span;
});
};

return withClient(
apmEsClient,
instances.flatMap((instance, i) =>
times(NUMBER_OF_DEPENDENCIES_PER_SERVICE)
.map((j) => instanceDependencies(instance, `${i + 1}.${j + 1}`))
.flat()
)
);
},
};
};

export default scenario;
16 changes: 13 additions & 3 deletions packages/kbn-apm-synthtrace/src/scenarios/many_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ import { ApmFields, apm } from '@kbn/apm-synthtrace-client';
import { Scenario } from '../cli/scenario';
import { getSynthtraceEnvironment } from '../lib/utils/get_synthtrace_environment';
import { withClient } from '../lib/utils/with_client';
import { getExceptionTypeForIndex } from './helpers/exception_types';
import { getRandomNameForIndex } from './helpers/random_names';

const ENVIRONMENT = getSynthtraceEnvironment(__filename);

const scenario: Scenario<ApmFields> = async (runOptions) => {
const { logger } = runOptions;

const severities = ['critical', 'error', 'warning', 'info', 'debug', 'trace'];

return {
generate: ({ range, clients: { apmEsClient } }) => {
const transactionName = 'DELETE /api/orders/{id}';

const instance = apm
.service({ name: `synth-node`, environment: ENVIRONMENT, agentName: 'nodejs' })
.service({
name: `synthtrace-high-cardinality-0`,
environment: ENVIRONMENT,
agentName: 'java',
})
.instance('instance');

const failedTraceEvents = range
Expand All @@ -38,7 +42,13 @@ const scenario: Scenario<ApmFields> = async (runOptions) => {
.duration(1000)
.failure()
.errors(
instance.error({ message: errorMessage, type: 'My Type' }).timestamp(timestamp + 50)
instance
.error({
message: errorMessage,
type: getExceptionTypeForIndex(index),
culprit: 'request (node_modules/@elastic/transport/src/Transport.ts)',
})
.timestamp(timestamp + 50)
);
});

Expand Down
21 changes: 11 additions & 10 deletions packages/kbn-apm-synthtrace/src/scenarios/many_instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const ENVIRONMENT = getSynthtraceEnvironment(__filename);
const scenario: Scenario<ApmFields> = async ({ logger, scenarioOpts = { instances: 2000 } }) => {
const numInstances = scenarioOpts.instances;
const agentVersions = ['2.1.0', '2.0.0', '1.15.0', '1.14.0', '1.13.1'];
const language = 'go';
const serviceName = 'synth-many-instances';
const language = 'java';
const transactionName = 'GET /order/{id}';

return {
Expand All @@ -29,7 +28,7 @@ const scenario: Scenario<ApmFields> = async ({ logger, scenarioOpts = { instance
const randomName = getRandomNameForIndex(index);
return apm
.service({
name: serviceName,
name: 'synthtrace-high-cardinality-0',
environment: ENVIRONMENT,
agentName: language,
})
Expand All @@ -51,13 +50,15 @@ const scenario: Scenario<ApmFields> = async ({ logger, scenarioOpts = { instance

return !generateError
? span.success()
: span
.failure()
.errors(
instance
.error({ message: `No handler for ${transactionName}` })
.timestamp(timestamp + 50)
);
: span.failure().errors(
instance
.error({
message: `No handler for ${transactionName}`,
type: 'No handler',
culprit: 'request',
})
.timestamp(timestamp + 50)
);
});

const cpuPct = random(0, 1);
Expand Down
16 changes: 9 additions & 7 deletions packages/kbn-apm-synthtrace/src/scenarios/many_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ const scenario: Scenario<ApmFields> = async ({ logger, scenarioOpts = { services

return !generateError
? span.success()
: span
.failure()
.errors(
instance
.error({ message: `No handler for ${transactionName}` })
.timestamp(timestamp + 50)
);
: span.failure().errors(
instance
.error({
message: `No handler for ${transactionName}`,
type: 'No handler',
culprit: 'request',
})
.timestamp(timestamp + 50)
);
});
};

Expand Down
12 changes: 10 additions & 2 deletions packages/kbn-apm-synthtrace/src/scenarios/many_transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ const scenario: Scenario<ApmFields> = async (runOptions) => {
generate: ({ range, clients: { apmEsClient } }) => {
const instances = times(numServices).map((index) =>
apm
.service({ name: `synth-go-${index}`, environment: ENVIRONMENT, agentName: 'go' })
.service({
name: `synthtrace-high-cardinality-${index}`,
environment: ENVIRONMENT,
agentName: 'java',
})
.instance(`instance-${index}`)
);

Expand All @@ -60,7 +64,11 @@ const scenario: Scenario<ApmFields> = async (runOptions) => {
.failure()
.errors(
instance
.error({ message: '[ResponseError] index_not_found_exception' })
.error({
message: '[ResponseError] index_not_found_exception',
type: 'ResponseError',
culprit: 'elasticsearch',
})
.timestamp(timestamp + 50)
)
);
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion packages/kbn-apm-synthtrace/src/scenarios/simple_trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ const scenario: Scenario<ApmFields> = async (runOptions) => {
.failure()
.errors(
instance
.error({ message: '[ResponseError] index_not_found_exception' })
.error({
message: '[ResponseError] index_not_found_exception',
type: 'ResponseError',
})
.timestamp(timestamp + 50)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,31 @@ describe('Service inventory', () => {
});
});

describe('Table search', () => {
beforeEach(() => {
cy.updateAdvancedSettings({
'observability:apmEnableTableSearchBar': true,
});

cy.loginAsEditorUser();
});

it('filters for java service on the table', () => {
cy.visitKibana(serviceInventoryHref);
cy.contains('opbeans-node');
cy.contains('opbeans-java');
cy.contains('opbeans-rum');
cy.get('[data-test-subj="tableSearchInput"]').type('java');
cy.contains('opbeans-node').should('not.exist');
cy.contains('opbeans-java');
cy.contains('opbeans-rum').should('not.exist');
cy.get('[data-test-subj="tableSearchInput"]').clear();
cy.contains('opbeans-node');
cy.contains('opbeans-java');
cy.contains('opbeans-rum');
});
});

describe('Check detailed statistics API with multiple services', () => {
before(() => {
// clean previous data created
Expand Down
Loading

0 comments on commit 4e6c910

Please sign in to comment.