Skip to content

Commit 89194b4

Browse files
committed
fix(dashboard): reset the log filters when the tenant or app changes
LogsView kept its filter, pod and container across a scope switch, so the first request for the new tenant still asked for the previous tenant's pod before the picker fell back to All. The view's state is now keyed on the proxy root, so a new tenant or application starts with no filter and All selected. Assisted-by: LLM Signed-off-by: ZverGuy <[email protected]>
1 parent 711a82e commit 89194b4

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ describe("LogsView with the production query defaults", () => {
6262
expect((await screen.findAllByRole("option")).map((o) => o.textContent)).toEqual(["All"])
6363
})
6464

65+
it("starts the next tenant with no filter, pod or container of the previous one", async () => {
66+
const { client, raw } = clientWith(defaultHandler)
67+
const { switchTo } = renderWithProductionDefaults(client, "tenant-reset-a")
68+
await userEvent.type(screen.getByLabelText("LogsQL filter"), "error{Enter}")
69+
await userEvent.click(screen.getByRole("combobox", { name: "Pod" }))
70+
await userEvent.click(await screen.findByRole("option", { name: "db-1" }))
71+
await waitFor(() =>
72+
expect(raw.mock.calls.some(([p]) => new URL(p, "http://x").searchParams.get("query") === '{kubernetes_pod_name="db-1"} (error)')).toBe(true),
73+
)
74+
75+
switchTo("tenant-reset-b")
76+
77+
await waitFor(() => expect(raw.mock.calls.some(([p]) => p.includes("/tenant-reset-b/") && p.includes("select/logsql/query?"))).toBe(true))
78+
const first = raw.mock.calls.find(([p]) => p.includes("/tenant-reset-b/") && p.includes("select/logsql/query?"))!
79+
expect(new URL(first[0], "http://x").searchParams.get("query")).toBe("*")
80+
expect(screen.getByRole("combobox", { name: "Pod" })).toHaveTextContent("All")
81+
expect(screen.getByRole("combobox", { name: "Container" })).toHaveTextContent("All")
82+
expect(screen.getByLabelText("LogsQL filter")).toHaveValue("")
83+
})
84+
6585
it("keeps the current lines while a new filter in the same tenant loads", async () => {
6686
const { client } = clientWith((endpoint, params) =>
6787
endpoint.endsWith("query") && params.get("query") === "slow" ? new Promise(() => {}) : defaultHandler(endpoint, params),

‎packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,14 @@ function placeholderFor({ follow, stopped, loading, failed, longestRange, retry
8181
return <EmptyState tone="dark" title="No log lines for this range and filter." hint={longestRange ? "Try a broader filter." : "Try a longer range or a broader filter."} />
8282
}
8383

84+
// Filter, pod and container belong to one scope; a new tenant or application starts clean.
8485
export function LogsView({ scope }: { scope: ObservabilityScope }) {
85-
const client = useK8sClient()
8686
const root = logsRoot(scope)
87+
return <ScopedLogsView key={root} root={root} />
88+
}
89+
90+
function ScopedLogsView({ root }: { root: string }) {
91+
const client = useK8sClient()
8792
const [range, setRange] = useState<LogRangeKey>("1h")
8893
const [draft, setDraft] = useState("")
8994
const [filter, setFilter] = useState("")

0 commit comments

Comments
 (0)