migrateAnnotation.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { AnnotationQuery } from '@grafana/data';
  2. import { AzureMonitorQuery, AzureQueryType } from '../types';
  3. // The old Angular annotations editor put some properties (rawQuery, workspace, subscription)
  4. // on the root annotation object, rather than down in the 'targets' query value
  5. // This migration moves them to a Log Analytics query compatible with the React query editor
  6. // The old Angular annotations editor did not support any other query types.
  7. export default function migrateAnnotation(annotation: AnnotationQuery<AzureMonitorQuery>) {
  8. const oldQuery = typeof annotation.rawQuery === 'string' ? annotation.rawQuery : null;
  9. const oldWorkspace = typeof annotation.workspace === 'string' ? annotation.workspace : null;
  10. if (!(oldQuery && oldWorkspace && !annotation.target?.azureLogAnalytics?.query)) {
  11. return annotation;
  12. }
  13. const newQuery: AzureMonitorQuery = {
  14. ...(annotation.target ?? {}),
  15. refId: annotation.target?.refId ?? 'Anno',
  16. queryType: AzureQueryType.LogAnalytics,
  17. azureLogAnalytics: {
  18. query: oldQuery,
  19. resource: oldWorkspace,
  20. },
  21. };
  22. return {
  23. ...annotation,
  24. rawQuery: undefined,
  25. workspace: undefined,
  26. subscription: undefined,
  27. queryType: undefined,
  28. target: newQuery,
  29. };
  30. }