Skip to content

[build-tools] Add eas/posthog_wait_for_metric workflow function#3945

Draft
gwdp wants to merge 1 commit into
gwdp/eng-21551-posthog-flag-rolloutfrom
gwdp/eng-21551-posthog-wait-for-metric
Draft

[build-tools] Add eas/posthog_wait_for_metric workflow function#3945
gwdp wants to merge 1 commit into
gwdp/eng-21551-posthog-flag-rolloutfrom
gwdp/eng-21551-posthog-wait-for-metric

Conversation

@gwdp

@gwdp gwdp commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Why

Gate an EAS workflow on a PostHog metric. Hold a rollout until errors stay low (or any metric clears) before it continues, instead of watching dashboards by hand. imo this is the coolest 🔥

How

Adds eas/posthog_wait_for_metric. It polls a HogQL query until operator/threshold is met, every interval_seconds (default 30) for up to timeout_seconds (default 600). Auth is the same personal key as the flag step, and the key needs the query read scope. (good docs coming)

It also sets a value output with the query result that met the threshold, so a later step can use ${{ steps.<step id>.outputs.value }}.

There's no ignore_error here on purpose. It's a gate, so timing out fails the step. Network errors, 429 and 5xx retry until the deadline. Auth and query errors fail right away.

Test Plan

CI passes. Test workflow below. The second and third jobs fail on purpose (timeout and bad query shape). Not live-run yet, since the key from connect lacks the query scope. Will run it before undrafting.

Test workflow
name: PostHog wait-for-metric test

jobs:
  wait_cleared:
    steps:
      - uses: eas/posthog_wait_for_metric
        with:
          query: select count() from events
          operator: gte
          threshold: 0

  wait_timeout:
    steps:
      - uses: eas/posthog_wait_for_metric
        with:
          query: select count() from events
          operator: lt
          threshold: 0
          interval_seconds: 5
          timeout_seconds: 20

  wait_bad_query:
    steps:
      - uses: eas/posthog_wait_for_metric
        with:
          query: select event from events limit 1
          operator: gte
          threshold: 0
          interval_seconds: 5
          timeout_seconds: 15

Examples

These are simple workflows just to exercise the step. More fun and useful ones, mixed with EAS Update and deploys, are coming in the docs.

Send an event and wait for it

Two jobs with no needs, so they run at the same time. One sends the event, the other waits for it to land. This needs real concurrency. It won't clear on a local runner set to concurrency 1, since the jobs run one after another there.

name: Send an event and await it in parallel

jobs:
  send_ping:
    steps:
      - uses: eas/posthog_capture_event
        with:
          event: workflow_ping
          properties:
            source: parallel-demo

  await_ping:
    steps:
      - uses: eas/posthog_wait_for_metric
        with:
          query: select count() from events where event = 'workflow_ping' and timestamp > now() - interval 5 minute
          operator: gte
          threshold: 1
          interval_seconds: 10
          timeout_seconds: 300
Use the metric value in a later step

The gate exposes the reading it settled on as an output. A later step reads it with ${{ steps.gate.outputs.value }}.

name: Gate on a metric, then use its value

jobs:
  gated_announce:
    steps:
      - id: gate
        uses: eas/posthog_wait_for_metric
        with:
          query: select count() from events where event = '$exception' and timestamp > now() - interval 1 hour
          operator: lte
          threshold: 5
      - uses: eas/posthog_capture_event
        with:
          event: rollout_gate_cleared
          properties:
            error_count: ${{ steps.gate.outputs.value }}

@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

ENG-21551

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from c50c7ce to 4f8d88f Compare July 3, 2026 06:48
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 00debc7 to 5b641eb Compare July 3, 2026 06:48
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.40%. Comparing base (3745235) to head (25c9c2e).

Additional details and impacted files
@@                           Coverage Diff                           @@
##           gwdp/eng-21551-posthog-flag-rollout    #3945      +/-   ##
=======================================================================
+ Coverage                                59.33%   59.40%   +0.08%     
=======================================================================
  Files                                      938      939       +1     
  Lines                                    41223    41296      +73     
  Branches                                  8685     8699      +14     
=======================================================================
+ Hits                                     24454    24527      +73     
  Misses                                   16674    16674              
  Partials                                    95       95              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 5b641eb to 63af5cf Compare July 3, 2026 07:11
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 4f8d88f to 17c3b91 Compare July 3, 2026 07:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 63af5cf to 55545d5 Compare July 3, 2026 07:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 17c3b91 to 3745235 Compare July 3, 2026 07:40
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 55545d5 to 25c9c2e Compare July 3, 2026 07:40
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

✅ Thank you for adding the changelog entry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant