mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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. "<retention policy>.<measurement_name>") 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 <ryantxu@gmail.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
parent
a273c232a1
commit
a5a85e0398
@ -403,6 +403,10 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
params.db = this.database;
|
||||
}
|
||||
|
||||
if (options?.policy) {
|
||||
params.rp = options.policy;
|
||||
}
|
||||
|
||||
const { q } = data;
|
||||
|
||||
if (method === 'POST' && has(data, 'q')) {
|
||||
|
@ -11,7 +11,8 @@ const runExploreQuery = (
|
||||
): Promise<Array<{ text: string }>> => {
|
||||
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<string[]> {
|
||||
|
Loading…
Reference in New Issue
Block a user