LegacyAnnotationQueryRunner.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import { from, Observable, of } from 'rxjs';
  2. import { catchError } from 'rxjs/operators';
  3. import { AnnotationEvent, DataSourceApi } from '@grafana/data';
  4. import { shouldUseLegacyRunner } from 'app/features/annotations/standardAnnotationSupport';
  5. import { AnnotationQueryRunner, AnnotationQueryRunnerOptions } from './types';
  6. import { handleAnnotationQueryRunnerError } from './utils';
  7. export class LegacyAnnotationQueryRunner implements AnnotationQueryRunner {
  8. canRun(datasource?: DataSourceApi): boolean {
  9. if (!datasource) {
  10. return false;
  11. }
  12. if (shouldUseLegacyRunner(datasource)) {
  13. return true;
  14. }
  15. return Boolean(datasource.annotationQuery && !datasource.annotations);
  16. }
  17. run({ annotation, datasource, dashboard, range }: AnnotationQueryRunnerOptions): Observable<AnnotationEvent[]> {
  18. if (!this.canRun(datasource)) {
  19. return of([]);
  20. }
  21. return from(datasource!.annotationQuery!({ range, rangeRaw: range.raw, annotation, dashboard })).pipe(
  22. catchError(handleAnnotationQueryRunnerError)
  23. );
  24. }
  25. }