Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

5.8 KB
Raw Blame
// Per-service error and latency anomalies: each compares a service with its
// own usual band, so it fires on a change rather than a fixed count.
//
// Datadog only: prod traces and logs don't reach Grafana, and Grafana alerting
// has no anomaly detection.
import * as datadog from '@pulumi/datadog';
import { graphGroup, prodMonitor, thresholdGraph } from '../prod-monitor';

// Datadog has no anomaly function for log monitors, so the error-logs anomaly
// monitor reads this log-based metric instead. Counts every prod error log
// line, tagged by service.
new datadog.LogsMetric('macro-logs-errors', {
  name: 'macro.logs.errors',
  compute: { aggregationType: 'count' },
  filter: { query: 'env:prod status:error' },
  groupBies: [{ path: 'service', tagName: 'service' }],
});

// One graph per monitor below, titled like it, with the anomaly band each
// monitor alerts outside of.
const dashboard = new datadog.Dashboard('regression-alerts', {
  title: 'Regression alerts',
  description:
    'Every prod error and latency anomaly monitor with its band. Declared in infra/stacks/monitoring/monitors/regressions.ts; see docs/runbooks/regressions.md.',
  layoutType: 'ordered',
  widgets: [
    graphGroup('Errors', [
      thresholdGraph({
        title: 'HTTP server errors abnormally high',
        query:
          "anomalies(sum:trace.http.server.request.errors{env:prod} by {service}.as_count(), 'agile', 3)",
      }),
      thresholdGraph({
        title: 'Internal span errors abnormally high',
        query:
          "anomalies(sum:trace.Internal.errors{env:prod AND NOT service:web-app} by {service}.as_count(), 'agile', 3)",
      }),
      thresholdGraph({
        title: 'Queue consumer errors abnormally high',
        query:
          "anomalies(sum:trace.Consumer.errors{env:prod} by {service}.as_count(), 'agile', 3)",
      }),
      thresholdGraph({
        title: 'Error logs abnormally high',
        query:
          "anomalies(sum:macro.logs.errors{*} by {service}.as_count(), 'agile', 3)",
      }),
    ]),
    graphGroup('Latency', [
      thresholdGraph({
        title: 'HTTP latency abnormally high',
        query:
          "anomalies(p95:trace.http.server.request{env:prod AND (service:cloud-storage-service OR service:authentication-service)} by {service}, 'agile', 3)",
      }),
    ]),
  ],
});

// An anomaly monitor recovers once no point in its window is outside the band.
const ANOMALY_THRESHOLDS = { critical: '1', criticalRecovery: '0' };
const ANOMALY_WINDOWS = {
  triggerWindow: 'last_30m',
  recoveryWindow: 'last_15m',
};

prodMonitor('apm-server-error-anomaly', {
  title: 'HTTP server errors abnormally high',
  service: 'apm',
  query:
    "avg(last_4h):anomalies(sum:trace.http.server.request.errors{env:prod} by {service}.as_count(), 'agile', 3, direction='above', interval=300, alert_window='last_30m', count_default_zero='true') >= 1",
  monitorThresholds: ANOMALY_THRESHOLDS,
  monitorThresholdWindows: ANOMALY_WINDOWS,
  pages: false,
  description:
    '{{service.name}} is returning more HTTP server errors than its usual band. Check the latest deploy of that service first.',
  dashboard: dashboard.url,
  runbook: 'docs/runbooks/regressions.md#errors',
});

// Excludes web-app: browser spans fail on users' networks and devices, so its
// band swings with traffic. Browser errors have their own RUM monitors.
prodMonitor('apm-internal-error-anomaly', {
  title: 'Internal span errors abnormally high',
  service: 'apm',
  query:
    "avg(last_4h):anomalies(sum:trace.Internal.errors{env:prod AND NOT service:web-app} by {service}.as_count(), 'agile', 3, direction='above', interval=300, alert_window='last_30m', count_default_zero='true') >= 1",
  monitorThresholds: ANOMALY_THRESHOLDS,
  monitorThresholdWindows: ANOMALY_WINDOWS,
  pages: false,
  description:
    '{{service.name}} is recording more failed internal spans (background jobs, workers) than its usual band. Check the latest deploy of that service first.',
  dashboard: dashboard.url,
  runbook: 'docs/runbooks/regressions.md#errors',
});

prodMonitor('apm-consumer-error-anomaly', {
  title: 'Queue consumer errors abnormally high',
  service: 'apm',
  query:
    "avg(last_4h):anomalies(sum:trace.Consumer.errors{env:prod} by {service}.as_count(), 'agile', 3, direction='above', interval=300, alert_window='last_30m', count_default_zero='true') >= 1",
  monitorThresholds: ANOMALY_THRESHOLDS,
  monitorThresholdWindows: ANOMALY_WINDOWS,
  pages: false,
  description:
    '{{service.name}} is failing more queue and Kafka messages than its usual band.',
  dashboard: dashboard.url,
  runbook: 'docs/runbooks/regressions.md#errors',
});

prodMonitor('apm-latency-anomaly', {
  title: 'HTTP latency abnormally high',
  service: 'apm',
  query:
    "avg(last_4h):anomalies(p95:trace.http.server.request{env:prod AND (service:cloud-storage-service OR service:authentication-service)} by {service}, 'agile', 3, direction='above', interval=300, alert_window='last_30m', count_default_zero='true') >= 1",
  monitorThresholds: ANOMALY_THRESHOLDS,
  monitorThresholdWindows: ANOMALY_WINDOWS,
  pages: false,
  description: '{{service.name}} p95 HTTP latency is above its usual band.',
  dashboard: dashboard.url,
  runbook: 'docs/runbooks/regressions.md#latency',
});

prodMonitor('error-logs-anomaly', {
  title: 'Error logs abnormally high',
  service: 'logs',
  query:
    "avg(last_4h):anomalies(sum:macro.logs.errors{*} by {service}.as_count(), 'agile', 3, direction='above', interval=300, alert_window='last_30m', count_default_zero='true') >= 1",
  monitorThresholds: ANOMALY_THRESHOLDS,
  monitorThresholdWindows: ANOMALY_WINDOWS,
  pages: false,
  description:
    '{{service.name}} is logging more errors than its usual band. Check the latest deploy of that service first.',
  dashboard: dashboard.url,
  runbook: 'docs/runbooks/regressions.md#errors',
});