mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 11:13:07 +08:00
Postgres/MySQL/MSSQL: Remove usage of legacy timeSrv (#45241)
This commit is contained in:

committed by
GitHub

parent
fed112ef3b
commit
0e8a5407d1
@ -2,12 +2,11 @@ import { map as _map } from 'lodash';
|
||||
import { lastValueFrom, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { BackendDataSourceResponse, DataSourceWithBackend, FetchResponse, getBackendSrv } from '@grafana/runtime';
|
||||
import { AnnotationEvent, DataSourceInstanceSettings, MetricFindValue, ScopedVars } from '@grafana/data';
|
||||
import { AnnotationEvent, DataSourceInstanceSettings, MetricFindValue, ScopedVars, TimeRange } from '@grafana/data';
|
||||
|
||||
import ResponseParser from './response_parser';
|
||||
import PostgresQueryModel from 'app/plugins/datasource/postgres/postgres_query_model';
|
||||
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
//Types
|
||||
import { PostgresOptions, PostgresQuery, PostgresQueryForInterpolation } from './types';
|
||||
import { getSearchFilterScopedVar } from '../../../features/variables/utils';
|
||||
@ -23,8 +22,7 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
|
||||
|
||||
constructor(
|
||||
instanceSettings: DataSourceInstanceSettings<PostgresOptions>,
|
||||
private readonly templateSrv: TemplateSrv = getTemplateSrv(),
|
||||
private readonly timeSrv: TimeSrv = getTimeSrv()
|
||||
private readonly templateSrv: TemplateSrv = getTemplateSrv()
|
||||
) {
|
||||
super(instanceSettings);
|
||||
this.name = instanceSettings.name;
|
||||
@ -142,7 +140,7 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
|
||||
format: 'table',
|
||||
};
|
||||
|
||||
const range = this.timeSrv.timeRange();
|
||||
const range = optionalOptions?.range as TimeRange;
|
||||
|
||||
return lastValueFrom(
|
||||
getBackendSrv()
|
||||
@ -150,8 +148,8 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
|
||||
url: '/api/ds/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
from: range.from.valueOf().toString(),
|
||||
to: range.to.valueOf().toString(),
|
||||
from: range?.from?.valueOf()?.toString(),
|
||||
to: range?.to?.valueOf()?.toString(),
|
||||
queries: [interpolatedQuery],
|
||||
},
|
||||
requestId: refId,
|
||||
@ -169,7 +167,6 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
|
||||
|
||||
private _metaRequest(rawSql: string) {
|
||||
const refId = 'meta';
|
||||
const range = this.timeSrv.timeRange();
|
||||
const query = {
|
||||
refId: refId,
|
||||
datasource: this.getRef(),
|
||||
@ -180,8 +177,6 @@ export class PostgresDatasource extends DataSourceWithBackend<PostgresQuery, Pos
|
||||
url: '/api/ds/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
from: range.from.valueOf().toString(),
|
||||
to: range.to.valueOf().toString(),
|
||||
queries: [query],
|
||||
},
|
||||
requestId: refId,
|
||||
|
Reference in New Issue
Block a user