mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Graph Panel: Add feature toggle that will allow automatic migration to timeseries panel (#50631)
This commit is contained in:
parent
b6f97e8101
commit
ae8dd73770
@ -55,6 +55,7 @@ export interface FeatureToggles {
|
|||||||
traceToMetrics?: boolean;
|
traceToMetrics?: boolean;
|
||||||
prometheusStreamingJSONParser?: boolean;
|
prometheusStreamingJSONParser?: boolean;
|
||||||
validateDashboardsOnSave?: boolean;
|
validateDashboardsOnSave?: boolean;
|
||||||
|
autoMigrateGraphPanels?: boolean;
|
||||||
prometheusWideSeries?: boolean;
|
prometheusWideSeries?: boolean;
|
||||||
canvasPanelNesting?: boolean;
|
canvasPanelNesting?: boolean;
|
||||||
cloudMonitoringExperimentalUI?: boolean;
|
cloudMonitoringExperimentalUI?: boolean;
|
||||||
|
@ -221,6 +221,12 @@ var (
|
|||||||
State: FeatureStateAlpha,
|
State: FeatureStateAlpha,
|
||||||
RequiresRestart: true,
|
RequiresRestart: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "autoMigrateGraphPanels",
|
||||||
|
Description: "Replace the angular graph panel with timeseries",
|
||||||
|
State: FeatureStateBeta,
|
||||||
|
FrontendOnly: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "prometheusWideSeries",
|
Name: "prometheusWideSeries",
|
||||||
Description: "Enable wide series responses in the Prometheus datasource",
|
Description: "Enable wide series responses in the Prometheus datasource",
|
||||||
|
@ -163,6 +163,10 @@ const (
|
|||||||
// Validate dashboard JSON POSTed to api/dashboards/db
|
// Validate dashboard JSON POSTed to api/dashboards/db
|
||||||
FlagValidateDashboardsOnSave = "validateDashboardsOnSave"
|
FlagValidateDashboardsOnSave = "validateDashboardsOnSave"
|
||||||
|
|
||||||
|
// FlagAutoMigrateGraphPanels
|
||||||
|
// Replace the angular graph panel with timeseries
|
||||||
|
FlagAutoMigrateGraphPanels = "autoMigrateGraphPanels"
|
||||||
|
|
||||||
// FlagPrometheusWideSeries
|
// FlagPrometheusWideSeries
|
||||||
// Enable wide series responses in the Prometheus datasource
|
// Enable wide series responses in the Prometheus datasource
|
||||||
FlagPrometheusWideSeries = "prometheusWideSeries"
|
FlagPrometheusWideSeries = "prometheusWideSeries"
|
||||||
|
@ -163,6 +163,8 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
|||||||
|
|
||||||
libraryPanel?: { uid: undefined; name: string } | PanelModelLibraryPanel;
|
libraryPanel?: { uid: undefined; name: string } | PanelModelLibraryPanel;
|
||||||
|
|
||||||
|
autoMigrateFrom?: string;
|
||||||
|
|
||||||
// non persisted
|
// non persisted
|
||||||
isViewing = false;
|
isViewing = false;
|
||||||
isEditing = false;
|
isEditing = false;
|
||||||
@ -222,6 +224,12 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
|||||||
(this as any)[property] = model[property];
|
(this as any)[property] = model[property];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special 'graph' migration logic
|
||||||
|
if (this.type === 'graph' && config?.featureToggles?.autoMigrateGraphPanels) {
|
||||||
|
this.autoMigrateFrom = this.type;
|
||||||
|
this.type = 'timeseries';
|
||||||
|
}
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
defaultsDeep(this, cloneDeep(defaults));
|
defaultsDeep(this, cloneDeep(defaults));
|
||||||
|
|
||||||
@ -368,6 +376,18 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
const version = getPluginVersion(plugin);
|
const version = getPluginVersion(plugin);
|
||||||
|
|
||||||
|
if (this.autoMigrateFrom) {
|
||||||
|
const wasAngular = this.autoMigrateFrom === 'graph';
|
||||||
|
this.callPanelTypeChangeHandler(
|
||||||
|
plugin,
|
||||||
|
this.autoMigrateFrom,
|
||||||
|
this.getOptionsToRemember(), // old options
|
||||||
|
wasAngular
|
||||||
|
);
|
||||||
|
|
||||||
|
delete this.autoMigrateFrom;
|
||||||
|
}
|
||||||
|
|
||||||
if (plugin.onPanelMigration) {
|
if (plugin.onPanelMigration) {
|
||||||
if (version !== this.pluginVersion) {
|
if (version !== this.pluginVersion) {
|
||||||
this.options = plugin.onPanelMigration(this);
|
this.options = plugin.onPanelMigration(this);
|
||||||
@ -401,6 +421,19 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let panel plugins inspect options from previous panel and keep any that it can use
|
||||||
|
private callPanelTypeChangeHandler(
|
||||||
|
newPlugin: PanelPlugin,
|
||||||
|
oldPluginId: string,
|
||||||
|
oldOptions: any,
|
||||||
|
wasAngular: boolean
|
||||||
|
) {
|
||||||
|
if (newPlugin.onPanelTypeChanged) {
|
||||||
|
const prevOptions = wasAngular ? { angular: oldOptions } : oldOptions.options;
|
||||||
|
Object.assign(this.options, newPlugin.onPanelTypeChanged(this, oldPluginId, prevOptions, this.fieldConfig));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
changePlugin(newPlugin: PanelPlugin) {
|
changePlugin(newPlugin: PanelPlugin) {
|
||||||
const pluginId = newPlugin.meta.id;
|
const pluginId = newPlugin.meta.id;
|
||||||
const oldOptions: any = this.getOptionsToRemember();
|
const oldOptions: any = this.getOptionsToRemember();
|
||||||
@ -415,11 +448,8 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
|||||||
this.clearPropertiesBeforePluginChange();
|
this.clearPropertiesBeforePluginChange();
|
||||||
this.restorePanelOptions(pluginId);
|
this.restorePanelOptions(pluginId);
|
||||||
|
|
||||||
// Let panel plugins inspect options from previous panel and keep any that it can use
|
// Potentially modify current options
|
||||||
if (newPlugin.onPanelTypeChanged) {
|
this.callPanelTypeChangeHandler(newPlugin, oldPluginId, oldOptions, wasAngular);
|
||||||
const prevOptions = wasAngular ? { angular: oldOptions } : oldOptions.options;
|
|
||||||
Object.assign(this.options, newPlugin.onPanelTypeChanged(this, oldPluginId, prevOptions, prevFieldConfig));
|
|
||||||
}
|
|
||||||
|
|
||||||
// switch
|
// switch
|
||||||
this.type = pluginId;
|
this.type = pluginId;
|
||||||
|
Loading…
Reference in New Issue
Block a user