Skip to content

[build] Add weekly CI check for Plausible pageview usage - #17900

Open
titusfortner wants to merge 1 commit into
trunkfrom
plausible-usage-check
Open

titusfortner wants to merge 1 commit into
trunkfrom
plausible-usage-check

Conversation

@titusfortner

Copy link
Copy Markdown
Member

🔗 Related Issues

Related to #17881

💥 What does this PR do?

  • Gets Selenium Manager telemetry for the previous week to see if the page views are outside our expected range
  • Posts to selenium-tlc for us to investigate for suspicious profiles.
  • Runs Wednesday mornings, and can be triggered on demand from the Actions tab.

🔧 Implementation Notes

  • Queries a fixed seven-day window (yesterday back six days) rather than Plausible's period=7d, which folds in today's partial data and makes the number depend on what time the job runs.
  • The budget is 17M/week against a 75M/month plan limit. Current volume is ~128M/week, so this job will fail every run until telemetry drops.

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): Claude Code
    • What was generated: the workflow and the shell script
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

  • Follow-up: five workflows now inline the same Slack notification block, which could move to a shared composite action.

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Add weekly GitHub Actions check for Plausible pageview overage + Slack alert

✨ Enhancement ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Add scheduled + manual GitHub Actions workflow to monitor weekly Plausible pageviews.
• Query a fixed 7-day completed window to avoid partial-day noise.
• Fail the job and notify selenium-tlc in Slack when usage exceeds budget.
Diagram

