Explore: Transform prometheus query to elasticsearch query (#23670)

* Explore: Transform prometheus query to elasticsearch query

Enable a way to transform prometheus/loki labels to elasticsearch query.
This make a link between metrics to logs.
Examples:
A prometheus query : rate(my_metric{label1="value1",label2!="value2",label3=~"value.+",label4!~".*tothemoon"}[5m])
Will be this elasticsearch query when switching to elasticsearch datasource:  __name__:"my_metric" AND label1:"value1" AND NOT label2:"value2" AND label3:/value.+/ AND NOT label4:/.*tothemoon/

* fix test

* remove non needed async

* Use prism token instead of regex

* fix test ./scripts/ci-frontend-metrics.sh

* mock timesrv and TemplateSrv in test

* Remove unnecessary await/async

Co-authored-by: Melchior MOULIN <m.moulin@criteo.com>
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
This commit is contained in:
Melchior MOULIN
2020-09-08 12:34:11 +02:00
committed by GitHub
parent 561920f18b
commit dfc78d0979
3 changed files with 255 additions and 0 deletions

View File

@@ -8,7 +8,10 @@ import {
DataFrame,
ScopedVars,
DataLink,
PluginMeta,
DataQuery,
} from '@grafana/data';
import LanguageProvider from './language_provider';
import { ElasticResponse } from './elastic_response';
import { IndexPattern } from './index_pattern';
import { ElasticQueryBuilder } from './query_builder';
@@ -34,6 +37,7 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
logMessageField?: string;
logLevelField?: string;
dataLinks: DataLinkConfig[];
languageProvider: LanguageProvider;
/** @ngInject */
constructor(
@@ -69,6 +73,7 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
if (this.logLevelField === '') {
this.logLevelField = undefined;
}
this.languageProvider = new LanguageProvider(this);
}
private request(method: string, url: string, data?: undefined) {
@@ -100,6 +105,10 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
});
}
async importQueries(queries: DataQuery[], originMeta: PluginMeta): Promise<ElasticsearchQuery[]> {
return this.languageProvider.importQueries(queries, originMeta.id);
}
/**
* Sends a GET request to the specified url on the newest matching and available index.
*