16 changes: 13 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,29 @@ You can install all needed gems for spec tests into the modules directory by
running:

```sh
bundle install --path .vendor/ --without development system_tests release --jobs "$(nproc)"
bundle config set --local path '.vendor/'
bundle config set --local without 'development system_tests release'
bundle install --jobs "$(nproc)"
```

If you also want to run acceptance tests:

```sh
bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)"
bundle config set --local path '.vendor/'
bundle config set --local without 'development release'
bundle config set --local with 'system_tests'
bundle install --jobs "$(nproc)"
```

Our all in one solution if you don't know if you need to install or update gems:

```sh
bundle install --path .vendor/ --with system_tests --without development release --jobs "$(nproc)"; bundle update; bundle clean
bundle config set --local path '.vendor/'
bundle config set --local without 'development release'
bundle config set --local with 'system_tests'
bundle install --jobs "$(nproc)"
bundle update
bundle clean
```

As an alternative to the `--jobs "$(nproc)` parameter, you can set an
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

name: CI

on: pull_request
on:
pull_request: {}
push:
branches:
- main
- master

concurrency:
group: ${{ github.ref_name }}
Expand All @@ -13,6 +18,6 @@ concurrency:
jobs:
puppet:
name: Puppet
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v1
uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v2
with:
pidfile_workaround: 'false'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
release:
name: Release
uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v1
uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v2
with:
allowed_owner: 'voxpupuli'
secrets:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
.*.sw?
/.yardoc/
/Guardfile
bolt-debug.log
.rerun.json
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

modulesync_config_version: '7.0.0'
modulesync_config_version: '7.5.0'
1 change: 1 addition & 0 deletions .pmtignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
/.yardoc/
/.yardopts
/Dockerfile
/HISTORY.md
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

