Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions grafonnet/grafana.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
gaugePanel:: import 'gauge_panel.libsonnet',
barGaugePanel:: import 'bar_gauge_panel.libsonnet',
statPanel:: import 'stat_panel.libsonnet',
transformation:: import 'transformation.libsonnet',
}
6 changes: 6 additions & 0 deletions grafonnet/table_panel.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* @method addColumn(field, style) Adds a column
* @method hideColumn(field) Hides a column
* @method addLink(link) Adds a link
* @method addTransformation(transformation) Adds a transformation object
* @method addTransformations(transformations) Adds an array of transformations
*/
new(
title,
Expand Down Expand Up @@ -81,5 +83,9 @@
addLink(link):: self {
links+: [link],
},
addTransformation(transformation):: self {
transformations+: [transformation],
},
addTransformations(transformations):: std.foldl(function(p, t) p.addTransformation(t), transformations, self),
},
}
12 changes: 12 additions & 0 deletions grafonnet/transformation.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
/**
* @name transformation.new
*/
new(
id='',
options={}
):: {
id: id,
options: options,
},
}
40 changes: 40 additions & 0 deletions tests/table_panel/test.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local grafana = import 'grafonnet/grafana.libsonnet';
local tablePanel = grafana.tablePanel;
local transformation = grafana.transformation;

{
basic: tablePanel.new(
Expand Down Expand Up @@ -46,6 +47,45 @@ local tablePanel = grafana.tablePanel;
tablePanel.new('with batch targets', span=12)
.addTargets([{ a: 'foo' }, { b: 'foo' }]),
],
transformations:
[
tablePanel.new('with transformations', span=12)
.addTransformation(transformation.new('seriesToColumns', options={
byField: 'instance',
}))
.addTransformation(transformation.new('filterFieldsByName', options={
include: {
names: [
'instance',
],
},
})),
tablePanel.new('with batch transformations', span=12)
.addTransformations([
transformation.new('filterFieldsByName', options={
include: {
names: [
'instance',
'nodename',
'Value #D',
'Value #B',
'Value #C',
'Value #E',
'Value #F',
'Value #G',
'Value #H',
'Value #I',
'Value #J',
'Value #K',
'Value #L',
],
},
}),
transformation.new('seriesToColumns', options={
byField: 'instance',
}),
]),
],
hideColumns: tablePanel.new(
'test',
span=12,
Expand Down
74 changes: 74 additions & 0 deletions tests/table_panel/test_compiled.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,79 @@
"title": "with batch targets",
"type": "table"
}
],
"transformations": [
{
"columns": [ ],
"datasource": null,
"links": [ ],
"span": 12,
"styles": [ ],
"targets": [ ],
"timeFrom": null,
"timeShift": null,
"title": "with transformations",
"transformations": [
{
"id": "seriesToColumns",
"options": {
"byField": "instance"
}
},
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"instance"
]
}
}
}
],
"type": "table"
},
{
"columns": [ ],
"datasource": null,
"links": [ ],
"span": 12,
"styles": [ ],
"targets": [ ],
"timeFrom": null,
"timeShift": null,
"title": "with batch transformations",
"transformations": [
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"instance",
"nodename",
"Value #D",
"Value #B",
"Value #C",
"Value #E",
"Value #F",
"Value #G",
"Value #H",
"Value #I",
"Value #J",
"Value #K",
"Value #L"
]
}
}
},
{
"id": "seriesToColumns",
"options": {
"byField": "instance"
}
}
],
"type": "table"
}
]
}
11 changes: 11 additions & 0 deletions tests/transformation/test.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local grafana = import 'grafonnet/grafana.libsonnet';
local transformation = grafana.transformation;

{
basic: transformation.new(),
advanced: transformation.new(
'seriesToColumns', options={
byField: 'instance',
}
),
}
12 changes: 12 additions & 0 deletions tests/transformation/test_compiled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"advanced": {
"id": "seriesToColumns",
"options": {
"byField": "instance"
}
},
"basic": {
"id": "",
"options": { }
}
}