View as Markdown

Using Datadog with Mergify

Send your merge queue metrics to Datadog to build dashboards, alerts, and reports alongside the rest of your observability data.


The Datadog integration pushes your merge queue metrics into your own Datadog account. Everything on the merge queue statistics page is available as a Datadog metric, so you can graph queue health next to your own service metrics and alert on it.

It ships as a Mergify tile in Datadog’s integration catalog, and Mergify writes the metrics for you: there is no agent to install and nothing to run in your CI.

  • A Datadog account, and permission to authorize integrations and create API keys in it.

  • On the Mergify side, a plan that includes the Datadog integration, plus the GitHub organization Owner role or the Integrations Admin delegated role.

  1. Install the Mergify tile from Datadog’s integration catalog and click Connect Accounts. The connection starts on the Datadog side, so the Connect Your Datadog Account button on the dashboard’s Settings → Integrations → Datadog page opens Datadog’s catalog rather than connecting from Mergify.

    The Datadog integration in the Mergify dashboard's integrations list
  2. Authorize Mergify from the Datadog site your organization uses. Mergify supports US1, US3, US5, EU1, US1-FED, and AP1, and connects to whichever one you start from. Datadog then asks which GitHub organization to connect. Mergify creates an API key scoped to the integration and starts pushing metrics to that site.

  3. Choose what to monitor. For each repository, select the merge queue base branches you want metrics for: the branches your queued pull requests target, such as main or a release branch.

To switch the Datadog site your metrics go to, connect Mergify again from the site you want to move to. Reconnecting replaces the previous connection, whatever it was.

  1. Sign in to Datadog on the site you are moving to.

  2. In that account, install the Mergify tile and click Connect Accounts, exactly as you did when you first connected.

  3. Choose the same GitHub organization as before, and authorize Mergify.

The Datadog permissions in Prerequisites apply again, to the Datadog organization you move to. Metrics switch sites at the next publication. If you start the authorization and do not finish it, the previous connection stays in place.

What moves with you, and what does not

Section titled What moves with you, and what does not

Your monitored repositories and their base branches are preserved, so you do not select them again. What stays behind on the old site:

  • The metrics already sent there, and anything you built on them: Mergify publishes new points from the moment you reconnect, so recreate the dashboards and monitors on the new site.

  • The API key Mergify created. Reconnecting creates a new key on the new site and does not revoke the old one, so delete it yourself in the old Datadog organization once the switch is done.

To stop sending metrics without disconnecting anything, remove every repository from the integration page in the Mergify dashboard. Metrics only cover the repositories you select, so an empty list stops them. The connection and the API key stay in place, ready if you add a repository back.

To disconnect entirely, delete the API key Mergify created in your Datadog organization. Mergify checks that key every minute and drops the connection as soon as it stops working, so nothing is left behind on either side.

Every metric is published every 5 minutes, and each point covers the 5-minute window it represents. A metric with nothing to report for a window is left out of that publication rather than sent as a zero. Gaps are normal on a quiet queue, and a no-data monitor will fire on one.

Every metric carries these tags:

Tag Description
repository Full repository name, such as octo/hello-world
branch The base branch the queued pull requests target
queue Name of the queue rule
priority_rule Name of the matching priority rule, when set

priority_rule is the exception: running_checks.max, the two ci_runs.* metrics, bisection.red_steps and the two bisection.failure_first.* metrics never carry it.

Metrics submitted as count are event tallies that Datadog sums exactly over any time range. Metrics submitted as gauge are peak values within the window.

Metric Type Description
mergify.queue.entered count Pull requests that entered the queue
mergify.queue.merged count Pull requests merged out of the queue
mergify.queue.exit_reason count Pull requests that left the queue, tagged with exit_reason
mergify.queue.size.max gauge Largest the queue got
mergify.queue.running_checks.max gauge Most checks running at once
mergify.queue.check_outcome count Finished queue checks, tagged with outcome
mergify.queue.checks_retries.started count Retries the queue started
mergify.queue.checks_retries.passed count Retries whose run passed
mergify.queue.checks_retries.failed count Retries whose run failed again
mergify.queue.checks_retries.torn_down count Retries whose run ended before its checks concluded
mergify.queue.checks_retries.recovered count Deprecated, superseded by the four above
mergify.queue.checks_retries.not_recovered count Deprecated, superseded by the four above
mergify.queue.bisection.started count Batch bisections started
mergify.queue.bisection.red_steps count Bisection steps whose checks failed or timed out
mergify.queue.bisection.failure_first.stopped_early_red_steps count Red steps Fail First stopped early
mergify.queue.bisection.failure_first.test_time_saved count Estimated test time Fail First saved, in seconds
mergify.queue.merged_batches count Batches the queue merged
mergify.queue.skip_intermediate_results.batches_saved count Batches merged on a later batch’s pass
mergify.queue.skip_intermediate_results.batches_saved_during_speculative_checks count In speculative checks
mergify.queue.skip_intermediate_results.batches_saved_during_bisection count In a bisection
mergify.queue.skip_intermediate_results.eligible_batches count Batches the option would have merged while off
mergify.queue.skip_intermediate_results.eligible_batches_failed count Eligible batches whose own checks failed
mergify.queue.skip_intermediate_results.eligible_batches_aborted count Eligible batches cut short of a pass
mergify.queue.skip_intermediate_results.eligible_wait_time.sum count Time eligible batches waited, in seconds
mergify.queue.total_queue_time.sum count Total time queued, in seconds
mergify.queue.total_queue_time.count count Queue sessions the sum covers
mergify.queue.ci_runtime.sum count Total CI runtime, in seconds
mergify.queue.ci_runtime.count count CI runs the sum covers
mergify.queue.ci_runs.started count CI runs the queue started
mergify.queue.ci_runs.wasted count CI runs the queue threw away, tagged with reason
mergify.queue.batch_size.sum count Total pull requests across batches
mergify.queue.batch_size.count count Batches the sum covers
mergify.queue.breakdown.ci_runtime.sum count Queued time spent running CI, in seconds
mergify.queue.idle.capacity.sum count Queued time spent waiting for capacity, in seconds
mergify.queue.idle.schedule.sum count Queued time spent waiting for a schedule, in seconds
mergify.queue.idle.freeze.sum count Queued time waiting on a freeze, in seconds
mergify.queue.idle.count count Queue sessions the breakdown sums cover