graph TD
  W["GitHub Actions workflow"] --> S["Usage check script"] --> P{{"Plausible API"}} --> D{"Over budget?"}
  D -->|"no"| OK["Pass / record outputs"]
  D -->|"yes"| N{{"Slack notify (selenium-tlc)"}}

  subgraph Legend
    direction LR
    _int["Internal step"] ~~~ _dec{"Decision"} ~~~ _ext{{"External system"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reusable workflow or composite action for Slack notifications
  • ➕ Deduplicates the repeated Slack notification block across multiple workflows
  • ➕ Centralizes Slack formatting/channel logic and secret handling
  • ➕ Easier to roll out future notification changes consistently
  • ➖ Adds an extra abstraction to maintain/version
  • ➖ Requires small refactors across existing workflows to adopt it
2. Implement the check as a small Node/Python action instead of bash
  • ➕ More robust JSON parsing and error handling than shell + jq
  • ➕ Easier unit testing of date-window and threshold calculations
  • ➖ More code/runtime setup than a single script
  • ➖ Adds language runtime/tooling maintenance for a simple check
3. Use Plausible built-in periods with a guard for partial-day data
  • ➕ Simplifies the API parameters and date math
  • ➕ Less platform-dependent date handling
  • ➖ Still needs logic to avoid/compensate for partial current-day data
  • ➖ Makes results time-of-day dependent unless carefully normalized

Recommendation: The PR’s approach (a minimal workflow + bash script using a fixed completed 7-day window) is appropriate for a lightweight budget guardrail and avoids partial-day variance. The main improvement worth considering is extracting the Slack notification into a shared reusable workflow/composite action to reduce duplication across workflows.

Files changed (2) +135 / -0

Enhancement (1) +101 / -0
check-plausible-usage.shAdd script to query last 7 full days of Plausible pageviews and enforce threshold +101/-0

Add script to query last 7 full days of Plausible pageviews and enforce threshold

• Adds a bash script that queries Plausible’s aggregate stats for a fixed custom date range (yesterday back six days) and extracts 'pageviews'. Computes budget deltas and a monthly pace estimate, writes GitHub outputs/summary, and exits non-zero when the weekly threshold is exceeded to trigger alerting.

scripts/github-actions/check-plausible-usage.sh

Other (1) +34 / -0
plausible-usage.ymlAdd scheduled Plausible usage workflow with Slack-on-failure alert +34/-0

Add scheduled Plausible usage workflow with Slack-on-failure alert

• Introduces a GitHub Actions workflow that runs weekly (Wednesday) and supports manual dispatch. Executes the Plausible usage check script with a stats API key and sends a Slack notification to 'selenium-tlc' when the job fails.

.github/workflows/plausible-usage.yml

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. No tests for Plausible script 📘 Rule violation ☼ Reliability
Description
This PR adds a new weekly CI check with non-trivial parsing and budget/threshold calculations, but
introduces no test coverage to validate behavior across success/error responses. Lacking tests makes
the workflow brittle and increases the chance of silent regressions in monitoring/alerting logic.
Code

scripts/github-actions/check-plausible-usage.sh[R60-63]

+pageviews="$(jq -r '.results.pageviews.value // empty' <<<"$body" 2>/dev/null || true)"
+
+if [[ ! "$pageviews" =~ ^[0-9]+$ ]]; then
+  echo "::error::No pageviews value in the Plausible response"
Evidence
PR Compliance ID 4 requires new behavior to be covered by tests where practical. The added script
contains new parsing and calculation logic that drives CI failures/Slack alerts, but the PR adds
only the workflow and script with no test additions in the diff.

AGENTS.md: Testing standards: prefer unit tests, write tests early, and avoid mocks
scripts/github-actions/check-plausible-usage.sh[60-101]
.github/workflows/plausible-usage.yml[19-34]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new Plausible usage check script adds behavior (API response parsing and threshold/budget calculations) without any accompanying tests.

## Issue Context
Compliance requires new behavior to be covered by tests where practical, preferring small/unit tests. For this script, you can make the core logic testable without hitting the real Plausible API by isolating calculation/parsing into functions and feeding representative sample JSON inputs.

## Fix Focus Areas
- scripts/github-actions/check-plausible-usage.sh[60-101]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Curl request can hang 🐞 Bug ☼ Reliability
Description
check-plausible-usage.sh calls Plausible via curl without any connection/overall timeout, so a
stalled network request can block the scheduled workflow until GitHub’s job timeout and
delay/prevent the Slack alert.
Code

scripts/github-actions/check-plausible-usage.sh[R39-42]

+if ! response="$(curl --silent --show-error --write-out '\n%{http_code}' \
+  --get "https://plausible.io/api/v1/stats/aggregate" \
+  --header "Authorization: Bearer ${PLAUSIBLE_STATS_KEY}" \
+  --data-urlencode "site_id=${SITE_ID}" \
Evidence
The script’s only Plausible call is a plain curl invocation with no timeout flags, and it’s run by a
scheduled workflow, so the weekly check can block for an unbounded amount of time at the script
level.

scripts/github-actions/check-plausible-usage.sh[37-48]
.github/workflows/plausible-usage.yml[1-6]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The Plausible API request uses `curl` without `--connect-timeout` and `--max-time` (and optionally retries). A hung TCP/TLS connection or slow upstream can stall the whole workflow run.

### Issue Context
This script is executed by a weekly scheduled workflow; the job only notifies Slack on failure, so a hung request delays the alert.

### Fix Focus Areas
- scripts/github-actions/check-plausible-usage.sh[39-45]
- .github/workflows/plausible-usage.yml[1-6]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Unvalidated numeric overrides 🐞 Bug ≡ Correctness
Description
PLAUSIBLE_THRESHOLD and PLAUSIBLE_MONTHLY_LIMIT are documented as overridable but never validated as
numeric; invalid values can be coerced (e.g., to 0) or trigger arithmetic/awk errors, causing
incorrect over/under decisions or confusing failures.
Code

scripts/github-actions/check-plausible-usage.sh[R14-16]

+SITE_ID="${PLAUSIBLE_SITE_ID:-manager.selenium.dev}"
+THRESHOLD="${PLAUSIBLE_THRESHOLD:-17000000}"
+MONTHLY_LIMIT="${PLAUSIBLE_MONTHLY_LIMIT:-75000000}"
Evidence
The script reads threshold/limit from environment and later uses THRESHOLD in arithmetic and
percent calculation; only pageviews is validated as numeric.

scripts/github-actions/check-plausible-usage.sh[14-16]
scripts/github-actions/check-plausible-usage.sh[60-76]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`PLAUSIBLE_THRESHOLD` / `PLAUSIBLE_MONTHLY_LIMIT` are treated as numbers but are not validated before use. In bash arithmetic and awk, malformed values may be coerced or error out, leading to false alerts or hard-to-debug failures.

### Issue Context
The script already validates `pageviews` is numeric, but not the user-supplied numeric configuration.

### Fix Focus Areas
- scripts/github-actions/check-plausible-usage.sh[14-16]
- scripts/github-actions/check-plausible-usage.sh[62-76]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +60 to +63
pageviews="$(jq -r '.results.pageviews.value // empty' <<<"$body" 2>/dev/null || true)"

if [[ ! "$pageviews" =~ ^[0-9]+$ ]]; then
echo "::error::No pageviews value in the Plausible response"

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.

Remediation recommended

1. No tests for plausible script 📘 Rule violation ☼ Reliability

This PR adds a new weekly CI check with non-trivial parsing and budget/threshold calculations, but
introduces no test coverage to validate behavior across success/error responses. Lacking tests makes
the workflow brittle and increases the chance of silent regressions in monitoring/alerting logic.
Agent Prompt
## Issue description
The new Plausible usage check script adds behavior (API response parsing and threshold/budget calculations) without any accompanying tests.

## Issue Context
Compliance requires new behavior to be covered by tests where practical, preferring small/unit tests. For this script, you can make the core logic testable without hitting the real Plausible API by isolating calculation/parsing into functions and feeding representative sample JSON inputs.

## Fix Focus Areas
- scripts/github-actions/check-plausible-usage.sh[60-101]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +39 to +42
if ! response="$(curl --silent --show-error --write-out '\n%{http_code}' \
--get "https://plausible.io/api/v1/stats/aggregate" \
--header "Authorization: Bearer ${PLAUSIBLE_STATS_KEY}" \
--data-urlencode "site_id=${SITE_ID}" \

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.

Remediation recommended

2. Curl request can hang 🐞 Bug ☼ Reliability

check-plausible-usage.sh calls Plausible via curl without any connection/overall timeout, so a
stalled network request can block the scheduled workflow until GitHub’s job timeout and
delay/prevent the Slack alert.
Agent Prompt
### Issue description
The Plausible API request uses `curl` without `--connect-timeout` and `--max-time` (and optionally retries). A hung TCP/TLS connection or slow upstream can stall the whole workflow run.

### Issue Context
This script is executed by a weekly scheduled workflow; the job only notifies Slack on failure, so a hung request delays the alert.

### Fix Focus Areas
- scripts/github-actions/check-plausible-usage.sh[39-45]
- .github/workflows/plausible-usage.yml[1-6]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +14 to +16
SITE_ID="${PLAUSIBLE_SITE_ID:-manager.selenium.dev}"
THRESHOLD="${PLAUSIBLE_THRESHOLD:-17000000}"
MONTHLY_LIMIT="${PLAUSIBLE_MONTHLY_LIMIT:-75000000}"

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.

Informational

3. Unvalidated numeric overrides 🐞 Bug ≡ Correctness

PLAUSIBLE_THRESHOLD and PLAUSIBLE_MONTHLY_LIMIT are documented as overridable but never validated as
numeric; invalid values can be coerced (e.g., to 0) or trigger arithmetic/awk errors, causing
incorrect over/under decisions or confusing failures.
Agent Prompt
### Issue description
`PLAUSIBLE_THRESHOLD` / `PLAUSIBLE_MONTHLY_LIMIT` are treated as numbers but are not validated before use. In bash arithmetic and awk, malformed values may be coerced or error out, leading to false alerts or hard-to-debug failures.

### Issue Context
The script already validates `pageviews` is numeric, but not the user-supplied numeric configuration.

### Fix Focus Areas
- scripts/github-actions/check-plausible-usage.sh[14-16]
- scripts/github-actions/check-plausible-usage.sh[62-76]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@selenium-ci selenium-ci added the B-build Includes scripting, bazel and CI integrations label Aug 11, 2026

This branch has not been deployed

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

Labels

B-build Includes scripting, bazel and CI integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants