Skip to content

Commit

Permalink
GeneralSettings: Enable support for nowDelay (grafana#79703)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanortegaalba authored Jan 11, 2024
1 parent d3ff471 commit eb64209
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
11 changes: 6 additions & 5 deletions docs/sources/developers/kinds/core/dashboard/schema-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions kinds/dashboard/dashboard_kind.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 3 additions & 0 deletions pkg/kinds/dashboard/dashboard_spec_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export function transformSceneToSaveModel(scene: DashboardScene, isSnapshot = fa
...defaultTimePickerConfig,
refresh_intervals,
hidden: hideTimePicker,
nowDelay: timeRange.UNSAFE_nowDelay,
},
panels,
annotations: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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() || {};

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit eb64209

Please sign in to comment.