mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user