Skip to content

Commit 002eb1d

Browse files
fix applying Custom query parameters when querying from Grafana variables (#413)
Related issue: #405
1 parent 7fe3529 commit 002eb1d

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## tip
44

5-
* BUGFIX: fix an issue with parsings of the logs lines when in the logs line empty `_stream` and missed `_msg` fields. See [#330](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/330)
5+
* BUGFIX: fix an issue with parsings of the logs lines when in the logs line empty `_stream` and missed `_msg` fields. See [#330](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/330).
6+
* BUGFIX: fix applying `Custom query parameters` when querying from Grafana variables. See [#405](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/405).
67

78
## v0.21.0
89

pkg/plugin/fields_query.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
)
99

1010
type FieldsQuery struct {
11-
Query string `json:"query"`
12-
Limit string `json:"limit"`
13-
Start string `json:"start"`
14-
End string `json:"end"`
15-
Field string `json:"field"`
11+
Query string `json:"query"`
12+
Limit string `json:"limit"`
13+
Start string `json:"start"`
14+
End string `json:"end"`
15+
Field string `json:"field"`
16+
ExtraFilters string `json:"extra_filters"`
1617
}
1718

1819
// getFieldsQueryFromRaw parses the field values query json from the raw message.
@@ -41,5 +42,8 @@ func (fv *FieldsQuery) queryParams() url.Values {
4142
if fv.Field != "" {
4243
params.Set("field", fv.Field)
4344
}
45+
if fv.ExtraFilters != "" {
46+
params.Set("extra_filters", fv.ExtraFilters)
47+
}
4448
return params
4549
}

src/components/QueryEditor/QueryBuilder/components/QueryBuilderFilters/QueryBuilderFieldFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const QueryBuilderFieldFilter = ({ datasource, filter, query, indexPath, timeRan
7272
const filtersWithoutCurrent = deleteByIndexPath(query.filters, indexPath)
7373
const currentOperator = query.filters.operators[indexPath[0] - 1] || "AND"
7474
const filters = currentOperator === "AND" ? filterVisualQueryToString(filtersWithoutCurrent, true) : ""
75-
const list = await datasource.languageProvider?.getFieldList({ type, timeRange, field, limit, query: filters });
75+
const list = await datasource.languageProvider?.getFieldList({ type, timeRange, field, limit, query: filters }, datasource.customQueryParameters);
7676
const result = list ? list.map(({ value, hits }) => ({
7777
value,
7878
label: value || " ",

src/components/VariableQueryEditor/VariableQueryEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const VariableQueryEditor = ({ onChange, query, datasource, range }: Prop
8383
timeRange: range,
8484
limit,
8585
query: getTemplateSrv().replace(queryFilter),
86-
});
86+
}, datasource.customQueryParameters);
8787

8888
const result = list
8989
? list.map(({ value, hits }) => ({

src/datasource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class VictoriaLogsDatasource
254254
type: FilterFieldType.FieldName,
255255
timeRange: options?.timeRange,
256256
limit: DEFAULT_FIELD_DISPLAY_VALUES_LIMIT,
257-
})
257+
}, this.customQueryParameters)
258258
return list
259259
? list.map(({ value }) => ({ text: value || " " }))
260260
: []
@@ -266,7 +266,7 @@ export class VictoriaLogsDatasource
266266
timeRange: options.timeRange,
267267
limit: DEFAULT_FIELD_DISPLAY_VALUES_LIMIT,
268268
field: options.key,
269-
})
269+
}, this.customQueryParameters)
270270
return list
271271
? list.map(({ value }) => ({ text: value || " " }))
272272
: []
@@ -301,7 +301,7 @@ export class VictoriaLogsDatasource
301301
field: query.field,
302302
query: query.query,
303303
limit: query.limit,
304-
});
304+
}, this.customQueryParameters);
305305
return (list ? list.map(({ value }) => ({ text: value })) : [])
306306
}
307307

src/language_provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ export default class LogsQlLanguageProvider extends LanguageProvider {
3838
return Promise.all([]);
3939
};
4040

41-
async getFieldList(options: FetchFieldsOptions): Promise<FieldHits[]> {
41+
async getFieldList(options: FetchFieldsOptions, customParams?: URLSearchParams): Promise<FieldHits[]> {
4242
if (options.type === FilterFieldType.FieldValue && !options.field) {
4343
console.warn('getFieldList: field is required for FieldValue type');
4444
return [];
4545
}
4646

4747
const urlParams = new URLSearchParams();
48+
if (customParams) {
49+
for (const [key, value] of customParams) {
50+
urlParams.append(key, value);
51+
}
52+
}
4853
urlParams.append('query', options.query || '*');
4954

5055
const timeRange = this.getTimeRangeParams(options.timeRange);

0 commit comments

Comments
 (0)