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-run the group by query on refresh (#94133)

Jon McCalluma14c53bde697
diff --git a/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.test.ts b/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.test.ts
index b77196e43365..0d1b94f4b0a7 100644
--- a/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.test.ts
+++ b/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.test.ts
@@ -5,6 +5,7 @@ import { initKeaTests } from '~/test/init'
import { logsGroupByCreate } from 'products/logs/frontend/generated/api'
import { logsViewerConfigLogic } from '../LogsViewer/config/logsViewerConfigLogic'
+import { logsViewerFiltersLogic } from '../LogsViewer/Filters/logsViewerFiltersLogic'
import { logsGroupByLogic } from './logsGroupByLogic'
jest.mock('lib/api')
@@ -13,6 +14,7 @@ jest.mock('products/logs/frontend/generated/api')
describe('logsGroupByLogic', () => {
let logic: ReturnType<typeof logsGroupByLogic.build>
let configLogic: ReturnType<typeof logsViewerConfigLogic.build>
+ let filtersLogic: ReturnType<typeof logsViewerFiltersLogic.build>
beforeEach(() => {
localStorage.clear()
@@ -26,6 +28,8 @@ describe('logsGroupByLogic', () => {
})
configLogic = logsViewerConfigLogic({ id: 'test' })
configLogic.mount()
+ filtersLogic = logsViewerFiltersLogic({ id: 'test' })
+ filtersLogic.mount()
logic = logsGroupByLogic({ id: 'test' })
logic.mount()
})
@@ -49,4 +53,15 @@ describe('logsGroupByLogic', () => {
])
expect(body.query.groupBy).toBeUndefined()
})
+
+ it('re-aggregates when the refresh button runs the query', async () => {
+ configLogic.actions.setGroupBys([{ key: 'service.name', source: 'resource' }])
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logsGroupByCreate).toHaveBeenCalledTimes(1)
+
+ filtersLogic.actions.bumpFacetRefresh()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logsGroupByCreate).toHaveBeenCalledTimes(2)
+ })
})
diff --git a/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.ts b/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.ts
index 386822b5d7ac..80e11f107efe 100644
--- a/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.ts
+++ b/products/logs/frontend/components/LogsGroupBy/logsGroupByLogic.ts
@@ -65,6 +65,9 @@ export interface logsGroupByLogicActions {
setGroupBys: (groupBys: LogsViewerGroupBy[]) => {
groupBys: LogsViewerGroupBy[]
} // logsViewerConfigLogic
+ bumpFacetRefresh: () => {
+ value: true
+ } // logsViewerFiltersLogic
setDateRange: (dateRange: DateRange) => {
dateRange: DateRange
} // logsViewerFiltersLogic
@@ -145,7 +148,15 @@ export const logsGroupByLogic = kea<logsGroupByLogicType>([
],
actions: [
logsViewerFiltersLogic({ id: props.id }),
- ['setDateRange', 'zoomDateRange', 'setSearchTerm', 'setFilters', 'setFilterGroup', 'setPinnedFilters'],
+ [
+ 'setDateRange',
+ 'zoomDateRange',
+ 'setSearchTerm',
+ 'setFilters',
+ 'setFilterGroup',
+ 'setPinnedFilters',
+ 'bumpFacetRefresh',
+ ],
logsViewerConfigLogic({ id: props.id }),
['setGroupBys', 'addGroupBy', 'removeGroupByAt', 'replaceGroupByAt'],
],
@@ -222,6 +233,9 @@ export const logsGroupByLogic = kea<logsGroupByLogicType>([
setFilterGroup: reload,
setPinnedFilters: reload,
// Immediate: changing the grouping dimensions or ranking column is a deliberate click.
+ // The refresh button fires `bumpFacetRefresh` through the shared filters logic, so
+ // the groups re-aggregate with the logs table instead of showing the earlier result.
+ bumpFacetRefresh: () => actions.loadGroups(),
setGroupBys: () => actions.loadGroups(),
addGroupBy: () => actions.loadGroups(),
removeGroupByAt: () => actions.loadGroups(),