diff --git a/docs/sources/developers/kinds/core/dashboard/schema-reference.md b/docs/sources/developers/kinds/core/dashboard/schema-reference.md index 60738bb0907..958fba1d097 100644 --- a/docs/sources/developers/kinds/core/dashboard/schema-reference.md +++ b/docs/sources/developers/kinds/core/dashboard/schema-reference.md @@ -195,11 +195,12 @@ Sensitive information stripped: queries (metric, template,annotation) and panel Time picker configuration It defines the default config for the time picker and the refresh picker for the specific dashboard. -| Property | Type | Required | Default | Description | -|---------------------|----------|----------|---------------------------------------|---------------------------------------------------------------------------------------------------| -| `hidden` | boolean | **Yes** | `false` | Whether timepicker is visible or not. | -| `refresh_intervals` | string[] | **Yes** | `[5s 10s 30s 1m 5m 15m 30m 1h 2h 1d]` | Interval options available in the refresh picker dropdown. | -| `time_options` | string[] | **Yes** | `[5m 15m 1h 6h 12h 24h 2d 7d 30d]` | Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard. | +| Property | Type | Required | Default | Description | +|---------------------|----------|----------|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------| +| `hidden` | boolean | **Yes** | `false` | Whether timepicker is visible or not. | +| `refresh_intervals` | string[] | **Yes** | `[5s 10s 30s 1m 5m 15m 30m 1h 2h 1d]` | Interval options available in the refresh picker dropdown. | +| `time_options` | string[] | **Yes** | `[5m 15m 1h 6h 12h 24h 2d 7d 30d]` | Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard. | +| `nowDelay` | string | No | | Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values. | ### Panels diff --git a/kinds/dashboard/dashboard_kind.cue b/kinds/dashboard/dashboard_kind.cue index 4a30d6866b8..d00e41ce12d 100644 --- a/kinds/dashboard/dashboard_kind.cue +++ b/kinds/dashboard/dashboard_kind.cue @@ -454,6 +454,8 @@ lineage: schemas: [{ refresh_intervals: [...string] | *["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"] // Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard. time_options: [...string] | *["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"] + // Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values. + nowDelay?: string } @cuetsy(kind="interface") @grafana(TSVeneer="type") // 0 for no shared crosshair or tooltip (default). diff --git a/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts b/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts index 44c982655e7..b4956e659cb 100644 --- a/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts +++ b/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts @@ -638,6 +638,10 @@ export interface TimePickerConfig { * Whether timepicker is visible or not. */ hidden: boolean; + /** + * Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values. + */ + nowDelay?: string; /** * Interval options available in the refresh picker dropdown. */ diff --git a/pkg/kinds/dashboard/dashboard_spec_gen.go b/pkg/kinds/dashboard/dashboard_spec_gen.go index 498784a321b..a2fdbb19e0b 100644 --- a/pkg/kinds/dashboard/dashboard_spec_gen.go +++ b/pkg/kinds/dashboard/dashboard_spec_gen.go @@ -858,6 +858,9 @@ type TimePickerConfig struct { // Whether timepicker is visible or not. Hidden bool `json:"hidden"` + // Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values. + NowDelay *string `json:"nowDelay,omitempty"` + // Interval options available in the refresh picker dropdown. RefreshIntervals []string `json:"refresh_intervals"` diff --git a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts index 540c76baecd..0e051c19809 100644 --- a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts +++ b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts @@ -251,6 +251,7 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel) fiscalYearStartMonth: oldModel.fiscalYearStartMonth, timeZone: oldModel.timezone, weekStart: oldModel.weekStart, + UNSAFE_nowDelay: oldModel.timepicker?.nowDelay, }), $variables: variables, $behaviors: [ diff --git a/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts b/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts index 2cd2edc8828..ccb5f53fc6d 100644 --- a/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts +++ b/public/app/features/dashboard-scene/serialization/transformSceneToSaveModel.ts @@ -127,6 +127,7 @@ export function transformSceneToSaveModel(scene: DashboardScene, isSnapshot = fa ...defaultTimePickerConfig, refresh_intervals, hidden: hideTimePicker, + nowDelay: timeRange.UNSAFE_nowDelay, }, panels, annotations: { diff --git a/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx b/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx index 75185f94a23..b86749abcbb 100644 --- a/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx +++ b/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx @@ -125,7 +125,11 @@ export class GeneralSettingsEditView }; public onNowDelayChange = (value: string) => { - // TODO: Figure out how to store nowDelay in Dashboard Scene + const timeRange = this.getTimeRange(); + + timeRange?.setState({ + UNSAFE_nowDelay: value, + }); }; public onHideTimePickerChange = (value: boolean) => { @@ -146,7 +150,7 @@ export class GeneralSettingsEditView const { navModel, pageNav } = useDashboardEditPageNav(model.getDashboard(), model.getUrlKey()); const { title, description, tags, meta, editable, overlay } = model.getDashboard().useState(); const { sync: graphTooltip } = model.getCursorSync()?.useState() || {}; - const { timeZone, weekStart } = model.getTimeRange().useState(); + const { timeZone, weekStart, UNSAFE_nowDelay: nowDelay } = model.getTimeRange().useState(); const { intervals } = model.getRefreshPicker()?.useState() || {}; const { hideTimeControls } = model.getDashboardControls()?.useState() || {}; @@ -230,8 +234,7 @@ export class GeneralSettingsEditView onLiveNowChange={model.onLiveNowChange} refreshIntervals={intervals} timePickerHidden={hideTimeControls} - // TODO: Implement this in dashboard scene - // nowDelay={timepicker.nowDelay || ''} + nowDelay={nowDelay || ''} // TODO: Implement this in dashboard scene // liveNow={liveNow} liveNow={false}