Skip to content

Commit e9ad12f

Browse files
authored
feat(logs): Support multiple visualizes and groupbys in logs (#97912)
This adds support in logs to allow users to add multiple visualizes and groupbys.
1 parent 6597345 commit e9ad12f

File tree

7 files changed

+665
-292
lines changed

7 files changed

+665
-292
lines changed

static/app/views/explore/logs/logsTab.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
StyledPageFilterBar,
6060
TableActionsContainer,
6161
ToolbarAndBodyContainer,
62+
ToolbarContainer,
6263
TopSectionBody,
6364
} from 'sentry/views/explore/logs/styles';
6465
import {LogsAggregateTable} from 'sentry/views/explore/logs/tables/logsAggregateTable';
@@ -157,15 +158,14 @@ export function LogsTabContent({
157158
return newSearch;
158159
}, [logsSearch, timeseriesIngestDelay]);
159160

161+
const yAxes = new Set(visualizes.map(visualize => visualize.yAxis));
162+
160163
const _timeseriesResult = useSortedTimeSeries(
161164
{
162165
search,
163-
yAxis: visualizes.map(visualize => visualize.yAxis),
166+
yAxis: [...yAxes],
164167
interval,
165-
fields: [
166-
...groupBys.filter(Boolean),
167-
...visualizes.map(visualize => visualize.yAxis),
168-
],
168+
fields: [...groupBys.filter(Boolean), ...yAxes],
169169
topEvents: topEventsLimit,
170170
orderby,
171171
},
@@ -341,7 +341,9 @@ export function LogsTabContent({
341341

342342
<ToolbarAndBodyContainer sidebarOpen={sidebarOpen}>
343343
{sidebarOpen && (
344-
<LogsToolbar stringTags={stringAttributes} numberTags={numberAttributes} />
344+
<ToolbarContainer sidebarOpen={sidebarOpen}>
345+
<LogsToolbar stringTags={stringAttributes} numberTags={numberAttributes} />
346+
</ToolbarContainer>
345347
)}
346348
<BottomSectionBody>
347349
<section>

static/app/views/explore/logs/logsToolbar.spec.tsx

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,8 @@ describe('LogsToolbar', () => {
103103

104104
let options: HTMLElement[];
105105

106-
// count only has 1 option available
107-
await userEvent.click(screen.getByRole('button', {name: 'logs'}));
108-
options = screen.getAllByRole('option');
109-
expect(options).toHaveLength(1);
110-
expect(options[0]).toHaveTextContent('logs');
111-
await userEvent.click(options[0]!);
112-
expect(router.location.query.aggregateField).toEqual(
113-
[{groupBy: ''}, {yAxes: ['count(message)']}].map(aggregateField =>
114-
JSON.stringify(aggregateField)
115-
)
116-
);
106+
// count has no user changable argument
107+
expect(screen.getByRole('button', {name: 'logs'})).toBeDisabled();
117108

118109
// count unique only shows string attributes
119110
await userEvent.click(screen.getByRole('button', {name: 'count'}));
@@ -145,6 +136,37 @@ describe('LogsToolbar', () => {
145136
)
146137
);
147138
});
139+
140+
it('can add/delete visualizes', async function () {
141+
const {router} = render(
142+
<Wrapper>
143+
<LogsToolbar
144+
numberTags={{bar: {key: 'bar', name: 'bar'}, foo: {key: 'foo', name: 'foo'}}}
145+
stringTags={{
146+
message: {key: 'message', name: 'message'},
147+
severity: {key: 'severity', name: 'severity'},
148+
}}
149+
/>
150+
</Wrapper>
151+
);
152+
153+
await userEvent.click(screen.getByRole('button', {name: 'count'}));
154+
await userEvent.click(screen.getByRole('option', {name: 'avg'}));
155+
156+
await userEvent.click(screen.getByRole('button', {name: 'Add Chart'}));
157+
expect(router.location.query.aggregateField).toEqual(
158+
[{groupBy: ''}, {yAxes: ['avg(bar)']}, {yAxes: ['count(message)']}].map(
159+
aggregateField => JSON.stringify(aggregateField)
160+
)
161+
);
162+
163+
await userEvent.click(screen.getAllByLabelText('Remove Overlay')[0]!);
164+
expect(router.location.query.aggregateField).toEqual(
165+
[{groupBy: ''}, {yAxes: ['count(message)']}].map(aggregateField =>
166+
JSON.stringify(aggregateField)
167+
)
168+
);
169+
});
148170
});
149171

150172
describe('group by section', () => {
@@ -177,5 +199,37 @@ describe('LogsToolbar', () => {
177199
)
178200
);
179201
});
202+
203+
it('can add/delete group bys', async function () {
204+
const {router} = render(
205+
<Wrapper>
206+
<LogsToolbar
207+
numberTags={{bar: {key: 'bar', name: 'bar'}, foo: {key: 'foo', name: 'foo'}}}
208+
stringTags={{
209+
message: {key: 'message', name: 'message'},
210+
severity: {key: 'severity', name: 'severity'},
211+
}}
212+
/>
213+
</Wrapper>
214+
);
215+
216+
await userEvent.click(screen.getByRole('button', {name: '\u2014'}));
217+
await userEvent.click(screen.getByRole('option', {name: 'message'}));
218+
219+
await userEvent.click(screen.getByRole('button', {name: 'Add Group'}));
220+
expect(router.location.query.aggregateField).toEqual(
221+
[{groupBy: 'message'}, {yAxes: ['count(message)']}, {groupBy: ''}].map(
222+
aggregateField => JSON.stringify(aggregateField)
223+
)
224+
);
225+
226+
await userEvent.click(screen.getAllByLabelText('Remove Column')[0]!);
227+
expect(router.location.query.aggregateField).toEqual(
228+
// BUG: a little weird that the 2nd group by moves up to take its place
229+
[{groupBy: ''}, {yAxes: ['count(message)']}].map(aggregateField =>
230+
JSON.stringify(aggregateField)
231+
)
232+
);
233+
});
180234
});
181235
});

0 commit comments

Comments
 (0)