Skip to content

observability-diff: scope PR comment to files the PR actually changes#4711

Merged
lukemelia merged 2 commits intomainfrom
fix/observability-diff-only-pr-changed-files
May 7, 2026
Merged

observability-diff: scope PR comment to files the PR actually changes#4711
lukemelia merged 2 commits intomainfrom
fix/observability-diff-only-pr-changed-files

Conversation

@lukemelia
Copy link
Copy Markdown
Contributor

@lukemelia lukemelia commented May 7, 2026

Summary

The observability-diff PR comment workflow currently shows total drift between main + this PR and live staging Grafana. That includes drift from earlier merges that haven't reached staging, manual UI edits in staging, AMG-era residue, etc. — most of which has nothing to do with the PR being reviewed and adds noise.

This PR scopes the diff to only the dashboard/folder files that changed in the PR, so the comment reflects what would happen on apply of this PR, not accumulated drift.

Mechanism

  • New diff.sh --only-changed-since=<ref> flag. When set, runs git diff --name-only <ref>...HEAD -- packages/observability/grafanactl/resources/ and only includes those files in the canonicalize + diff pipeline.
  • If no PR-relevant paths changed, diff.sh exits 0 with empty stdout (skipping the expensive grafanactl pull). The workflow's comment step then renders the existing "No dashboard / folder changes detected" body.
  • The workflow passes origin/${{ github.event.pull_request.base.ref }} so the comparison is against the PR's actual target branch.
  • actions/checkout gains fetch-depth: 0 so origin/<base>...HEAD has both refs available (default fetch-depth: 1 only fetches HEAD).

Implementation notes

  • Filter is stored as a newline-separated string + [[ "$line" == "$key" ]] scan, not declare -A, for bash 3.2 compatibility — same constraint the rest of the script already honors (see the find -print0 pattern comments throughout).
  • The filter check is applied in both normalize() (per-folder layout) and normalize_json_content() (jq canonicalization) so unrelated files never reach the final git diff --no-index.
  • No filter (default behavior, ad-hoc local invocation) preserves the original "diff everything" behavior.

Effect on the existing stack

