Skip to content

Commit

Permalink
Merge pull request #29 from rhowe/add-timeshift
Browse files Browse the repository at this point in the history
Add timeFrom and timeShift parameters to stat, table, and timeseries
  • Loading branch information
rhowe authored Feb 24, 2023
2 parents 1a811ed + 159ea4a commit 92aa873
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ docs/api-docs.md
*_test_output.json
e2e/node_modules
.DS_Store

*~
*.orig
*.rej
*.swp
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.0.1 (2023-02-24)

- Add support for manipulating the time window to stat, table, and timeseries
panels via the `timeFrom` and `timeShift` parameters.

## 1.0.0 (2023-02-19)

Bulk changelog update & arbitrary version bump.
Expand Down
6 changes: 6 additions & 0 deletions grafonnet/stat_panel.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* @param repeat (optional) Name of variable that should be used to repeat this panel.
* @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical.
* @param repeatMaxPerRow (optional) How many panels to limit each row to when repeating horizontally.
* @param timeFrom (optional) Override the time window for the panel.
* @param timeShift (optional) Shift the time window for the panel.
* @return A json that represents a stat panel.
*
* @method addTarget(target) Adds a target object.
Expand Down Expand Up @@ -92,6 +94,8 @@
repeat=null,
repeatDirection='h',
repeatMaxPerRow=null,
timeFrom=null,
timeShift=null,
):: {
type: 'stat',
title: title,
Expand Down Expand Up @@ -144,6 +148,8 @@
[if repeat != null then 'repeat']: repeat,
[if repeat != null then 'repeatDirection']: repeatDirection,
[if repeat != null && repeatDirection == 'h' && repeatMaxPerRow != null then 'maxPerRow']: repeatMaxPerRow,
[if timeFrom != null then 'timeFrom']: timeFrom,
[if timeShift != null then 'timeShift']: timeShift,
targets: [],
pluginVersion: '9.2.4',
_nextTarget:: 0,
Expand Down
6 changes: 6 additions & 0 deletions grafonnet/table_panel.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
* @param repeat (optional) Name of variable that should be used to repeat this panel.
* @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical.
* @param repeatMaxPerRow (optional) How many panels to limit each row to when repeating horizontally.
* @param timeFrom (optional) Override the time window for the panel.
* @param timeShift (optional) Shift the time window for the panel.
* @return A json that represents a table panel.
*
* @method addTarget(target) Adds a target object.
Expand Down Expand Up @@ -74,6 +76,8 @@
repeat=null,
repeatDirection='h',
repeatMaxPerRow=null,
timeFrom=null,
timeShift=null,
):: {
type: 'table',
title: title,
Expand Down Expand Up @@ -119,6 +123,8 @@
[if repeat != null then 'repeat']: repeat,
[if repeat != null then 'repeatDirection']: repeatDirection,
[if repeat != null && repeatDirection == 'h' && repeatMaxPerRow != null then 'maxPerRow']: repeatMaxPerRow,
[if timeFrom != null then 'timeFrom']: timeFrom,
[if timeShift != null then 'timeShift']: timeShift,
targets: [],
pluginVersion: '9.2.1',
_nextTarget:: 0,
Expand Down
6 changes: 6 additions & 0 deletions grafonnet/timeseries_panel.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* @param repeat (optional) Name of variable that should be used to repeat this panel.
* @param repeatDirection (default `'h'`) 'h' for horizontal or 'v' for vertical.
* @param repeatMaxPerRow (optional) How many panels to limit each row to when repeating horizontally.
* @param timeFrom (optional) Override the time window for the panel.
* @param timeShift (optional) Shift the time window for the panel.
* @return A json that represents a graph panel.
*
* @method addTarget(target) Adds a target object.
Expand Down Expand Up @@ -109,6 +111,8 @@
repeat=null,
repeatDirection='h',
repeatMaxPerRow=null,
timeFrom=null,
timeShift=null,
):: {
type: 'timeseries',
title: title,
Expand Down Expand Up @@ -195,6 +199,8 @@
[if repeat != null then 'repeat']: repeat,
[if repeat != null then 'repeatDirection']: repeatDirection,
[if repeat != null && repeatDirection == 'h' && repeatMaxPerRow != null then 'maxPerRow']: repeatMaxPerRow,
[if timeFrom != null then 'timeFrom']: timeFrom,
[if timeShift != null then 'timeShift']: timeShift,
targets: [],
_nextTarget:: 0,
addThreshold(color, value=null):: self {
Expand Down
4 changes: 4 additions & 0 deletions tests/timeseries_panel/timeseries.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ local overrides = grafana.timeseriesPanel.overrides;
thresholds_are_absolute: std.assertEqual('absolute', dash.fieldConfig.defaults.thresholds.mode),
no_threshold_steps: std.assertEqual([], dash.fieldConfig.defaults.thresholds.steps),
no_overrides: std.assertEqual([], dash.fieldConfig.overrides),
no_time_window_override: std.assertEqual(false, std.objectHas(dash, 'timeFrom')),
no_time_window_shift: std.assertEqual(false, std.objectHas(dash, 'timeShift')),
},
can_set_description: std.assertEqual(
'A description',
Expand All @@ -79,6 +81,8 @@ local overrides = grafana.timeseriesPanel.overrides;
can_map_missing_values: std.assertEqual(123, grafana.timeseriesPanel.new(title='', noValue=123).fieldConfig.defaults.noValue),
can_display_thresholds: std.assertEqual('line', grafana.timeseriesPanel.new(title='', thresholdDisplay='line').fieldConfig.defaults.custom.thresholdsStyle.mode),
thresholds_can_be_percentages: std.assertEqual('percentage', grafana.timeseriesPanel.new(title='', thresholdMode='percentage').fieldConfig.defaults.thresholds.mode),
can_override_time_window: std.assertEqual('3d', grafana.timeseriesPanel.new(title='', timeFrom='3d').timeFrom),
can_shift_time_window: std.assertEqual('24h', grafana.timeseriesPanel.new(title='', timeShift='24h').timeShift),
legend_tests: {
can_hide: std.assertEqual('hidden', grafana.timeseriesPanel.new(title='', legendMode='hidden').options.legend.displayMode),
can_display_as_table: std.assertEqual('table', grafana.timeseriesPanel.new(title='', legendMode='table').options.legend.displayMode),
Expand Down
4 changes: 4 additions & 0 deletions tests/timeseries_panel/timeseries_compiled.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
"can_make_transparent": true,
"can_map_missing_values": true,
"can_override_display_name": true,
"can_override_time_window": true,
"can_set_decimals": true,
"can_set_description": true,
"can_set_fixed_color": true,
"can_set_max": true,
"can_set_min": true,
"can_set_unit": true,
"can_shift_time_window": true,
"check_defaults": {
"axis_auto_placement": true,
"axis_centered_zero": true,
Expand Down Expand Up @@ -56,6 +58,8 @@
"no_repeat": true,
"no_targets": true,
"no_threshold_steps": true,
"no_time_window_override": true,
"no_time_window_shift": true,
"no_value_mappings": true,
"sets_title": true,
"thresholds_are_absolute": true,
Expand Down

0 comments on commit 92aa873

Please sign in to comment.