mirror of https://github.com/grafana/grafana
Dashboard: Add suggestion box for Flame Graph (#70763)
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>pull/65241/head
parent
927393633c
commit
d31e96104a
@ -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()); |
||||
|
@ -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, |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue