Skip to content

Commit

Permalink
[APM] Fix service metrics generator (#142790)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
kpatticha and kibanamachine authored Oct 10, 2022
1 parent 6139304 commit 6ec4061
Showing 1 changed file with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ export type ServiceFields = Fields &
| 'service.name'
| 'service.version'
| 'service.environment'
| 'transaction.type'
> &
Partial<{
_doc_count: number;
transaction: {
duration: {
summary: {
min: number;
max: number;
sum: number;
value_count: number;
};
};
failure_count: number;
success_count: number;
type: string;
'duration.summary': {
min: number;
max: number;
sum: number;
value_count: number;
};
};
}>;

Expand Down Expand Up @@ -86,10 +84,10 @@ export class ServicMetricsAggregator implements StreamAggregator<ApmFields> {
},
},
failure_count: {
type: { type: 'long' },
type: 'long',
},
success_count: {
type: { type: 'long' },
type: 'long',
},
},
},
Expand Down Expand Up @@ -141,22 +139,24 @@ export class ServicMetricsAggregator implements StreamAggregator<ApmFields> {
}

const state = this.state[key];
state.count++;

switch (event['event.outcome']) {
case 'failure':
state.failure_count++;
break;
case 'success':
state.success_count++;
break;
}

const duration = Number(event['transaction.duration.us']);

if (duration >= 0) {
state.count++;

state.sum += duration;
if (duration > state.max) state.max = duration;
if (duration < state.min) state.min = Math.min(0, duration);

switch (event['event.outcome']) {
case 'failure':
state.failure_count++;
break;
case 'success':
state.success_count++;
break;
}
}
};

Expand Down Expand Up @@ -197,18 +197,16 @@ export class ServicMetricsAggregator implements StreamAggregator<ApmFields> {
'processor.event': 'metric',
'service.name': state['service.name'],
'service.environment': state['service.environment'],
'transaction.type': state['transaction.type'],
transaction: {
duration: {
summary: {
min: state.min,
max: state.max,
sum: state.sum,
value_count: state.count,
},
'duration.summary': {
min: state.min,
max: state.max,
sum: state.sum,
value_count: state.count,
},
failure_count: state.failure_count,
success_count: state.success_count,
failure_count: state.failure_count,
type: state['transaction.type'] ?? 'request',
},
};
}
Expand Down

0 comments on commit 6ec4061

Please sign in to comment.