For the open dashboard PRs (#4694#4699):

PR Files in grafanactl/resources/ Expected comment
#4694 (Loki/Alloy infra) none "No dashboard / folder changes detected"
#4695 (job_id correlation) none "No dashboard / folder changes detected"
#4696 (tag dashboards + Logs vars) boxel-logs.json, synapse.json only those two files' diffs
#4697 (split Boxel Jobs) indexing.json, job-queue.json, deletion of boxel-jobs.json only those
#4698 (Realms + Users) the 4 entity dashboards only those
#4699 (Overview + service stubs) the 5 new dashboards, deletion of worker-status.json only those

Right now every one of those PRs gets the same multi-thousand-line diff dominated by drift unrelated to the PR. After this lands, each comment will be tightly scoped.

Test plan

  • Locally: ./scripts/diff.sh --env staging --only-changed-since=origin/main (requires AWS access for SSM token) — verify scope is just files changed since main.
  • Locally: ./scripts/diff.sh --env staging --only-changed-since=<ref-with-no-observability-changes> — verify exits 0 with empty stdout, no grafanactl pull happened.
  • CI: open any PR touching observability infra (not dashboards) — comment should say "No dashboard / folder changes detected".
  • CI: open a PR modifying one dashboard — comment should show only that dashboard's diff.

🤖 Generated with Claude Code

@lukemelia lukemelia requested a review from Copilot May 7, 2026 16:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Observability diff (vs staging)

No dashboard / folder changes detected against the staging Grafana.

(Run: https://github.com/cardstack/boxel/actions/runs/25511601796)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Scopes the “observability diff vs staging” PR comment to only the Grafana dashboard/folder manifests that are changed by the current PR, reducing noise from unrelated drift in staging.

Changes:

  • Add diff.sh --only-changed-since=<ref> to filter diffs to only files changed under packages/observability/grafanactl/resources/, with an early exit when no relevant changes exist.
  • Update the observability-diff GitHub Actions workflow to use the new flag and to fetch full git history.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/observability/scripts/diff.sh Adds --only-changed-since filtering logic and applies it during normalization/canonicalization steps.
.github/workflows/observability-diff.yml Uses fetch-depth: 0 and passes --only-changed-since=origin/<base> to scope the generated PR comment diff.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/observability-diff.yml
Comment thread packages/observability/scripts/diff.sh
Comment thread packages/observability/scripts/diff.sh
Comment thread packages/observability/scripts/diff.sh
lukemelia added a commit that referenced this pull request May 7, 2026
Four follow-ups from Copilot's review:

* Document `--only-changed-since` in diff.sh's header Usage block,
  including the empty-stdout semantics and the deletion-exclusion
  rationale.

* Validate the ref via `git rev-parse --verify` before using it.
  CI usually passes `origin/<base-ref>` and a missing/invalid ref
  used to surface as a noisy `git diff` failure under set -e;
  now diff.sh emits an actionable error pointing at the workflow's
  fetch step.

* `git diff --name-only --diff-filter=ACMRT` excludes Deletions
  from the filter set. `grafanactl push` is upsert-only and never
  deletes, so a deletion-only PR is a no-op for live state — should
  short-circuit to empty stdout, not trigger a `grafanactl pull`.

* Workflow: explicit `git fetch --no-tags --depth=1 origin "${PR_BASE_REF}"`
  before running diff.sh. Belt-and-suspenders even with
  `fetch-depth: 0` — actions/checkout's behavior with PR base refs
  isn't 100% guaranteed across runner image versions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lukemelia lukemelia force-pushed the fix/observability-diff-only-pr-changed-files branch from a1c9df2 to 529a1fd Compare May 7, 2026 16:54
@lukemelia lukemelia marked this pull request as ready for review May 7, 2026 16:56
@lukemelia lukemelia requested review from a team and habdelra May 7, 2026 16:56
The PR comment workflow (observability-diff.yml) runs diff.sh in "diff
everything" mode, which surfaces total drift between main + this PR
and live staging Grafana. That includes drift caused by earlier merges
that haven't reached staging yet, manual UI edits in staging, etc. —
none of which belong in the PR comment because the PR didn't change
those files.

Adds `diff.sh --only-changed-since=<ref>` to scope the diff to files
that changed in `git diff --name-only <ref>...HEAD` under
`packages/observability/grafanactl/resources/`. The workflow passes
the PR's base branch (`origin/<base.ref>`) so the comment shows what
THIS PR would change on apply, not accumulated drift.

If no observability dashboards/folders changed in the PR, diff.sh
exits 0 with empty stdout — the comment step renders the existing
"No dashboard / folder changes detected" body. Avoids both the
expensive grafanactl pull AND the noisy comment.

Implementation notes:
* Filter list is a newline-separated string (not an associative array)
  for bash 3.2 compatibility — same constraint the rest of this
  script already honors for `find -print0` patterns.
* `actions/checkout` gains `fetch-depth: 0` so `git diff origin/<base>...HEAD`
  has both refs available; default fetch-depth: 1 gives only HEAD.
* The filter is applied in both `normalize()` (which copies pulled
  files into the per-folder layout) and `normalize_json_content()`
  (which canonicalizes both sides). Files outside the filter are
  silently skipped at both stages so they never reach the final
  `git diff --no-index`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lukemelia added a commit that referenced this pull request May 7, 2026
Four follow-ups from Copilot's review:

* Document `--only-changed-since` in diff.sh's header Usage block,
  including the empty-stdout semantics and the deletion-exclusion
  rationale.

* Validate the ref via `git rev-parse --verify` before using it.
  CI usually passes `origin/<base-ref>` and a missing/invalid ref
  used to surface as a noisy `git diff` failure under set -e;
  now diff.sh emits an actionable error pointing at the workflow's
  fetch step.

* `git diff --name-only --diff-filter=ACMRT` excludes Deletions
  from the filter set. `grafanactl push` is upsert-only and never
  deletes, so a deletion-only PR is a no-op for live state — should
  short-circuit to empty stdout, not trigger a `grafanactl pull`.

* Workflow: explicit `git fetch --no-tags --depth=1 origin "${PR_BASE_REF}"`
  before running diff.sh. Belt-and-suspenders even with
  `fetch-depth: 0` — actions/checkout's behavior with PR base refs
  isn't 100% guaranteed across runner image versions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lukemelia lukemelia force-pushed the fix/observability-diff-only-pr-changed-files branch from 529a1fd to 237b46a Compare May 7, 2026 17:27
Four follow-ups from Copilot's review:

* Document `--only-changed-since` in diff.sh's header Usage block,
  including the empty-stdout semantics and the deletion-exclusion
  rationale.

* Validate the ref via `git rev-parse --verify` before using it.
  CI usually passes `origin/<base-ref>` and a missing/invalid ref
  used to surface as a noisy `git diff` failure under set -e;
  now diff.sh emits an actionable error pointing at the workflow's
  fetch step.

* `git diff --name-only --diff-filter=ACMRT` excludes Deletions
  from the filter set. `grafanactl push` is upsert-only and never
  deletes, so a deletion-only PR is a no-op for live state — should
  short-circuit to empty stdout, not trigger a `grafanactl pull`.

* Workflow: explicit `git fetch --no-tags --depth=1 origin "${PR_BASE_REF}"`
  before running diff.sh. Belt-and-suspenders even with
  `fetch-depth: 0` — actions/checkout's behavior with PR base refs
  isn't 100% guaranteed across runner image versions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lukemelia lukemelia force-pushed the fix/observability-diff-only-pr-changed-files branch from 237b46a to 064a2be Compare May 7, 2026 17:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Host Test Results

    1 files      1 suites   1h 47m 19s ⏱️
2 634 tests 2 619 ✅ 15 💤 0 ❌
2 653 runs  2 638 ✅ 15 💤 0 ❌

Results for commit 064a2be.

Realm Server Test Results

    1 files      1 suites   17m 10s ⏱️
1 262 tests 1 262 ✅ 0 💤 0 ❌
1 340 runs  1 340 ✅ 0 💤 0 ❌

Results for commit 064a2be.

@lukemelia lukemelia merged commit 9bb8213 into main May 7, 2026
70 checks passed
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.

3 participants