Skip to content

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

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

[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
Screenshot 2026-07-03 at 2 32 52 PM Screenshot 2026-07-03 at 2 32 57 PM

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

ENG-23097

@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.69%. Comparing base (f37a747) to head (bc4056b).

Additional details and impacted files
@@                           Coverage Diff                           @@
##           gwdp/eng-21551-posthog-flag-rollout    #3945      +/-   ##
=======================================================================
+ Coverage                                59.63%   59.69%   +0.06%     
=======================================================================
  Files                                      941      942       +1     
  Lines                                    41498    41555      +57     
  Branches                                  8746     8757      +11     
=======================================================================
+ Hits                                     24745    24802      +57     
  Misses                                   16659    16659              
  Partials                                    94       94              

☔ 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 2 times, most recently from 25c9c2e to 541170a Compare July 3, 2026 17:14
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 3745235 to e006085 Compare July 3, 2026 17:14

gwdp commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 541170a to 0040a80 Compare July 3, 2026 18:52
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from e006085 to 021c85f Compare July 3, 2026 18:52
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 0040a80 to 8d13771 Compare July 3, 2026 20:42
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch 2 times, most recently from a8e1b57 to f630079 Compare July 3, 2026 21:40
@gwdp gwdp requested a review from sjchmiela July 3, 2026 21:43
@gwdp gwdp marked this pull request as ready for review July 3, 2026 21:43
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Subscribed to pull request

File Patterns Mentions
**/* @douglowder

Generated by CodeMention

Warning: The preamble and epilogue options in commentConfiguration are deprecated. Use template instead.

@sjchmiela sjchmiela left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it would be even cooler if we could do it not-from-a-VM (type: posthog-wait-for-metric) and poll from a background job

Comment thread packages/build-tools/src/steps/utils/posthog.ts Outdated
Comment thread packages/build-tools/src/steps/functions/waitForPostHogMetric.ts Outdated
Comment thread packages/build-tools/src/steps/functions/waitForPostHogMetric.ts Outdated
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 021c85f to 7d5471d Compare July 6, 2026 19:51
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from f630079 to 28718f6 Compare July 6, 2026 19:51
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from 7d5471d to 2a9777a Compare July 6, 2026 20:40
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 28718f6 to 6e72fed Compare July 6, 2026 20:40
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 6e72fed to 2755d8a Compare July 6, 2026 21:59
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch 2 times, most recently from 05251fe to 84eab00 Compare July 6, 2026 22:21
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch 2 times, most recently from 58cfdcf to 9d6b3f4 Compare July 6, 2026 22:54
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch 2 times, most recently from 21a614d to c84289b Compare July 6, 2026 23:35
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch 2 times, most recently from 01a7642 to 9a9a276 Compare July 6, 2026 23:50

gwdp commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

i guess it would be even cooler if we could do it not-from-a-VM (type: posthog-wait-for-metric) and poll from a background job

Tysm for the idea, it would be even cooler, tracking it under ENG-23097 as a follow-up

@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-flag-rollout branch from c84289b to f37a747 Compare July 7, 2026 23:43
@gwdp gwdp force-pushed the gwdp/eng-21551-posthog-wait-for-metric branch from 9a9a276 to bc4056b Compare July 7, 2026 23:43
@github-actions

github-actions Bot commented Jul 7, 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.

2 participants