Both outcome and exit_reason are success when the pull request merged or its checks passed. Otherwise they name the reason the pull request left the queue or its checks were aborted, such as checks_failed or pr_dequeued; the integration’s README lists every value. The reason on ci_runs.wasted is drawn from those same abort reasons and is never success.

A retry is one new run of a batch whose checks were retried, never counted per pull request. passed, failed and torn_down can add up to fewer than started, since a retry whose run has not ended has no outcome. Build new charts on those four rather than on the deprecated recovered and not_recovered, which are still published.

merged_batches counts every batch the queue merged, and skip_intermediate_results.batches_saved the ones among them that skip_intermediate_results merged on later batches’ passes, without their own checks having to pass. batches_saved only moves when the option is on. The two batches_saved_during_* metrics split those batches by where the skip happened, during speculative checks or during a bisection, and can sum to less than batches_saved.

The eligible_* metrics estimate, from the queue’s own history, what the option would have done where it is off, and are the figures the statistics page shows in place of the saved batches. eligible_batches counts the batches the option would have merged on later batches’ passes, each of which waited for its own CI run instead; eligible_batches_failed and eligible_batches_aborted split them by how that wait ended, and eligible_wait_time.sum is how long they waited in all, with eligible_batches as its count. None of them is sent while the option is on, nor in isolated mode, which does not support it.

The duration and size metrics ship as a .sum and a .count rather than a pre-computed average, so Datadog can recompute the real average over whatever time range you graph. Divide a family’s own sum by its own count:

sum:mergify.queue.total_queue_time.sum{$repository} / sum:mergify.queue.total_queue_time.count{$repository}

The same shape gives average CI runtime (mergify.queue.ci_runtime.*) and average batch size (mergify.queue.batch_size.*).

The share of retried runs that passed:

sum:mergify.queue.checks_retries.passed{$repository} / (sum:mergify.queue.checks_retries.passed{$repository} + sum:mergify.queue.checks_retries.failed{$repository})

A run torn down before its checks concluded is in neither term.

Share of batches merged on a later batch’s pass

Section titled Share of batches merged on a later batch’s pass

Mergify sends no share metric, since a per-window rate cannot be summed back over a longer range: derive it from the counts. Where skip_intermediate_results is on, divide the batches it merged on a later batch’s pass by every batch the queue merged:

sum:mergify.queue.skip_intermediate_results.batches_saved{$repository}.fill(zero) / sum:mergify.queue.merged_batches{$repository}

A batches_saved of zero is not sent at all: .fill(zero) keeps the windows without a saved batch at a share of zero.

Where the option is off, the share it would have had is out of every batch the queue would have merged with it on, meaning the batches the queue merged plus the eligible batches that did not merge as they were:

sum:mergify.queue.skip_intermediate_results.eligible_batches{$repository} / (sum:mergify.queue.merged_batches{$repository} + sum:mergify.queue.skip_intermediate_results.eligible_batches_aborted{$repository})

Read that share as an estimate: it can read low, or above 1. The statistics page keeps its own share at or under 100%.

Share of red bisection steps stopped early

Section titled Share of red bisection steps stopped early

A bisection step is one part of a split batch, checked on top of the parts before it. bisection.red_steps counts the bisection steps whose checks failed or timed out, and failure_first.stopped_early_red_steps the ones stopped early by a test Fail First ran first:

sum:mergify.queue.bisection.failure_first.stopped_early_red_steps{$repository} / sum:mergify.queue.bisection.red_steps{$repository}

On a queue where Fail First served no step, neither that metric nor failure_first.test_time_saved is sent: a missing series means the queue is not using Fail First, not that it saved nothing.

Total queued time splits into CI runtime plus three kinds of waiting:

mergify.queue.breakdown.ci_runtime.sum # running CI
mergify.queue.idle.capacity.sum # waiting for a free check slot
mergify.queue.idle.schedule.sum # waiting for a schedule to open
mergify.queue.idle.freeze.sum # waiting for a freeze to lift

Divide any of them by mergify.queue.idle.count for a per-pull-request average. The three idle.* metrics are pure waiting time, so sum:mergify.queue.idle.*.sum is total wasted time without CI.

The Mergify - Merge Queue Stats dashboard in Datadog

The Mergify tile ships a Mergify - Merge Queue Stats dashboard that mirrors the merge queue statistics page. In Datadog, search for mergify in your account’s integration catalog, open the Mergify tile, and find the dashboard under the Monitoring Resources tab. Clone it to adapt it to your own repositories, or build your own from the metrics above.

Since the metrics are ordinary Datadog metrics, you can alert on them with monitors. Useful ones to start with:

  • mergify.queue.size.max staying above a threshold, which usually means CI capacity is the bottleneck.

  • Average queued time trending up week over week.

  • Retry pass rate dropping, which points at genuinely broken tests rather than flaky ones.

  • mergify.queue.exit_reason counting anything other than success, which means pull requests are leaving the queue without merging.

Was this page helpful?