-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatasource.ts
55 lines (46 loc) · 1.69 KB
/
datasource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
CoreApp,
DataQueryRequest,
DataSourceInstanceSettings,
MetricFindValue,
ScopedVars,
VariableSupportType
} from '@grafana/data';
import {DataSourceWithBackend, getTemplateSrv} from '@grafana/runtime';
import {AnnotationEditor} from './components/AnnotationEditor';
import {VariableQueryEditor} from './components/VariableQueryEditor';
import {DEFAULT_QUERY, RocksetDataSourceOptions, RocksetQuery} from './types';
export class DataSource extends DataSourceWithBackend<RocksetQuery, RocksetDataSourceOptions> {
constructor(instanceSettings: DataSourceInstanceSettings<RocksetDataSourceOptions>) {
super(instanceSettings);
this.annotations = {
QueryEditor: AnnotationEditor,
prepareQuery: (anno) => anno.target
}
this.variables = {
editor: VariableQueryEditor as any,
getType: () => VariableSupportType.Custom,
query: (q: DataQueryRequest<RocksetQuery>) => this.query({
...q,
targets: q.targets.map((t) => ({...t, refId: "variable-query"}))
})
}
}
async metricFindQuery(query: any, options?: any): Promise<MetricFindValue[]> {
console.log({query, options});
// TODO;
return [{
text: "__TEST__"
}]
}
applyTemplateVariables(query: RocksetQuery, scopedVars: ScopedVars): Record<string, any> {
const templateSrv = getTemplateSrv();
return {
...query,
queryText: query.queryText ? templateSrv.replace(query.queryText, scopedVars) : '',
};
}
getDefaultQuery(_: CoreApp): Partial<RocksetQuery> {
return DEFAULT_QUERY;
}
}