Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support grafana in cluster configs #21

Merged
merged 1 commit into from
Feb 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions manifests/cluster.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
# @param ganglia_req_query
# @param ganglia_opt_query
# @param ganglia_version
# @param grafana_host
# @param grafana_org_id
# @param grafana_theme
# @param grafana_dashboard_name
# @param grafana_dashboard_uid
# @param grafana_dashboard_panels
# @param grafana_labels
# @param batch_connect
#
define openondemand::cluster (
Expand Down Expand Up @@ -68,9 +75,29 @@
Hash $ganglia_req_query = {'c' => $name},
Hash $ganglia_opt_query = {'h' => "%{h}.${::domain}"},
String $ganglia_version = '3',
Optional[Variant[Stdlib::HTTPSUrl,Stdlib::HTTPUrl]] $grafana_host = undef,
Integer $grafana_org_id = 1,
Optional[String] $grafana_theme = undef,
Optional[String] $grafana_dashboard_name = undef,
Optional[String] $grafana_dashboard_uid = undef,
Optional[Struct[{
'cpu' => Integer,
'memory' => Integer,
}]] $grafana_dashboard_panels = undef,
Optional[Struct[{
'cluster' => String,
'host' => String,
'jobid' => Optional[String],
}]] $grafana_labels = undef,
Hash[String, Openondemand::Batch_connect] $batch_connect = {},
) {

if $grafana_host {
if $grafana_dashboard_name == undef or $grafana_dashboard_uid == undef or $grafana_dashboard_panels == undef or $grafana_labels == undef {
fail('Must define grafana_dashboard_name, grafana_dashboard_uid, grafana_dashboard_panels and grafana_labels')
}
}

include openondemand

file { "/etc/ood/config/clusters.d/${name}.yml":
Expand Down
49 changes: 48 additions & 1 deletion spec/defines/cluster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'test'
end

let :params do
let :default_params do
{
acls: [
{
Expand Down Expand Up @@ -44,6 +44,8 @@
}
end

let(:params) { default_params }

it do
is_expected.to contain_file('/etc/ood/config/clusters.d/test.yml').with('ensure' => 'file',
'owner' => 'root',
Expand All @@ -55,6 +57,51 @@
content = catalogue.resource('file', '/etc/ood/config/clusters.d/test.yml').send(:parameters)[:content]
puts content
end

context 'with grafana defined' do
let :params do
default_params.merge!(
ganglia_host: nil,
grafana_host: 'https://grafana.domain',
grafana_dashboard_name: 'test',
grafana_dashboard_uid: 'foo',
grafana_dashboard_panels: { 'cpu' => 1, 'memory' => 2 },
grafana_labels: { 'cluster' => 'cluster', 'host' => 'host' },
)
end

it { is_expected.to compile.with_all_deps }

context 'with partial params' do
let :params do
default_params.merge!(
ganglia_host: nil,
grafana_host: 'https://grafana.domain',
)
end

it 'fails with lack of parameters' do
is_expected.to compile.and_raise_error(%r{Must define grafana})
end
end

context 'require cpu and memory panels' do
let :params do
default_params.merge!(
ganglia_host: nil,
grafana_host: 'https://grafana.domain',
grafana_dashboard_name: 'test',
grafana_dashboard_uid: 'foo',
grafana_dashboard_panels: { 'cpu' => 1 },
grafana_labels: { 'cluster' => 'cluster', 'host' => 'host' },
)
end

it 'fails' do
is_expected.to compile.and_raise_error(%r{expects a value for key 'memory'})
end
end
end
end
end
end
18 changes: 18 additions & 0 deletions templates/cluster/main.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ v2:
<%- end -%>
version: "<%= @ganglia_version %>"
<%- end -%>
<%- if @grafana_host -%>
grafana:
host: "<%= @grafana_host %>"
orgId: <%= @grafana_ord_id %>
<%- if @grafana_theme -%>
theme: "<%= @grafana_theme %>"
<%- end -%>
dashboard:
name: "<%= @grafana_dashboard_name %>"
uid: "<%= @grafana_dashboard_uid %>"
panels:
cpu: <%= @grafana_dashboard_panels['cpu'] %>
memory: <%= @grafana_dashboard_panels['memory'] %>
labels:
<%- @grafana_labels.each_pair do |k, v| -%>
<%= k %>: "<%= v %>"
<%- end -%>
<%- end -%>
<% end -%>
<% if ! @batch_connect.empty? -%>
batch_connect:
Expand Down