inherit_from: .rubocop_todo.yml
inherit_gem:
voxpupuli-test: rubocop.yml
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v13.2.0](https://github.com/voxpupuli/puppet-grafana/tree/v13.2.0) (2024-05-24)

[Full Changelog](https://github.com/voxpupuli/puppet-grafana/compare/v13.1.0...v13.2.0)

**Implemented enhancements:**

- Support Grafana 10.x [\#348](https://github.com/voxpupuli/puppet-grafana/pull/348) ([treydock](https://github.com/treydock))

**Fixed bugs:**

- Remove legacy top-scope syntax [\#344](https://github.com/voxpupuli/puppet-grafana/pull/344) ([smortex](https://github.com/smortex))

## [v13.1.0](https://github.com/voxpupuli/puppet-grafana/tree/v13.1.0) (2023-10-31)

[Full Changelog](https://github.com/voxpupuli/puppet-grafana/compare/v13.0.1...v13.1.0)
Expand Down
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

8 changes: 3 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ group :test do
gem 'voxpupuli-test', '~> 7.0', :require => false
gem 'coveralls', :require => false
gem 'simplecov-console', :require => false
gem 'puppet_metadata', '~> 3.0', :require => false
gem 'puppet_metadata', '~> 3.5', :require => false
gem 'toml', :require => false
end

Expand All @@ -17,13 +17,11 @@ group :development do
end

group :system_tests do
gem 'voxpupuli-acceptance', '~> 2.0', :require => false
gem 'voxpupuli-acceptance', '~> 3.0', :require => false
end

group :release do
gem 'github_changelog_generator', '>= 1.16.1', :require => false
gem 'voxpupuli-release', '~> 3.0', :require => false
gem 'faraday-retry', '~> 2.1', :require => false
gem 'voxpupuli-release', '~> 3.0', :require => false
end

gem 'rake', :require => false
Expand Down
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Installs and configures Grafana.
##### Using the Class

```puppet
class { '::grafana':
class { 'grafana':
install_method => 'docker',
}
```
Expand Down
45 changes: 34 additions & 11 deletions lib/puppet/provider/grafana_team/grafana.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def team
def map_preferences(preferences)
{
theme: preferences['theme'],
home_dashboard: preferences['homeDashboardId'],
home_dashboard: preferences['homeDashboardId'] || preferences['homeDashboardUID'],
timezone: preferences['timezone']
}
end
Expand All @@ -94,12 +94,16 @@ def preferences

def setup_save_preferences_data
endpoint = format('%s/teams/%s/preferences', resource[:grafana_api_path], @team[:id])
dash = get_dashboard(resource[:home_dashboard], resource[:home_dashboard_folder])
dash = get_dashboard(resource[:home_dashboard], resource[:home_dashboard_folder], true)
request_data = {
theme: resource[:theme],
homeDashboardId: dash[:id],
timezone: resource[:timezone]
}
if major_version >= 10
request_data[:homeDashboardUID] = dash[:uid]
else
request_data[:homeDashboardId] = dash[:id]
end
['PUT', endpoint, request_data]
end

Expand All @@ -123,7 +127,7 @@ def set_current_organization

def home_dashboard_folder
preferences unless @preferences
dash = get_dashboard(@preferences[:home_dashboard])
dash = get_dashboard(@preferences[:home_dashboard], nil)
return dash[:folder_name] if dash

nil
Expand All @@ -136,7 +140,7 @@ def home_dashboard_folder=(value)

def home_dashboard
preferences unless @preferences
dash = get_dashboard(@preferences[:home_dashboard])
dash = get_dashboard(@preferences[:home_dashboard], nil)
return dash[:name] if dash

nil
Expand All @@ -147,30 +151,48 @@ def home_dashboard=(value)
save_preferences
end

def setup_search_path(ident, folder_id = nil)
query = if ident.is_a?(Numeric) || ident.match(%r{/^[0-9]*$/})
def version
return if @version

response = send_request('GET', format('%s/health', resource[:grafana_api_path]))
data = parse_response(response.body)
@version = data['version']
end

def major_version
version unless @version
@version.split('.').first.to_i
end

def setup_search_path(ident, folder_id = nil, search = false)
query = if search
{
query: ident,
type: 'dash-db'
}
elsif ident.is_a?(Numeric) || ident.match(%r{/^[0-9]*$/})
{
dashboardIds: ident,
type: 'dash-db'
}
else
{
query: ident,
dashboardUIDs: ident,
type: 'dash-db'
}
end
query[:folderIds] = folder_id unless folder_id.nil?
query
end

def get_dashboard(ident, folder = nil)
def get_dashboard(ident, folder = nil, search = false)
set_current_organization
return { id: 0, name: 'Default' } if ident == 0 # rubocop:disable Style/NumericPredicate
return { id: 0, name: 'Default' } if ident == 0 || ident.nil? # rubocop:disable Style/NumericPredicate

folder_id = nil
folder_id = get_dashboard_folder_id(folder) unless folder.nil?

search_path = setup_search_path(ident, folder_id)
search_path = setup_search_path(ident, folder_id, search)
response = send_request('GET', format('%s/search', resource[:grafana_api_path]), nil, search_path)
raise_on_error(response.code, format('Fail to retrieve dashboars (HTTP response: %s/%s)', response.code, response.body))

Expand All @@ -183,6 +205,7 @@ def format_dashboard(dashboard)

{
id: dashboard.first['id'],
uid: dashboard.first['uid'],
name: dashboard.first['title'],
folder_uid: dashboard.first['folderUid'],
folder_name: dashboard.first['folderTitle'],
Expand Down
7 changes: 6 additions & 1 deletion lib/puppet/type/grafana_folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@
newproperty(:permissions, array_matching: :all) do
desc 'The permissions of the folder'
def insync?(is)
is.sort_by { |k| k['permission'] } == should.sort_by { |k| k['permission'] }
# Doing sort_by on array of values from each Hash was producing
# inconsistent results where Puppet would think changes were necessary when
# not actually necessary
is_m = is.map { |p| p.keys.sort.map { |k| p[k] }.join('-') }
should_m = should.map { |p| p.keys.sort.map { |k| p[k] }.join('-') }
is_m.sort == should_m.sort
end
end

Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
# The whole grafana configuration
#
# @example Using the Class
# class { '::grafana':
# class { 'grafana':
# install_method => 'docker',
# }
#
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-grafana",
"version": "13.1.0",
"version": "13.2.0",
"author": "Vox Pupuli",
"summary": "This module provides Grafana, a dashboard and graph editor for Graphite and InfluxDB.",
"license": "Apache-2.0",
Expand Down
7 changes: 6 additions & 1 deletion spec/acceptance/grafana_team_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ class { 'grafana':
it 'has set default home dashboard' do
shell('curl --user admin:admin http://localhost:3000/api/teams/1/preferences') do |f|
data = JSON.parse(f.stdout)
expect(data).to include('homeDashboardId' => 0)
# preferences are empty by default in Grafana 10
if grafana_version =~ %r{^(8|9)}
expect(data).to include('homeDashboardId' => 0)
else
expect(data).to be_empty
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/grafana_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ class { 'grafana':
it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-PUPPET
grafana_user { 'admin1':
grafana_user { 'user1':
ensure => absent,
grafana_url => 'http://localhost:3000',
grafana_user => 'user1',
grafana_password => 'newpassword',
grafana_user => 'admin1',
grafana_password => 'Admin5ecret',
}
PUPPET
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/acceptance/supported_versions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

def supported_versions
%w[8.5.22 9.2.15]
%w[8.5.22 9.2.15 10.3.1]
end