Skip to content

Commit

Permalink
Simpler API for Grizzly resources (grafana#635)
Browse files Browse the repository at this point in the history
* Simpler API for Grizzly resources

* lint, and add necessary resource.libsonnet
  • Loading branch information
malcolmholmes authored Aug 23, 2021
1 parent 0d13e5b commit 763787b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions grizzly/check.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local resource = import 'resource.libsonnet';
{
new(type, name, check)::
resource.new('SyntheticMonitoringCheck', name)
+ resource.addMetadata('type', type)
+ resource.withSpec(check),
}
21 changes: 21 additions & 0 deletions grizzly/grafana.libsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local resource = import 'resource.libsonnet';
local util = import 'util.libsonnet';

{
Expand All @@ -18,4 +19,24 @@ local util = import 'util.libsonnet';
}
for key in std.objectFields(mixins)
},

dashboard: {
new(name, dashboard_json)::
resource.new('Dashboard', name)
+ resource.withSpec(dashboard_json),
},

folder: {
new(name, title)::
resource.new('DashboardFolder', name)
+ resource.withSpec({
title: title,
}),
},

datasource: {
new(name, datasource_json)::
resource.new('Datasource', name)
+ resource.withSpec(datasource_json),
},
}
8 changes: 8 additions & 0 deletions grizzly/grizzly.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ local prometheus = import 'prometheus.libsonnet';
+ prometheus.fromMapsFiltered(main.prometheusRules, mixinRules)
+ prometheus.fromMixins(main.mixins),
},

resource: (import 'resource.libsonnet'),
dashboard: grafana.dashboard,
folder: grafana.folder,
datasource: grafana.datasource,
rule_group: prometheus.rule_group,
synthetic_monitoring_check: (import 'check.libsonnet'),

}
9 changes: 9 additions & 0 deletions grizzly/prometheus.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local util = import 'util.libsonnet';
local kind = 'PrometheusRuleGroup';
local recordingRules = 'prometheusRules';
local alertRules = 'prometheusAlerts';
local resource = import 'resource.libsonnet';

{
getMixinRuleNames(mixins)::
local flatMixins = [mixins[key] for key in std.objectFieldsAll(mixins)];
Expand All @@ -27,4 +29,11 @@ local alertRules = 'prometheusAlerts';
)
for key in std.objectFields(mixins)
},

rule_group: {
new(namespace, name, group)::
resource.new('PrometheusRuleGroup', name)
+ resource.addMetadata('namespace', namespace)
+ resource.withSpec(group),
},
}
22 changes: 22 additions & 0 deletions grizzly/resource.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
defaultApiVersion:: 'grizzly.grafana.com/v1alpha1',
new(kind, name):: {
apiVersion: $.defaultApiVersion,
kind: kind,
metadata: {
name: name,
},
},
withApiVersion(apiVersion):: {
defaultApiVersion:: apiVersion,
apiVersion: apiVersion,
},
addMetadata(name, value):: {
metadata+: {
[name]: value,
},
},
withSpec(spec):: {
spec: spec,
},
}

0 comments on commit 763787b

Please sign in to comment.