Skip to content

Commit

Permalink
Additional instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
matschaffer committed Jun 14, 2022
1 parent aee16d6 commit 2804efc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion x-pack/plugins/alerting/server/monitoring/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
* 2.0.
*/

import { Counter, Meter } from '@opentelemetry/api-metrics';
import { Counter, Histogram, Meter } from '@opentelemetry/api-metrics';

export class Metrics {
ruleExecutionsTotal: Counter;
ruleExecutions: Counter;
ruleFailures: Counter;
ruleDuration: Histogram;

constructor(meter: Meter) {
this.ruleExecutionsTotal = meter.createCounter('ruleExecutionsTotal');
this.ruleExecutions = meter.createCounter('ruleExecutions');
this.ruleFailures = meter.createCounter('ruleFailures');
this.ruleDuration = meter.createHistogram('ruleDuration');
}
}
5 changes: 4 additions & 1 deletion x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ export class TaskRunner<
if (null != duration) {
executionStatus.lastDuration = nanosToMillis(duration);
monitoringHistory.duration = executionStatus.lastDuration;
this.metrics.ruleDuration.record(executionStatus.lastDuration);
}

// if executionStatus indicates an error, fill in fields in
Expand All @@ -802,9 +803,11 @@ export class TaskRunner<
if (!this.cancelled) {
this.inMemoryMetrics.increment(IN_MEMORY_METRICS.RULE_EXECUTIONS);
// NOTE: Using the typesafe opentelemetry counter here directly
this.metrics.ruleExecutions.add(1);
this.metrics.ruleExecutionsTotal.add(1);
this.metrics.ruleExecutions.add(1, { ruleType: this.ruleType.id });
if (executionStatus.error) {
this.inMemoryMetrics.increment(IN_MEMORY_METRICS.RULE_FAILURES);
this.metrics.ruleFailures.add(1);
}
this.logger.debug(
`Updating rule task for ${this.ruleType.id} rule with id ${ruleId} - ${JSON.stringify(
Expand Down

0 comments on commit 2804efc

Please sign in to comment.