Skip to content

fix(url): update scenes, remove json and line filter from service url#1977

Open
L2D2Grafana wants to merge 8 commits into
mainfrom
l2d22/1976-errors-stuck-in-urls
Open

fix(url): update scenes, remove json and line filter from service url#1977
L2D2Grafana wants to merge 8 commits into
mainfrom
l2d22/1976-errors-stuck-in-urls

Conversation

@L2D2Grafana

@L2D2Grafana L2D2Grafana commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary 📝

Fixes #1976 — clicking "Show logs" on the service-selection page failed on the first attempt but worked after a page refresh.

Drilldown-only URL params (var-jsonFields / var-lineFormat) were being left in the URL on the service-selection page. On the first "Show logs" click they interpolated a malformed detected_fields query (| json trueundefined"", | line_format "{{.true}}"), surfacing a JSON.parse: unexpected end of data / parse error until a hard refresh cleared the state.

What changed 🔧

Core fix

  • Add SERVICE_URL_EXCLUDED_KEYS (var-jsonFields, var-lineFormat) and filter them out of the service URL in buildServicesRoutesrc/services/routing.ts.
  • On IndexScene activation (when not embedded and on the service-selection page), scrub any stuck excluded keys by replacing the location with a clean explore URL — src/Components/IndexScene/IndexScene.tsx.
  • resetVariablesIfNotInUrl now also clears lineFilters / jsonFields / lineFormat, and treats an empty param (e.g. var-jsonFields=) as "absent". SceneAppPage caches scenes by pathname (not query string), so re-entering a cached scene could keep stale variable values while the URL says empty — this re-syncs them.

Dependencies

  • Bump @grafana/scenes and @grafana/scenes-react from 7.4.28.9.0.
  • Bump pnpm 11.8.011.9.0. ⚠️ This reformatted the entire pnpm-lock.yaml (every resolution: / engines: entry), which accounts for the very large lockfile diff — the only functional dependency change is the scenes bump.

Tests 🧪

  • Unitsrc/services/routing.test.ts: asserts buildServicesUrl(ROUTES.explore()) drops var-jsonFields / var-lineFormat.
  • E2E (new)tests/invalidUrl.spec.ts: landing directly on a URL carrying invalid jsonFields / lineFormat now loads the logs view without a parse error.
  • E2E (Grafana 13.1 compatibility) — these suites run only on the latest Grafana (skipUnlessLatestGrafana) and needed updating for current behavior:
    • exploreServices.spec.tsshould add labels to favorites: returning to service selection now resets the search, so we assert the search is cleared rather than clicking a clear button that is no longer present.
    • exploreServices.spec.tsnavigating back will re-run volume query: simplified to track logsVolumeCount (1 → 2 → 3), which is what the test title verifies. Dropped the flaky logsQueryCount upper-bound checks — that count races async panel rendering, and the panel-query count is already covered by the sibling refreshing time range test.
    • jsonView.spec.tscan share link to log line: assert the restored row's data-scrolled / aria-expanded attributes instead of a toBeInViewport() geometry check, which is unreliable for the tall expanded row in the short default viewport.

Manual verification

  • Fresh "Show logs" from Drilldown → Logs (no filters) produces a well-formed detected_fields request (no trueundefined / duplicate | json) and loads without the JSON.parse error.
  • Landing on the service-selection page with var-jsonFields / var-lineFormat in the URL strips them (URL replaced with a clean explore URL) without breaking back/forward navigation.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Changes

Hello! 👋 This comment was generated by a Github Action to help you and reviewers understand the impact of your PR on frontend bundle sizes.

Great job! Bundle size increase of 0% is now below threshold of 5%.

Whenever this PR is updated, this comment will update to reflect the latest changes.

@L2D2Grafana L2D2Grafana force-pushed the l2d22/1976-errors-stuck-in-urls branch from 303bc18 to 09e16fd Compare June 29, 2026 20:13
L2D2Grafana and others added 4 commits July 1, 2026 12:11
…e scene

