Skip to content

Commit

Permalink
[APM] Add table tabs showing summary of metrics (#153044)
Browse files Browse the repository at this point in the history
Closes #146877

Notes:
- Crash rate is calculated per sessions, the same session ID is kept
after a crash, so a session can have more than one crash.
- App number of launches is not available
- Error rate stays out for now
- Http requests, `host.os.version` and `service.version` is only
available on transactions, metrics and errors. Not spans for now, there
are two issues opened to fix this for the apm mobile agents team
- Instead of the View Load (not available), we show Throughput 
- The filters (+ -) will be added in a follow-up PR

Pending:
- [x] API tests
- [x] e2e tests


https://user-images.githubusercontent.com/31922082/234267965-e5e1e411-87c6-40b8-9e94-31d792f9d806.mov

---------

Co-authored-by: Yngrid Coello <[email protected]>
  • Loading branch information
MiriamAparicio and yngrdyn authored Apr 25, 2023
1 parent 3864554 commit b6a91f3
Show file tree
Hide file tree
Showing 27 changed files with 1,826 additions and 64 deletions.
2 changes: 2 additions & 0 deletions packages/kbn-apm-synthtrace-client/src/lib/apm/apm_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ApmApplicationMetricFields = Partial<{
'faas.timeout': number;
'faas.coldstart_duration': number;
'faas.duration': number;
'application.launch.time': number;
}>;

export type ApmUserAgentFields = Partial<{
Expand Down Expand Up @@ -88,6 +89,7 @@ export type ApmFields = Fields<{
'error.grouping_key': string;
'error.grouping_name': string;
'error.id': string;
'error.type': string;
'event.ingested': number;
'event.name': string;
'event.outcome': string;
Expand Down
22 changes: 21 additions & 1 deletion packages/kbn-apm-synthtrace-client/src/lib/apm/mobile_device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import { Entity } from '../entity';
import { Span } from './span';
import { Transaction } from './transaction';
import { ApmFields, SpanParams, GeoLocation } from './apm_fields';
import { ApmFields, SpanParams, GeoLocation, ApmApplicationMetricFields } from './apm_fields';
import { generateLongId } from '../utils/generate_id';
import { Metricset } from './metricset';
import { ApmError } from './apm_error';

export interface DeviceInfo {
manufacturer: string;
Expand Down Expand Up @@ -115,6 +117,7 @@ export class MobileDevice extends Entity<ApmFields> {
return this;
}

// FIXME synthtrace shouldn't have side-effects like this. We should use an API like .session() which returns a session
startNewSession() {
this.fields['session.id'] = generateLongId();
return this;
Expand Down Expand Up @@ -238,4 +241,21 @@ export class MobileDevice extends Entity<ApmFields> {

return this.span(spanParameters);
}

appMetrics(metrics: ApmApplicationMetricFields) {
return new Metricset<ApmFields>({
...this.fields,
'metricset.name': 'app',
...metrics,
});
}

crash({ message, groupingName }: { message: string; groupingName?: string }) {
return new ApmError({
...this.fields,
'error.type': 'crash',
'error.exception': [{ message, ...{ type: 'crash' } }],
'error.grouping_name': groupingName || message,
});
}
}
88 changes: 60 additions & 28 deletions packages/kbn-apm-synthtrace/src/scenarios/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const ENVIRONMENT = getSynthtraceEnvironment(__filename);

type DeviceMetadata = DeviceInfo & OSInfo;

const modelIdentifiersWithCrashes = [
'SM-G930F',
'HUAWEI P2-0000',
'Pixel 3a',
'LG K10',
'iPhone11,8',
'Watch6,8',
'iPad12,2',
];

const ANDROID_DEVICES: DeviceMetadata[] = [
{
manufacturer: 'Samsung',
Expand Down Expand Up @@ -354,34 +364,40 @@ const scenario: Scenario<ApmFields> = async ({ scenarioOpts, logger }) => {
device.startNewSession();
const framework =
device.fields['device.manufacturer'] === 'Apple' ? 'iOS' : 'Android Activity';
const couldCrash = modelIdentifiersWithCrashes.includes(
device.fields['device.model.identifier'] ?? ''
);
const startTx = device
.transaction('Start View - View Appearing', framework)
.timestamp(timestamp)
.duration(500)
.success()
.children(
device
.span({
spanName: 'onCreate',
spanType: 'app',
spanSubtype: 'external',
'service.target.type': 'http',
'span.destination.service.resource': 'external',
})
.duration(50)
.success()
.timestamp(timestamp + 20),
device
.httpSpan({
spanName: 'GET backend:1234',
httpMethod: 'GET',
httpUrl: 'https://backend:1234/api/start',
})
.duration(800)
.failure()
.timestamp(timestamp + 400)
);
return [
device
.transaction('Start View - View Appearing', framework)
.timestamp(timestamp)
.duration(500)
.success()
.children(
device
.span({
spanName: 'onCreate',
spanType: 'app',
spanSubtype: 'external',
'service.target.type': 'http',
'span.destination.service.resource': 'external',
})
.duration(50)
.success()
.timestamp(timestamp + 20),
device
.httpSpan({
spanName: 'GET backend:1234',
httpMethod: 'GET',
httpUrl: 'https://backend:1234/api/start',
})
.duration(800)
.failure()
.timestamp(timestamp + 400)
),
couldCrash && index % 2 === 0
? startTx.errors(device.crash({ message: 'error' }).timestamp(timestamp))
: startTx,
device
.transaction('Second View - View Appearing', framework)
.timestamp(10000 + timestamp)
Expand Down Expand Up @@ -418,7 +434,23 @@ const scenario: Scenario<ApmFields> = async ({ scenarioOpts, logger }) => {
});
};

return [...androidDevices, ...iOSDevices].map((device) => sessionTransactions(device));
const appLaunchMetrics = (device: MobileDevice) => {
return clickRate.generator((timestamp, index) =>
device
.appMetrics({
'application.launch.time': 100 * (index + 1),
})
.timestamp(timestamp)
);
};

return [
...androidDevices.flatMap((device) => [
sessionTransactions(device),
appLaunchMetrics(device),
]),
...iOSDevices.map((device) => sessionTransactions(device)),
];
},
};
};
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/common/data_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type AnyApmDocumentType =
| ApmDocumentType.TransactionMetric
| ApmDocumentType.TransactionEvent
| ApmDocumentType.ServiceDestinationMetric
| ApmDocumentType.ServiceSummaryMetric;
| ApmDocumentType.ServiceSummaryMetric
| ApmDocumentType.ErrorEvent;

export interface ApmDataSource<
TDocumentType extends AnyApmDocumentType = AnyApmDocumentType
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/common/document_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum ApmDocumentType {
TransactionEvent = 'transactionEvent',
ServiceDestinationMetric = 'serviceDestinationMetric',
ServiceSummaryMetric = 'serviceSummaryMetric',
ErrorEvent = 'error',
}

export type ApmServiceTransactionDocumentType =
Expand Down

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

1 change: 1 addition & 0 deletions x-pack/plugins/apm/common/es_fields/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const ERROR_EXC_MESSAGE = 'error.exception.message'; // only to be used i
export const ERROR_EXC_HANDLED = 'error.exception.handled'; // only to be used in es queries, since error.exception is now an array
export const ERROR_EXC_TYPE = 'error.exception.type';
export const ERROR_PAGE_URL = 'error.page.url';
export const ERROR_TYPE = 'error.type';

// METRICS
export const METRIC_SYSTEM_FREE_MEMORY = 'system.memory.actual.free';
Expand Down
Loading

0 comments on commit b6a91f3

Please sign in to comment.