From a5a85e03985aca2d572f06adc3adf834b4a53338 Mon Sep 17 00:00:00 2001 From: Brett Buddin Date: Thu, 26 Jan 2023 13:14:02 -0500 Subject: [PATCH] InfluxDB: Send retention policy with InfluxQL queries if its been specified. (#62149) * InfluxDB: Send retention policy with InfluQL queries if it's been specified. In InfluxDB v2, due to technical limitations of the InfluxDB v1 compatibility layer, retention policies in a query (e.g. ".") aren't honored and must be specified in the URL query parameter `rp` to be applied. Grafana doesn't send this query parameter which results in all queries resolving to the default retention policy when querying InfluxDB v2 servers using InfluxQL. This addresses the issue by sending the `rp` query parameter for queries that have specified a retention policy in the `target` given to `runExploreQuery`. The outcomes are: 1. InfluxQL queries executed against InfluxDB v2 databases will have the necessary retention policy information for queries like `SHOW FIELD KEYS FROM measurement` to function correctly. 2. InfluxQL queries executed against InfluxDB v1 databases will be unaffected, because this `rp` query parameter is unsupported there. You can read more about the rentention policy mapping behavior of InfluxDB v2 in our documentation: - https://docs.influxdata.com/influxdb/v2.6/reference/api/influxdb-1x/dbrp/#when-querying-data - https://docs.influxdata.com/influxdb/v2.6/reference/api/influxdb-1x/query/#query-a-non-default-retention-policy * Use the ? operator Co-authored-by: Ryan McKinley Co-authored-by: Ryan McKinley --- public/app/plugins/datasource/influxdb/datasource.ts | 4 ++++ .../app/plugins/datasource/influxdb/influxQLMetadataQuery.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/influxdb/datasource.ts b/public/app/plugins/datasource/influxdb/datasource.ts index 878cb0ced9b..33dabd8cd23 100644 --- a/public/app/plugins/datasource/influxdb/datasource.ts +++ b/public/app/plugins/datasource/influxdb/datasource.ts @@ -403,6 +403,10 @@ export default class InfluxDatasource extends DataSourceWithBackend> => { const builder = new InfluxQueryBuilder(target, datasource.database); const q = builder.buildExploreQuery(type, withKey, withMeasurementFilter); - return datasource.metricFindQuery(q); + const options = { policy: target.policy }; + return datasource.metricFindQuery(q, options); }; export async function getAllPolicies(datasource: InfluxDatasource): Promise {