SceneAppPage caches the drilldown scene by pathname (ignoring the query
string), so navigating away from a service and back re-shows the cached
scene with its original variable state. Stale jsonFields/lineFormat values
left in that cached scene leaked into the query (`| json trueundefined""`,
`| line_format "{{.true}}"`), producing a malformed query (#1976).

resetVariablesIfNotInUrl now also covers jsonFields, lineFormat and
lineFilters, and treats an absent OR empty URL param as "no filters" (the
re-show URL has e.g. `var-jsonFields=` present-but-empty), so re-entry
re-syncs the stale cached variables to the URL. On a fresh URL load
AdHocFiltersVariable already drops the invalid filter on parse, so the two
paths together keep the query well-formed.

Adds an e2e test asserting that landing on a service URL with invalid
jsonFields/lineFormat values loads without a malformed-query error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@L2D2Grafana L2D2Grafana force-pushed the l2d22/1976-errors-stuck-in-urls branch from 09e16fd to 99df5bf Compare July 7, 2026 15:48
@L2D2Grafana L2D2Grafana marked this pull request as ready for review July 7, 2026 21:46
@L2D2Grafana L2D2Grafana requested a review from a team as a code owner July 7, 2026 21:46
Copilot AI review requested due to automatic review settings July 7, 2026 21:46

Copilot AI 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.

Pull request overview

Fixes a navigation/state bug in the Logs Drilldown plugin where drilldown-only URL params could persist on the service-selection route, leading to malformed LogQL interpolation (and a parse/JSON.parse error) on the first “Show logs” click.

Changes:

  • Filter drilldown-only params out of service-selection URLs and proactively scrub them on IndexScene activation when on the service-selection page.
  • Re-sync cached scene variables with the URL by clearing ad-hoc variables when the corresponding URL param is absent or empty.
  • Update unit/E2E coverage and bump @grafana/scenes / @grafana/scenes-react to 8.9.0 (plus pnpm version bump in package.json).

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/invalidUrl.spec.ts Adds E2E coverage to ensure landing on a URL with invalid jsonFields/lineFormat does not surface parse errors.
tests/exploreServices.spec.ts Updates E2E assertions to match current service-selection behavior and reduces query-count flakiness.
tests/breakdowns/jsonView.spec.ts Adjusts E2E assertions for shared log-line links to use DOM/ARIA signals rather than viewport geometry.
src/services/routing.ts Adds excluded URL keys for service-selection URLs and applies filtering while building service routes.
src/services/routing.test.ts Adds a unit test ensuring excluded keys are dropped when building the explore/service-selection URL.
src/Components/IndexScene/IndexScene.tsx Scrubs excluded URL keys on activation for service-selection and clears cached ad-hoc variables when URL params are absent/empty.
package.json Bumps @grafana/scenes/@grafana/scenes-react and updates packageManager pnpm version.

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

if (!this.state.embedded && this.userInServiceSelection()) {
const searchParams = urlUtil.getUrlSearchParams();
const hasExcludedServiceUrlKey = SERVICE_URL_EXCLUDED_KEYS.some((key) =>
Object.prototype.hasOwnProperty.call(searchParams, key)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not

Suggested change
Object.prototype.hasOwnProperty.call(searchParams, key)
searchParams.hasOwnProperty(key)

?

if (cleanExploreUrl !== currentUrl) {
locationService.replace(cleanExploreUrl);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Additionally, why not using the current URL and search params, but removing SERVICE_URL_EXCLUDED_KEYS from the current search params?

That would mean, location.pathname + search params from line 290 but without the keys from SERVICE_URL_EXCLUDED_KEYS

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually my bad. If it's a search params instance, you check for existing keys using .get() or .has().

matyax
matyax previously approved these changes Jul 8, 2026

@matyax matyax left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Just a couple of questions.

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.

[BUG]: Clicking Show logs fails but works after refresh

3 participants