mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elastic: Internal data links (#25942)
* Allow internal datalinks for elastic * Add docs * Update docs/sources/features/datasources/elasticsearch.md Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
DataQueryResponse,
|
||||
DataFrame,
|
||||
ScopedVars,
|
||||
DataLink,
|
||||
} from '@grafana/data';
|
||||
import { ElasticResponse } from './elastic_response';
|
||||
import { IndexPattern } from './index_pattern';
|
||||
@@ -404,7 +405,7 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
|
||||
if (sentTargets.some(target => target.isLogsQuery)) {
|
||||
const response = er.getLogs(this.logMessageField, this.logLevelField);
|
||||
for (const dataFrame of response.data) {
|
||||
this.enhanceDataFrame(dataFrame);
|
||||
enhanceDataFrame(dataFrame, this.dataLinks);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -584,24 +585,6 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
|
||||
return false;
|
||||
}
|
||||
|
||||
enhanceDataFrame(dataFrame: DataFrame) {
|
||||
if (this.dataLinks.length) {
|
||||
for (const field of dataFrame.fields) {
|
||||
const dataLink = this.dataLinks.find(dataLink => field.name && field.name.match(dataLink.field));
|
||||
if (dataLink) {
|
||||
field.config = field.config || {};
|
||||
field.config.links = [
|
||||
...(field.config.links || []),
|
||||
{
|
||||
url: dataLink.url,
|
||||
title: '',
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private isPrimitive(obj: any) {
|
||||
if (obj === null || obj === undefined) {
|
||||
return true;
|
||||
@@ -639,3 +622,35 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies dataframe and adds dataLinks from the config.
|
||||
* Exported for tests.
|
||||
*/
|
||||
export function enhanceDataFrame(dataFrame: DataFrame, dataLinks: DataLinkConfig[]) {
|
||||
if (dataLinks.length) {
|
||||
for (const field of dataFrame.fields) {
|
||||
const dataLinkConfig = dataLinks.find(dataLink => field.name && field.name.match(dataLink.field));
|
||||
if (dataLinkConfig) {
|
||||
let link: DataLink;
|
||||
if (dataLinkConfig.datasourceUid) {
|
||||
link = {
|
||||
title: '',
|
||||
url: '',
|
||||
internal: {
|
||||
query: { query: dataLinkConfig.url },
|
||||
datasourceUid: dataLinkConfig.datasourceUid,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
link = {
|
||||
title: '',
|
||||
url: dataLinkConfig.url,
|
||||
};
|
||||
}
|
||||
field.config = field.config || {};
|
||||
field.config.links = [...(field.config.links || []), link];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user