diff --git a/public/app/features/panel/state/getAllSuggestions.ts b/public/app/features/panel/state/getAllSuggestions.ts index 2ae840213ab..7d33a54c2f7 100644 --- a/public/app/features/panel/state/getAllSuggestions.ts +++ b/public/app/features/panel/state/getAllSuggestions.ts @@ -20,6 +20,7 @@ export const panelsToCheckFirst = [ 'status-history', 'logs', 'candlestick', + 'flamegraph', ]; export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): Promise { diff --git a/public/app/plugins/panel/flamegraph/module.tsx b/public/app/plugins/panel/flamegraph/module.tsx index 3b1600d68b8..432e71da2d2 100644 --- a/public/app/plugins/panel/flamegraph/module.tsx +++ b/public/app/plugins/panel/flamegraph/module.tsx @@ -1,5 +1,6 @@ import { PanelPlugin } from '@grafana/data'; import { FlameGraphPanel } from './FlameGraphPanel'; +import { FlameGraphSuggestionsSupplier } from './suggestions'; -export const plugin = new PanelPlugin(FlameGraphPanel); +export const plugin = new PanelPlugin(FlameGraphPanel).setSuggestionsSupplier(new FlameGraphSuggestionsSupplier()); diff --git a/public/app/plugins/panel/flamegraph/suggestions.ts b/public/app/plugins/panel/flamegraph/suggestions.ts new file mode 100644 index 00000000000..f93733a5bbb --- /dev/null +++ b/public/app/plugins/panel/flamegraph/suggestions.ts @@ -0,0 +1,37 @@ +import { VisualizationSuggestionsBuilder } from '@grafana/data'; +import { config } from '@grafana/runtime'; +import { SuggestionName } from 'app/types/suggestions'; + +import { FlameGraphDataContainer as FlameGraphDataContainer } from './components/FlameGraph/dataTransform'; +import { FlameGraphDataContainer as FlameGraphDataContainerV2 } from './flamegraphV2/components/FlameGraph/dataTransform'; + +export class FlameGraphSuggestionsSupplier { + getListWithDefaults(builder: VisualizationSuggestionsBuilder) { + return builder.getListAppender<{}, {}>({ + name: SuggestionName.FlameGraph, + pluginId: 'flamegraph', + }); + } + + getSuggestionsForData(builder: VisualizationSuggestionsBuilder) { + if (!builder.data) { + return; + } + + // Try to instantiate FlameGraphDataContainer (depending on the version), since the instantiation can fail due + // to the format of the data - meaning that a Flame Graph cannot be used to visualize those data. + // Without this check, a suggestion containing an error is shown to the user. + const dataFrame = builder.data.series[0]; + try { + config.featureToggles.flameGraphV2 + ? new FlameGraphDataContainerV2(dataFrame) + : new FlameGraphDataContainer(dataFrame); + } catch (err) { + return; + } + + this.getListWithDefaults(builder).append({ + name: SuggestionName.FlameGraph, + }); + } +} diff --git a/public/app/types/suggestions.ts b/public/app/types/suggestions.ts index 22889b632d9..95a10a419fc 100644 --- a/public/app/types/suggestions.ts +++ b/public/app/types/suggestions.ts @@ -27,4 +27,5 @@ export enum SuggestionName { TextPanel = 'Text', DashboardList = 'Dashboard list', Logs = 'Logs', + FlameGraph = 'Flame graph', }