The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/query/state/DashboardQueryRunner/AnnotationsQueryRunner.ts

33 lines
1.2 KiB

import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { AnnotationEvent, DataSourceApi } from '@grafana/data';
import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types';
import { PanelModel } from '../../../dashboard/state';
import { executeAnnotationQuery } from '../../../annotations/executeAnnotationQuery';
import { handleAnnotationQueryRunnerError } from './utils';
export class AnnotationsQueryRunner implements AnnotationQueryRunner {
canRun(datasource?: DataSourceApi): boolean {
if (!datasource) {
return false;
}
return !Boolean(datasource.annotationQuery && !datasource.annotations);
}
run({ annotation, datasource, dashboard, range }: AnnotationQueryRunnerOptions): Observable<AnnotationEvent[]> {
if (!this.canRun(datasource)) {
return of([]);
}
const panel: PanelModel = {} as unknown as PanelModel; // deliberate setting panel to empty object because executeAnnotationQuery shouldn't depend on panelModel
return executeAnnotationQuery({ dashboard, range, panel }, datasource!, annotation).pipe(
map((result) => {
return result.events ?? [];
}),
catchError(handleAnnotationQueryRunnerError)
);
}
}