GeneralSettings: Enable support for nowDelay (#79703)

This commit is contained in:
Ivan Ortega Alba 2024-01-11 17:53:06 +01:00 committed by GitHub
parent d3ff4715a0
commit eb64209301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 9 deletions

View File

@ -195,11 +195,12 @@ Sensitive information stripped: queries (metric, template,annotation) and panel
Time picker configuration Time picker configuration
It defines the default config for the time picker and the refresh picker for the specific dashboard. It defines the default config for the time picker and the refresh picker for the specific dashboard.
| Property | Type | Required | Default | Description | | Property | Type | Required | Default | Description |
|---------------------|----------|----------|---------------------------------------|---------------------------------------------------------------------------------------------------| |---------------------|----------|----------|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `hidden` | boolean | **Yes** | `false` | Whether timepicker is visible or not. | | `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. | | `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. | | `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 ### Panels

View File

@ -454,6 +454,8 @@ lineage: schemas: [{
refresh_intervals: [...string] | *["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"] 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. // 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"] 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") } @cuetsy(kind="interface") @grafana(TSVeneer="type")
// 0 for no shared crosshair or tooltip (default). // 0 for no shared crosshair or tooltip (default).

View File

@ -638,6 +638,10 @@ export interface TimePickerConfig {
* Whether timepicker is visible or not. * Whether timepicker is visible or not.
*/ */
hidden: boolean; 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. * Interval options available in the refresh picker dropdown.
*/ */

View File

@ -858,6 +858,9 @@ type TimePickerConfig struct {
// Whether timepicker is visible or not. // Whether timepicker is visible or not.
Hidden bool `json:"hidden"` 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. // Interval options available in the refresh picker dropdown.
RefreshIntervals []string `json:"refresh_intervals"` RefreshIntervals []string `json:"refresh_intervals"`

View File

@ -251,6 +251,7 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel)
fiscalYearStartMonth: oldModel.fiscalYearStartMonth, fiscalYearStartMonth: oldModel.fiscalYearStartMonth,
timeZone: oldModel.timezone, timeZone: oldModel.timezone,
weekStart: oldModel.weekStart, weekStart: oldModel.weekStart,
UNSAFE_nowDelay: oldModel.timepicker?.nowDelay,
}), }),
$variables: variables, $variables: variables,
$behaviors: [ $behaviors: [

View File

@ -127,6 +127,7 @@ export function transformSceneToSaveModel(scene: DashboardScene, isSnapshot = fa
...defaultTimePickerConfig, ...defaultTimePickerConfig,
refresh_intervals, refresh_intervals,
hidden: hideTimePicker, hidden: hideTimePicker,
nowDelay: timeRange.UNSAFE_nowDelay,
}, },
panels, panels,
annotations: { annotations: {

View File

@ -125,7 +125,11 @@ export class GeneralSettingsEditView
}; };
public onNowDelayChange = (value: string) => { 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) => { public onHideTimePickerChange = (value: boolean) => {
@ -146,7 +150,7 @@ export class GeneralSettingsEditView
const { navModel, pageNav } = useDashboardEditPageNav(model.getDashboard(), model.getUrlKey()); const { navModel, pageNav } = useDashboardEditPageNav(model.getDashboard(), model.getUrlKey());
const { title, description, tags, meta, editable, overlay } = model.getDashboard().useState(); const { title, description, tags, meta, editable, overlay } = model.getDashboard().useState();
const { sync: graphTooltip } = model.getCursorSync()?.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 { intervals } = model.getRefreshPicker()?.useState() || {};
const { hideTimeControls } = model.getDashboardControls()?.useState() || {}; const { hideTimeControls } = model.getDashboardControls()?.useState() || {};
@ -230,8 +234,7 @@ export class GeneralSettingsEditView
onLiveNowChange={model.onLiveNowChange} onLiveNowChange={model.onLiveNowChange}
refreshIntervals={intervals} refreshIntervals={intervals}
timePickerHidden={hideTimeControls} timePickerHidden={hideTimeControls}
// TODO: Implement this in dashboard scene nowDelay={nowDelay || ''}
// nowDelay={timepicker.nowDelay || ''}
// TODO: Implement this in dashboard scene // TODO: Implement this in dashboard scene
// liveNow={liveNow} // liveNow={liveNow}
liveNow={false} liveNow={false}