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

Create subpaths for provisioning_datasources #362

Merged
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
17 changes: 13 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The following parameters are available in the `grafana` class:
* [`repo_release`](#-grafana--repo_release)
* [`repo_url`](#-grafana--repo_url)
* [`plugins`](#-grafana--plugins)
* [`provisioning_dir`](#-grafana--provisioning_dir)
* [`provisioning_dashboards`](#-grafana--provisioning_dashboards)
* [`provisioning_datasources`](#-grafana--provisioning_datasources)
* [`provisioning_dashboards_file`](#-grafana--provisioning_dashboards_file)
Expand Down Expand Up @@ -251,6 +252,14 @@ Plugins to be passed to `create_resources`, wraps around the

Default value: `{}`

##### <a name="-grafana--provisioning_dir"></a>`provisioning_dir`

Data type: `Stdlib::Absolutepath`

Path to the grafana provisioning dir e.g /etc/grafana/provisioning

Default value: `'/etc/grafana/provisioning'`

##### <a name="-grafana--provisioning_dashboards"></a>`provisioning_dashboards`

Data type: `Hash`
Expand All @@ -273,21 +282,21 @@ Default value: `{}`

##### <a name="-grafana--provisioning_dashboards_file"></a>`provisioning_dashboards_file`

Data type: `String`
Data type: `Stdlib::Absolutepath`

Fully qualified path to place the provisioning file
for dashboards, only used if provisioning_dashboards is specified.

Default value: `'/etc/grafana/provisioning/dashboards/puppetprovisioned.yaml'`
Default value: `"${provisioning_dir}/dashboards/puppetprovisioned.yaml"`

##### <a name="-grafana--provisioning_datasources_file"></a>`provisioning_datasources_file`

Data type: `String`
Data type: `Stdlib::Absolutepath`

Fully qualified path to place the provisioning file
for datasources, only used if provisioning_datasources is specified.

Default value: `'/etc/grafana/provisioning/datasources/puppetprovisioned.yaml'`
Default value: `"${provisioning_dir}/datasources/puppetprovisioned.yaml"`

##### <a name="-grafana--create_subdirs_provisioning"></a>`create_subdirs_provisioning`

Expand Down
1 change: 1 addition & 0 deletions data/family/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
grafana::cfg_location: '/usr/local/etc/grafana.ini'
grafana::provisioning_dir: '/usr/local/etc/grafana/provisioning'
grafana::data_dir: '/var/db/grafana'
grafana::install_method: 'repo'
grafana::manage_package_repo: false
Expand Down
11 changes: 11 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@
if (length($pdatasources) >= 1) {
# template uses:
# - pdatasources

$datasources_provisioning_dir = "${grafana::provisioning_dir}/datasources"

file { $datasources_provisioning_dir:
ensure => directory,
owner => 'grafana',
group => 'grafana',
mode => '0750',
before => File[$grafana::provisioning_datasources_file],
}

file { $grafana::provisioning_datasources_file:
ensure => file,
owner => 'grafana',
Expand Down
8 changes: 6 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
# Plugins to be passed to `create_resources`, wraps around the
# `grafana_plugin` resource.
#
# @param provisioning_dir
# Path to the grafana provisioning dir e.g /etc/grafana/provisioning
#
# @param provisioning_dashboards
# Dashboards to provision into grafana. grafana > v5.0.0
# required. Will be converted into YAML and used by grafana to
Expand Down Expand Up @@ -167,8 +170,9 @@
Hash $plugins = {},
Hash $provisioning_dashboards = {},
Hash $provisioning_datasources = {},
String $provisioning_dashboards_file = '/etc/grafana/provisioning/dashboards/puppetprovisioned.yaml',
String $provisioning_datasources_file = '/etc/grafana/provisioning/datasources/puppetprovisioned.yaml',
Stdlib::Absolutepath $provisioning_dir = '/etc/grafana/provisioning',
Stdlib::Absolutepath $provisioning_dashboards_file = "${provisioning_dir}/dashboards/puppetprovisioned.yaml",
Stdlib::Absolutepath $provisioning_datasources_file = "${provisioning_dir}/datasources/puppetprovisioned.yaml",
Boolean $create_subdirs_provisioning = false,
Optional[Hash] $sysconfig = undef,
Hash[String[1], Hash] $ldap_servers = {},
Expand Down
45 changes: 45 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,51 @@ class { 'grafana':
apply_manifest(pp, catch_changes: true)
end
end

context 'with fancy dashboard config and custom target file and create_subdirs_provisioning' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'grafana':
version => "#{grafana_version}",
create_subdirs_provisioning => true,
provisioning_datasources => {
apiVersion => 1,
datasources => [
{
name => 'Prometheus',
type => 'prometheus',
access => 'proxy',
url => 'http://localhost:9090/prometheus',
isDefault => false,
},
],
},
provisioning_dashboards => {
apiVersion => 1,
providers => [
{
name => 'default',
orgId => 1,
folder => '',
type => 'file',
disableDeletion => true,
options => {
path => '/var/lib/grafana/dashboards',
puppetsource => 'puppet:///modules/my_custom_module/dashboards',
},
},
],
},
provisioning_dashboards_file => '/etc/grafana/provisioning/dashboards/dashboard.yaml',
provisioning_datasources_file => '/etc/grafana/provisioning/datasources/datasources.yaml'
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
end
end
end

Expand Down
36 changes: 36 additions & 0 deletions spec/classes/grafana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,42 @@
end
end

context 'provisioning_datasources defined' do
let(:params) do
{
version: '11.0.0',
provisioning_datasources: {
apiVersion: 1,
datasources: [
{
name: 'Prometheus',
type: 'prometheus',
access: 'proxy',
url: 'http://localhost:9090/',
isDefault: true,
}
]
}
}
end

it do
puppetprovisioned_datasources_path = case facts[:osfamily]
when 'FreeBSD'
'/usr/local/etc/grafana/provisioning/datasources/puppetprovisioned.yaml'
else
'/etc/grafana/provisioning/datasources/puppetprovisioned.yaml'
end

expect(subject).to contain_file(puppetprovisioned_datasources_path).with(
ensure: 'file',
owner: 'grafana',
group: 'grafana',
mode: '0640'
)
end
end

context 'sysconfig environment variables' do
let(:params) do
{
Expand Down
Loading