Skip to main content

Turn on the alarms

The engine serves its metrics at /metrics on its health endpoint (Collect metrics). With alarms_enabled, the module runs an OpenTelemetry collector beside the engine in each replica, sends five of those metrics to an Application Insights resource, and creates five Azure Monitor metric alerts that call an action group you give. It is off by default: until you turn it on, the module creates none of it and nothing of it bills.

What you need first​

  • An action group, with its receivers (email, SMS, a webhook, and so on): each alert calls it when it fires and when it resolves.

  • The collector's image, pinned by digest. The OpenTelemetry Collector Contrib image (otel/opentelemetry-collector-contrib) has every component the module's configuration uses: the prometheus receiver, the filter, metricstransform and cumulativetodelta processors and the azuremonitor exporter. Pick a version and pin it by the digest the registry gives for it; the module refuses a tag alone. If you copy it to your own registry, container_registry_server applies to it as it does to the engine's image.

  • A health endpoint in your pathways.yaml, on alarms_health_port (9090 by default):

    pathways.yaml
    health:
    port: 9090
    plaintext: true

    With no host it binds to 127.0.0.1, so only the collector in the same replica reaches it, over plain HTTP that never leaves the replica. With no auth it asks for the bearer token in PATHWAYS_HEALTH_TOKEN, which the module sets. No ingress points at the port.

  • Room for the collector. It takes 0.25 vCPU and 0.5 GiB beside the engine's cpu and memory, so cpu must be 3.75 or less; the plan refuses more.

Turn it on​

main.tf
module "pathways" {
source = "github.com/cosyte/terraform-azurerm-pathways?ref=<commit or tag>"
# ...the inputs you already set

alarms_enabled = true
alarms_action_group_id = "/subscriptions/<id>/resourceGroups/<group>/providers/Microsoft.Insights/actionGroups/<name>"
alarms_collector_image = "otel/opentelemetry-collector-contrib:<version>@sha256:<digest>"
}

The apply writes two secrets to the Key Vault, so the machine that applies needs its way in, as it does for the database URL. It creates the Application Insights resource and the five alerts, and gives each slot's app a new revision with the collector in it. examples/production is a whole deployment with them on.

What it creates​

  • A health token, generated by the module and written to the Key Vault secret pathways-health-token. It is generated by an ephemeral resource and written in a write-only argument, so neither the plan nor the state holds it, and no output gives it. The app gives it to the engine as PATHWAYS_HEALTH_TOKEN and to the collector, not to the migrate job. To change it, raise alarms_health_token_version by one, apply, and restart the app's revision, since both containers read it when a replica starts.
  • An Application Insights resource, appi-<name>, workspace-based on the module's Log Analytics workspace, and its connection string as the Key Vault secret pathways-metrics-connection-string, which only the collector reads. The connection string lets a caller send telemetry and read nothing; it is in the Terraform state, as an attribute of the resource.
  • The collector, a second container in each replica of each slot's app. Every 30 seconds it reads http://127.0.0.1:<alarms_health_port>/metrics with the token, keeps pathways_store_up, pathways_oldest_pending_age_seconds, pathways_queue_depth, pathways_messages_refused_total and, of pathways_settled_destinations_total, only the outcome failed, and drops every other metric. It folds away every channel, destination and outcome label (the minimum for store up, the maximum for the oldest pending age, the sum for the queue depth and the two counters), so no channel or destination name leaves the replica, and sends the two counters as what was added since the previous scrape. Its logs go to the workspace with the engine's.
  • Five metric alerts on those custom metrics, in the azure.applicationinsights namespace:
AlertFires whenIts input, and default
pathways-<name>-store-downno reading of pathways_store_up was 1 for that many minutesalarms_store_down_minutes, 5
pathways-<name>-oldest-pending-ageevery reading of the oldest delivery's wait, on any destination, was above that for 5 minutesalarms_oldest_pending_age_seconds, 600
pathways-<name>-queue-depthevery reading of the deliveries pending, over every destination, was above that for 5 minutesalarms_queue_depth_threshold, 1000
pathways-<name>-refused-messagesthe sources refused more bodies than that in 15 minutes, all channels togetheralarms_refused_messages_threshold, 0
pathways-<name>-settled-failedmore messages than that settled as failed with a destination in 15 minutesalarms_settled_failed_threshold, 0

What is not alarmed​

  • A stopped engine or collector. Azure does not fire a metric alert on missing data, so the store down alert fires only while the engine reports that it cannot read its database. When nothing reports, no alert fires. Our AWS module counts a missing minute as down; Azure Monitor's metric alerts cannot. A log search alert on the Application Insights data can, and costs more; this module does not create one.
  • A store down window of 2 minutes. Azure takes a metric alert's window only from a fixed list, so alarms_store_down_minutes is 1, 5, 15, 30 or 60, with 5 as the default.
  • Anything per channel or per destination. The labels are folded away before the metrics leave the replica. The engine's /metrics keeps every label, for a collector of your own.
  • The platform itself: replica restarts, the database server's own metrics, the Key Vault. Azure Monitor's platform metrics cover those, and this module sets no alert on them.

Before you rely on it​

The collector's configuration is checked by the module's tests as data. It has not yet been run against a live collector, engine and Application Insights resource. On the first apply, in a test subscription, check two things before you trust the alerts:

  • The metrics arrive. In the Application Insights resource, under Metrics, the namespace azure.applicationinsights must list the five pathways_ metrics within a few minutes of the new revision starting. If none arrives, the collector's lines in the workspace say why.
  • The values look right. pathways_store_up is 1 while the engine reads its database, and the counters grow only when a body is refused or a settlement fails.

What it costs​

We give what bills, not prices: Azure's pricing pages and your agreement with Microsoft set those.

WhatHow it bills while it runs
Five metric alert rulesper monitored time series per month; each rule watches one
The metrics' datathe rows Application Insights keeps in the workspace, per GB ingested and past the included retention: a few rows a minute per replica
The two Key Vault secretsper operation; each replica reads both when it starts
The collector's share of each replica0.25 vCPU and 0.5 GiB more per replica, which Container Apps bills as it does the engine
The action groupper notification it sends, for the receivers that bill, such as SMS

Keeping the channel and destination labels would make one series per channel or destination and outcome, and the bill grow with each; the module folds them away for that reason.

Turn it off​

Set alarms_enabled = false and apply. The alerts and the Application Insights resource are deleted, the two secrets are deleted into the vault's soft-delete retention, and each app goes back to the engine alone. Take the health: block out of your pathways.yaml too, or give it a token of your own: without PATHWAYS_HEALTH_TOKEN the engine does not start.