Loki: Fix Loki with repeated panels and interpolation for Explore (#21685)

This commit is contained in:
Ivana Huckova
2020-01-24 09:50:09 +01:00
committed by GitHub
parent f91a495875
commit e75840737e
11 changed files with 40 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ import _ from 'lodash';
import ResponseParser from './response_parser';
import MysqlQuery from 'app/plugins/datasource/mysql/mysql_query';
import { getBackendSrv } from '@grafana/runtime';
import { ScopedVars } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
//Types
@@ -27,7 +28,8 @@ export class MysqlDatasource {
interpolateVariable = (value: string, variable: any) => {
if (typeof value === 'string') {
if (variable.multi || variable.includeAll) {
return this.queryModel.quoteLiteral(value);
const result = this.queryModel.quoteLiteral(value);
return result;
} else {
return value;
}
@@ -43,14 +45,17 @@ export class MysqlDatasource {
return quotedValues.join(',');
};
interpolateVariablesInQueries(queries: MysqlQueryForInterpolation[]): MysqlQueryForInterpolation[] {
interpolateVariablesInQueries(
queries: MysqlQueryForInterpolation[],
scopedVars: ScopedVars
): MysqlQueryForInterpolation[] {
let expandedQueries = queries;
if (queries && queries.length > 0) {
expandedQueries = queries.map(query => {
const expandedQuery = {
...query,
datasource: this.name,
rawSql: this.templateSrv.replace(query.rawSql, {}, this.interpolateVariable),
rawSql: this.templateSrv.replace(query.rawSql, scopedVars, this.interpolateVariable),
};
return expandedQuery;
});