Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(logs): re-mine patterns on refresh (#94215)

Jon McCallum444ca5bd882a
diff --git a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts
index 6899ef936b51..f201cecc5ef1 100644
--- a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts
+++ b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.test.ts
@@ -321,6 +321,40 @@ describe('logsPatternsLogic', () => {
)
})
+ it('re-mines when the refresh button runs the query', async () => {
+ // The refresh button dispatches `bumpFacetRefresh` on the shared filters logic. Without
+ // wiring, Patterns kept the earlier mine while the logs table below it re-ran.
+ const configLogic = logsViewerConfigLogic({ id: ID })
+ configLogic.mount()
+ configLogic.actions.setViewMode('patterns')
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadPatternsSuccess'])
+ mockCreate.mockClear()
+
+ await expectLogic(logic, () => {
+ filtersLogic.actions.bumpFacetRefresh()
+ }).toDispatchActions(['loadPatterns', 'loadPatternsSuccess'])
+
+ expect(mockCreate).toHaveBeenCalledTimes(1)
+ })
+
+ it('ignores the refresh button while Patterns is not the active lens', async () => {
+ // The logic can stay mounted after a lens switch; a refresh from the Logs table must not
+ // fire a stray mine.
+ const configLogic = logsViewerConfigLogic({ id: ID })
+ configLogic.mount()
+ configLogic.actions.setViewMode('patterns')
+ logic.mount()
+ await expectLogic(logic).toDispatchActions(['loadPatternsSuccess'])
+ configLogic.actions.setViewMode('logs')
+ mockCreate.mockClear()
+
+ filtersLogic.actions.bumpFacetRefresh()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockCreate).not.toHaveBeenCalled()
+ })
+
// The label format flips on a >= 24h window threshold (time-of-day vs date-prefixed) and
// early-returns on empty buckets — none of the above tests read `sparklineLabels`, so a
// flipped threshold or a broken dayjs format would otherwise go undetected.
diff --git a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts
index 4a8b28f3089e..d7d56e267d40 100644
--- a/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts
+++ b/products/logs/frontend/components/LogsPatterns/logsPatternsLogic.ts
@@ -116,6 +116,9 @@ export interface logsPatternsLogicActions {
setViewMode: (viewMode: LogsViewerViewMode) => {
viewMode: LogsViewerViewMode
} // logsViewerConfigLogic
+ bumpFacetRefresh: () => {
+ value: true
+ } // logsViewerFiltersLogic
setDateRange: (dateRange: DateRange) => {
dateRange: DateRange
} // logsViewerFiltersLogic
@@ -230,7 +233,15 @@ export const logsPatternsLogic = kea<logsPatternsLogicType>([
],
actions: [
logsViewerFiltersLogic({ id: props.id }),
- ['setDateRange', 'zoomDateRange', 'setSearchTerm', 'setFilters', 'setFilterGroup', 'setPinnedFilters'],
+ [
+ 'setDateRange',
+ 'zoomDateRange',
+ 'setSearchTerm',
+ 'setFilters',
+ 'setFilterGroup',
+ 'setPinnedFilters',
+ 'bumpFacetRefresh',
+ ],
logsViewerConfigLogic({ id: props.id }),
['setViewMode', 'setCompareEnabled', 'setBaselineMode'],
],
@@ -371,6 +382,20 @@ export const logsPatternsLogic = kea<logsPatternsLogicType>([
setFilterGroup: reload,
setPinnedFilters: reload,
+ // The refresh button fires `bumpFacetRefresh` through the shared filters logic. Re-mine
+ // immediately (no debounce) — it is a deliberate click, not typing — but only while
+ // Patterns is the active lens, and diff or plain to match compare mode.
+ bumpFacetRefresh: () => {
+ if (values.viewMode !== 'patterns') {
+ return
+ }
+ if (values.compareEnabled) {
+ actions.loadDiff()
+ } else {
+ actions.loadPatterns()
+ }
+ },
+
// Entering compare mode always diffs fresh; leaving it re-mines because the
// filters may have changed while the plain response sat unused.
setCompareEnabled: ({ enabled }) => {