Skip to content

Commit f85b5f4

Browse files
authored
Support log volume for SQL editor (#1475)
1 parent 1e1ff99 commit f85b5f4

File tree

12 files changed

+657
-651
lines changed

12 files changed

+657
-651
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Support log volume queries for the SQL editor. Note that this will only work for Grafana versions >= 12.4.0 (#1475)
8+
39
## 4.11.4
410

511
## Fixes
@@ -11,7 +17,7 @@
1117

1218
## 4.11.3
1319

14-
## Fixes
20+
### Fixes
1521

1622
- Fix config UI bugs (#1409) and update design (#1422)
1723
- Dependency updates

package-lock.json

Lines changed: 582 additions & 628 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
},
8787
"dependencies": {
8888
"@emotion/css": "11.13.5",
89-
"@grafana/data": "^11.6.6",
90-
"@grafana/runtime": "^11.6.6",
91-
"@grafana/schema": "^11.6.6",
92-
"@grafana/ui": "^11.6.6",
89+
"@grafana/data": "12.4.0-20238213662",
90+
"@grafana/runtime": "12.4.0-20238213662",
91+
"@grafana/schema": "12.4.0-20238213662",
92+
"@grafana/ui": "12.4.0-20238213662",
9393
"js-sql-parser": "^1.6.0",
9494
"pgsql-ast-parser": "^12.0.1",
9595
"semver": "^7.7.3",

src/components/configEditor/AliasTableConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const AliasTableEditor = (props: AliasTableEditorProps) => {
172172
size="sm"
173173
icon="trash-alt"
174174
onClick={onRemove}
175+
aria-label="alias-remove-entry"
175176
/>
176177
)}
177178
</Stack>

src/components/configEditor/HttpHeadersConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ const HttpHeaderEditor = (props: HttpHeaderEditorProps) => {
170170
size="sm"
171171
icon="trash-alt"
172172
onClick={onRemove}
173+
aria-label="http-header-remove"
173174
/>
174175
)}
175176
</Stack>

src/components/queryBuilder/AggregateEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const Aggregate = (props: AggregateProps) => {
8282
size="sm"
8383
icon="trash-alt"
8484
onClick={() => removeAggregate(index)}
85+
aria-label="aggregate-remove-item"
8586
/>
8687
</HorizontalGroup>
8788
);

src/components/queryBuilder/FilterEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ export const FilterEditor = (props: {
406406
size="sm"
407407
className={styles.Common.smallBtn}
408408
onClick={() => removeFilter(index)}
409+
aria-label="query-builder-filters-remove-button"
409410
/>
410411
</HorizontalGroup>
411412
);

src/components/queryBuilder/OrderByEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const OrderByItem = (props: OrderByItemProps) => {
5050
size="sm"
5151
icon="trash-alt"
5252
onClick={() => removeOrderByItem(index)}
53+
aria-label="order-by-remove-item"
5354
/>
5455
</>
5556
);

src/data/CHDatasource.test.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import {
55
DataQueryResponse,
66
SupplementaryQueryType,
77
TimeRange,
8-
TypedVariableModel,
98
toDataFrame,
9+
TypedVariableModel,
1010
} from '@grafana/data';
11-
import { DataQuery } from '@grafana/schema';
12-
import { Observable, of } from 'rxjs';
1311
import { DataSourceWithBackend } from '@grafana/runtime';
12+
import { DataQuery } from '@grafana/schema';
1413
import { mockDatasource } from '__mocks__/datasource';
15-
import { CHBuilderQuery, CHQuery, CHSqlQuery, EditorType } from 'types/sql';
16-
import { ColumnHint, QueryType, BuilderMode, QueryBuilderOptions } from 'types/queryBuilder';
1714
import { cloneDeep } from 'lodash';
15+
import { Observable, of } from 'rxjs';
16+
import { BuilderMode, ColumnHint, QueryBuilderOptions, QueryType } from 'types/queryBuilder';
17+
import { CHBuilderQuery, CHQuery, CHSqlQuery, EditorType } from 'types/sql';
18+
import { AdHocFilter } from './adHocFilter';
1819
import { Datasource } from './CHDatasource';
1920
import * as logs from './logs';
20-
import { AdHocFilter } from './adHocFilter';
2121

2222
jest.mock('./logs', () => ({
2323
getTimeFieldRoundingClause: jest.fn(),
@@ -517,6 +517,42 @@ describe('ClickHouseDatasource', () => {
517517
datasource = cloneDeep(mockDatasource);
518518
});
519519

520+
describe('getSupportedSupplementaryQueryTypes', () => {
521+
it('should return LogsVolume for empty dsRequest', async () => {
522+
const result = datasource.getSupportedSupplementaryQueryTypes();
523+
expect(result).toEqual([SupplementaryQueryType.LogsVolume]);
524+
});
525+
526+
it('should return LogsVolume when all targets use Builder editor', async () => {
527+
const dsRequest: DataQueryRequest<CHQuery> = {
528+
...request,
529+
targets: [
530+
{
531+
...query,
532+
editorType: EditorType.Builder,
533+
},
534+
],
535+
};
536+
const result = datasource.getSupportedSupplementaryQueryTypes(dsRequest);
537+
expect(result).toEqual([SupplementaryQueryType.LogsVolume]);
538+
});
539+
540+
it('should return empty array when any target uses SQL editor', async () => {
541+
const dsRequest: DataQueryRequest<CHQuery> = {
542+
...request,
543+
targets: [
544+
{
545+
...query,
546+
editorType: EditorType.SQL,
547+
queryType: query.builderOptions.queryType,
548+
},
549+
],
550+
};
551+
const result = datasource.getSupportedSupplementaryQueryTypes(dsRequest);
552+
expect(result).toEqual([]);
553+
});
554+
});
555+
520556
describe('getSupplementaryLogsVolumeQuery', () => {
521557
it('should return undefined if any of the conditions are not met', async () => {
522558
[QueryType.Table, QueryType.TimeSeries, QueryType.Traces].forEach((queryType) => {

src/data/CHDatasource.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@ import {
2020
TypedVariableModel,
2121
} from '@grafana/data';
2222
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
23-
import { Observable, map, firstValueFrom } from 'rxjs';
23+
import LogsContextPanel from 'components/LogsContextPanel';
24+
import { cloneDeep, isEmpty, isString } from 'lodash';
25+
import otel from 'otel';
26+
import { createElement as createReactElement, ReactNode } from 'react';
27+
import { firstValueFrom, map, Observable } from 'rxjs';
2428
import { CHConfig } from 'types/config';
25-
import { EditorType, CHQuery } from 'types/sql';
2629
import {
27-
QueryType,
2830
AggregateColumn,
2931
AggregateType,
3032
BuilderMode,
33+
ColumnHint,
3134
Filter,
3235
FilterOperator,
33-
TableColumn,
3436
OrderByDirection,
3537
QueryBuilderOptions,
36-
ColumnHint,
37-
TimeUnit,
38+
QueryType,
3839
SelectedColumn,
3940
SqlFunction,
41+
TableColumn,
42+
TimeUnit,
4043
} from 'types/queryBuilder';
44+
import { CHQuery, EditorType } from 'types/sql';
45+
import { pluginVersion } from 'utils/version';
4146
import { AdHocFilter } from './adHocFilter';
42-
import { cloneDeep, isEmpty, isString } from 'lodash';
4347
import {
4448
DEFAULT_LOGS_ALIAS,
4549
getIntervalInfo,
@@ -49,11 +53,7 @@ import {
4953
TIME_FIELD_ALIAS,
5054
} from './logs';
5155
import { generateSql, getColumnByHint, logAliasToColumnHints } from './sqlGenerator';
52-
import otel from 'otel';
53-
import { createElement as createReactElement, ReactNode } from 'react';
5456
import { dataFrameHasLogLabelWithName, transformQueryResponseWithTraceAndLogLinks } from './utils';
55-
import { pluginVersion } from 'utils/version';
56-
import LogsContextPanel from 'components/LogsContextPanel';
5757

5858
export class Datasource
5959
extends DataSourceWithBackend<CHQuery, CHConfig>
@@ -121,7 +121,10 @@ export class Datasource
121121
}
122122
}
123123

124-
getSupportedSupplementaryQueryTypes(): SupplementaryQueryType[] {
124+
getSupportedSupplementaryQueryTypes(dsRequest?: DataQueryRequest<CHQuery>): SupplementaryQueryType[] {
125+
if (dsRequest && dsRequest.targets.some((t) => t.editorType !== EditorType.Builder)) {
126+
return [];
127+
}
125128
return [SupplementaryQueryType.LogsVolume];
126129
}
127130

0 commit comments

Comments
 (0)