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
@@ -817,6 +822,46 @@ function luceneEscape(value: string) {
817
822
return value . replace ( / ( [ \! \* \+ \- \= < > \s \& \| \( \) \[ \] \{ \} \^ \~ \? \: \\ / " ] ) / g, '\\$1' ) ;
818
823
}
819
824
825
+ export function enhanceDataFrameWithDataLinks ( dataFrame : DataFrame , dataLinks : DataLinkConfig [ ] ) {
826
+ if ( ! dataLinks . length ) {
827
+ return ;
828
+ }
829
+
830
+ for ( const field of dataFrame . fields ) {
831
+ const linksToApply = dataLinks . filter ( ( dataLink ) => new RegExp ( dataLink . field ) . test ( field . name ) ) ;
832
+
833
+ if ( linksToApply . length === 0 ) {
834
+ continue ;
835
+ }
836
+
837
+ field . config = field . config || { } ;
838
+ field . config . links = [ ...( field . config . links || [ ] , linksToApply . map ( generateDataLink ) ) ] ;
839
+ }
840
+ }
841
+
842
+ function generateDataLink ( linkConfig : DataLinkConfig ) : DataLink {
843
+ const dataSourceSrv = getDataSourceSrv ( ) ;
844
+
845
+ if ( linkConfig . datasourceUid ) {
846
+ const dsSettings = dataSourceSrv . getInstanceSettings ( linkConfig . datasourceUid ) ;
847
+
848
+ return {
849
+ title : linkConfig . urlDisplayLabel || '' ,
850
+ url : '' ,
851
+ internal : {
852
+ query : { query : linkConfig . url } ,
853
+ datasourceUid : linkConfig . datasourceUid ,
854
+ datasourceName : dsSettings ?. name ?? 'Data source not found' ,
855
+ } ,
856
+ } ;
857
+ } else {
858
+ return {
859
+ title : linkConfig . urlDisplayLabel || '' ,
860
+ url : linkConfig . url ,
861
+ } ;
862
+ }
863
+ }
864
+
820
865
function createContextTimeRange ( rowTimeEpochMs : number , direction : string ) {
821
866
const offset = 7 ;
822
867
// For log context, we want to request data from 7 subsequent/previous indices
@@ -832,4 +877,3 @@ function createContextTimeRange(rowTimeEpochMs: number, direction: string) {
832
877
} ;
833
878
}
834
879
}
835
-
0 commit comments