6
6
AbstractQuery ,
7
7
CoreApp ,
8
8
DataFrame ,
9
+ DataLink ,
9
10
DataQueryError ,
10
11
DataQueryRequest ,
11
12
DataQueryResponse ,
@@ -32,7 +33,11 @@ import {
32
33
TimeRange ,
33
34
} from '@grafana/data' ;
34
35
import { BucketAggregation , DataLinkConfig , ElasticsearchQuery , Field , FieldMapping , IndexMetadata , Logs , TermsQuery } from './types' ;
35
- import { DataSourceWithBackend , getTemplateSrv , TemplateSrv } from '@grafana/runtime' ;
36
+ import {
37
+ DataSourceWithBackend ,
38
+ getTemplateSrv ,
39
+ TemplateSrv ,
40
+ getDataSourceSrv } from '@grafana/runtime' ;
36
41
import { LogRowContextOptions , LogRowContextQueryDirection , QuickwitOptions } from 'quickwit' ;
37
42
import { ElasticQueryBuilder } from 'QueryBuilder' ;
38
43
import { colors } from '@grafana/ui' ;
@@ -83,15 +88,15 @@ export class QuickwitDataSource
83
88
this . languageProvider = new ElasticsearchLanguageProvider ( this ) ;
84
89
}
85
90
86
- // /**
87
- // * Ideally final -- any other implementation may not work as expected
88
- // */
89
- // query(request: DataQueryRequest<ElasticsearchQuery>): Observable<DataQueryResponse > {
90
- // return super.query(request)
91
- // .pipe(map((response) => {
92
- // return response;
93
- // }));
94
- // }
91
+ query ( request : DataQueryRequest < ElasticsearchQuery > ) : Observable < DataQueryResponse > {
92
+ return super . query ( request )
93
+ . pipe ( map ( ( response ) => {
94
+ response . data . forEach ( ( dataFrame ) = > {
95
+ enhanceDataFrameWithDataLinks ( dataFrame , this . dataLinks ) ;
96
+ } ) ;
97
+ return response ;
98
+ } ) ) ;
99
+ }
95
100
96
101
/**
97
102
* Checks the plugin health
@@ -816,6 +821,46 @@ function luceneEscape(value: string) {
816
821
return value . replace ( / ( [ \! \* \+ \- \= < > \s \& \| \( \) \[ \] \{ \} \^ \~ \? \: \\ / " ] ) / g, '\\$1' ) ;
817
822
}
818
823
824
+ export function enhanceDataFrameWithDataLinks ( dataFrame : DataFrame , dataLinks : DataLinkConfig [ ] ) {
825
+ if ( ! dataLinks . length ) {
826
+ return ;
827
+ }
828
+
829
+ for ( const field of dataFrame . fields ) {
830
+ const linksToApply = dataLinks . filter ( ( dataLink ) => new RegExp ( dataLink . field ) . test ( field . name ) ) ;
831
+
832
+ if ( linksToApply . length === 0 ) {
833
+ continue ;
834
+ }
835
+
836
+ field . config = field . config || { } ;
837
+ field . config . links = [ ...( field . config . links || [ ] , linksToApply . map ( generateDataLink ) ) ] ;
838
+ }
839
+ }
840
+
841
+ function generateDataLink ( linkConfig : DataLinkConfig ) : DataLink {
842
+ const dataSourceSrv = getDataSourceSrv ( ) ;
843
+
844
+ if ( linkConfig . datasourceUid ) {
845
+ const dsSettings = dataSourceSrv . getInstanceSettings ( linkConfig . datasourceUid ) ;
846
+
847
+ return {
848
+ title : linkConfig . urlDisplayLabel || '' ,
849
+ url : '' ,
850
+ internal : {
851
+ query : { query : linkConfig . url } ,
852
+ datasourceUid : linkConfig . datasourceUid ,
853
+ datasourceName : dsSettings ?. name ?? 'Data source not found' ,
854
+ } ,
855
+ } ;
856
+ } else {
857
+ return {
858
+ title : linkConfig . urlDisplayLabel || '' ,
859
+ url : linkConfig . url ,
860
+ } ;
861
+ }
862
+ }
863
+
819
864
function createContextTimeRange ( rowTimeEpochMs : number , direction : string ) {
820
865
const offset = 7 ;
821
866
// For log context, we want to request data from 7 subsequent/previous indices
@@ -831,4 +876,3 @@ function createContextTimeRange(rowTimeEpochMs: number, direction: string) {
831
876
} ;
832
877
}
833
878
}
834
-
0 commit comments