grafana/public/app/features/trails/dashboardIntegration.ts
Torkel Ödegaard 1f1d348e17
DataTrails: Auto query, explore and breakdown/drilldown prototype (#77019)
* First try

* Update

* app with drilldowns

* Progres

* Progress

* update

* Update

* update

* Update

* Update

* Progress

* Update

* Progress

* Update

* Progress

* logs url sync

* related metrics

* Progress

* progress

* Progress

* Update

* Update

* Update

* Update

* Update

* fix

* Update

* update

* Update

* update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* update

* Update

* Update

* Settings

* Update

* Tweaks

* update

* Improve auto queries

* Update

* Update

* Fixes

* Update

* Update

* Update

* fix

* Update

* Removing logs view, cleanup

* Update

* Update

* disabled not implemented buttons

* Update

* Feature toggle on dashboard menu

* remove unused prometheus change

* removed bit

* Fix failing test

* chore: added `/public/app/features/trails/` to CODEOWNERS

* go mod tidy

* go mod tidy

* fix: added missing arg

* Moved panel action

* Moved panel action

---------

Co-authored-by: André Pereira <adrapereira@gmail.com>
Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
2023-11-15 11:28:29 +00:00

39 lines
1.3 KiB
TypeScript

import { PanelMenuItem } from '@grafana/data';
import { getDataSourceSrv } from '@grafana/runtime';
import { VizPanel } from '@grafana/scenes';
import { buildVisualQueryFromString } from 'app/plugins/datasource/prometheus/querybuilder/parsing';
import { DashboardScene } from '../dashboard-scene/scene/DashboardScene';
import { getQueryRunnerFor } from '../dashboard-scene/utils/utils';
import { DataTrailDrawer } from './DataTrailDrawer';
export function addDataTrailPanelAction(dashboard: DashboardScene, vizPanel: VizPanel, items: PanelMenuItem[]) {
const queryRunner = getQueryRunnerFor(vizPanel);
if (!queryRunner) {
return;
}
const ds = getDataSourceSrv().getInstanceSettings(queryRunner.state.datasource);
if (!ds || ds.meta.id !== 'prometheus' || queryRunner.state.queries.length > 1) {
return;
}
const query = queryRunner.state.queries[0];
const parsedResult = buildVisualQueryFromString(query.expr);
if (parsedResult.errors.length > 0) {
return;
}
items.push({
text: 'Data trail',
iconClassName: 'code-branch',
onClick: () => {
dashboard.showModal(
new DataTrailDrawer({ query: parsedResult.query, dsRef: ds, timeRange: dashboard.state.$timeRange!.clone() })
);
},
shortcut: 'p s',
});
}