Add support for prometheus_client options

Change-Id: Ieebd4c9dd30ab48fdb079e8a438a38d6e34af5af
This commit is contained in:
Takashi Kajinami 2025-02-16 19:21:02 +09:00
parent 8232536f9a
commit d874c8d61f
3 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,52 @@
# == Class: watcher::prometheus_client
#
# Configure the prometheus_client options
#
# === Parameters
#
# [*host*]
# (Required) The hostname of IP address for the prometheus server.
#
# [*port*]
# (Optional) The port number used by the prometheus server.
# Defaults to $facts['os_service_default']
#
# [*fqdn_label*]
# (Optional) The label that Prometheus uses to store the fqdn of exporters.
# Defaults to $facts['os_service_default']
#
# [*instance_uuid_label*]
# (Optional) The label that Prometheus uses to store the uuid of OpenStack
# instances.
# Defaults to $facts['os_service_default']
#
# [*username*]
# (Optional) The basic_auth username to use to authenticate with
# the Prometheus server.
# Defaults to $facts['os_service_default'].
#
# [*password*]
# (Optional) The basic_auth password to use to authenticate with
# the Prometheus server.
# Defaults to $facts['os_service_default'].
#
class watcher::prometheus_client (
$host,
$port = $facts['os_service_default'],
$fqdn_label = $facts['os_service_default'],
$instance_uuid_label = $facts['os_service_default'],
$username = $facts['os_service_default'],
$password = $facts['os_service_default'],
) {
include watcher::deps
watcher_config {
'prometheus_client/host': value => $host;
'prometheus_client/port': value => $port;
'prometheus_client/fqdn_label': value => $fqdn_label;
'prometheus_client/instance_uuid_label': value => $instance_uuid_label;
'prometheus_client/username': value => $username;
'prometheus_client/password': value => $password, secret => true;
}
}

View File

@ -0,0 +1,4 @@
---
features:
- |
The new ``watcher::prometheus_client`` class has been added.

View File

@ -0,0 +1,56 @@
require 'spec_helper'
describe 'watcher::prometheus_client' do
shared_examples 'watcher::prometheus_client' do
let :params do
{
:host => '127.0.0.1'
}
end
context 'with defaults' do
it 'should set the defaults' do
should contain_watcher_config('prometheus_client/host').with_value('127.0.0.1')
should contain_watcher_config('prometheus_client/port').with_value('<SERVICE DEFAULT>')
should contain_watcher_config('prometheus_client/fqdn_label').with_value('<SERVICE DEFAULT>')
should contain_watcher_config('prometheus_client/instance_uuid_label').with_value('<SERVICE DEFAULT>')
should contain_watcher_config('prometheus_client/username').with_value('<SERVICE DEFAULT>')
should contain_watcher_config('prometheus_client/password').with_value('<SERVICE DEFAULT>').with_secret(true)
end
end
context 'with parameters overridden' do
before :each do
params.merge!({
:port => 9090,
:fqdn_label => 'fqdn',
:instance_uuid_label => 'resource',
:username => 'promuser',
:password => 'prompass'
})
end
it 'should set the overridden values' do
should contain_watcher_config('prometheus_client/host').with_value('127.0.0.1')
should contain_watcher_config('prometheus_client/port').with_value(9090)
should contain_watcher_config('prometheus_client/fqdn_label').with_value('fqdn')
should contain_watcher_config('prometheus_client/instance_uuid_label').with_value('resource')
should contain_watcher_config('prometheus_client/username').with_value('promuser')
should contain_watcher_config('prometheus_client/password').with_value('prompass').with_secret(true)
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_behaves_like 'watcher::prometheus_client'
end
end
end