mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: test datasource (#45636)
* Test datasource * Remove core.explore check * Extract resused check to function * Update messages * Updated message
This commit is contained in:
@@ -22,7 +22,6 @@ import {
|
|||||||
TIME_SERIES_TIME_FIELD_NAME,
|
TIME_SERIES_TIME_FIELD_NAME,
|
||||||
TIME_SERIES_VALUE_FIELD_NAME,
|
TIME_SERIES_VALUE_FIELD_NAME,
|
||||||
TimeSeries,
|
TimeSeries,
|
||||||
CoreApp,
|
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import InfluxSeries from './influx_series';
|
import InfluxSeries from './influx_series';
|
||||||
import InfluxQueryModel from './influx_query_model';
|
import InfluxQueryModel from './influx_query_model';
|
||||||
@@ -165,7 +164,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
return super.query(filteredRequest);
|
return super.query(filteredRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.featureToggles.influxdbBackendMigration && this.access === 'proxy' && request.app === CoreApp.Explore) {
|
if (this.isMigrationToggleOnAndIsAccessProxy()) {
|
||||||
return super.query(filteredRequest).pipe(
|
return super.query(filteredRequest).pipe(
|
||||||
map((res) => {
|
map((res) => {
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
@@ -449,7 +448,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
}
|
}
|
||||||
|
|
||||||
async metricFindQuery(query: string, options?: any): Promise<MetricFindValue[]> {
|
async metricFindQuery(query: string, options?: any): Promise<MetricFindValue[]> {
|
||||||
if (this.isFlux || (config.featureToggles.influxdbBackendMigration && this.access === 'proxy')) {
|
if (this.isFlux || this.isMigrationToggleOnAndIsAccessProxy()) {
|
||||||
const target: InfluxQuery = {
|
const target: InfluxQuery = {
|
||||||
refId: 'metricFindQuery',
|
refId: 'metricFindQuery',
|
||||||
query,
|
query,
|
||||||
@@ -554,6 +553,33 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isMigrationToggleOnAndIsAccessProxy()) {
|
||||||
|
const target: InfluxQuery = {
|
||||||
|
refId: 'metricFindQuery',
|
||||||
|
query: 'SHOW TAG KEYS',
|
||||||
|
rawQuery: true,
|
||||||
|
};
|
||||||
|
return lastValueFrom(super.query({ targets: [target] } as DataQueryRequest))
|
||||||
|
.then((res: DataQueryResponse) => {
|
||||||
|
if (!res || !res.data || res.state !== LoadingState.Done) {
|
||||||
|
return {
|
||||||
|
status: 'error',
|
||||||
|
message: 'Error reading InfluxDB.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (res.data?.length) {
|
||||||
|
return { status: 'success', message: 'Data source is working.' };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: 'error',
|
||||||
|
message: 'Successfully connected to InfluxDB, but no tags found.',
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.catch((err: any) => {
|
||||||
|
return { status: 'error', message: err.message };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const queryBuilder = new InfluxQueryBuilder({ measurement: '', tags: [] }, this.database);
|
const queryBuilder = new InfluxQueryBuilder({ measurement: '', tags: [] }, this.database);
|
||||||
const query = queryBuilder.buildExploreQuery('RETENTION POLICIES');
|
const query = queryBuilder.buildExploreQuery('RETENTION POLICIES');
|
||||||
|
|
||||||
@@ -700,4 +726,8 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
|
|
||||||
return date.valueOf() + 'ms';
|
return date.valueOf() + 'ms';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMigrationToggleOnAndIsAccessProxy() {
|
||||||
|
return config.featureToggles.influxdbBackendMigration && this.access === 'proxy';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user