From da6e0478c38d8c647c6d8484828c351146a262dc Mon Sep 17 00:00:00 2001 From: Matthew Alexander LaChance Date: Tue, 29 Oct 2024 10:25:02 -0400 Subject: [PATCH] Collect etcd metrics --- .../profile/kubernetes/destination_port/etcd.pp | 6 ++++++ manifests/profile/kubernetes/kubelet.pp | 2 +- manifests/profile/prometheus.pp | 8 ++++++++ .../profile/kubernetes/destination_port_spec.rb | 8 ++++++++ spec/classes/profile/kubernetes/kubelet_spec.rb | 16 ++++++++-------- spec/classes/profile/prometheus_spec.rb | 1 + templates/profile/prometheus/config.yml.erb | 3 +++ .../prometheus/exporter/etcd/target.yaml.erb | 4 ++++ 8 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 templates/profile/prometheus/exporter/etcd/target.yaml.erb diff --git a/manifests/profile/kubernetes/destination_port/etcd.pp b/manifests/profile/kubernetes/destination_port/etcd.pp index 3e93acafb..08ab3f199 100644 --- a/manifests/profile/kubernetes/destination_port/etcd.pp +++ b/manifests/profile/kubernetes/destination_port/etcd.pp @@ -11,4 +11,10 @@ content => " server ${::hostname} ${::ipaddress}:2379 check\n", tag => "${cluster_name}_haproxy_kubernetes_etcd", } + + @@concat_fragment { "prometheus etcd service ${::hostname}": + tag => "${::datacenter}_prometheus_etcd_service_list", + target => '/etc/prometheus/etcd.yml', + content => template('nebula/profile/prometheus/exporter/etcd/target.yaml.erb') + } } diff --git a/manifests/profile/kubernetes/kubelet.pp b/manifests/profile/kubernetes/kubelet.pp index 088f342d6..0411fccd0 100644 --- a/manifests/profile/kubernetes/kubelet.pp +++ b/manifests/profile/kubernetes/kubelet.pp @@ -70,7 +70,7 @@ ; '200 Cluster etcd': - dport => ['2379', '2380'], + dport => ['2379', '2380', '2381'], ; '200 Cluster kubelet': diff --git a/manifests/profile/prometheus.pp b/manifests/profile/prometheus.pp index a480230c6..d4008005d 100644 --- a/manifests/profile/prometheus.pp +++ b/manifests/profile/prometheus.pp @@ -38,6 +38,7 @@ '/etc/prometheus/haproxy.yml:/etc/prometheus/haproxy.yml', '/etc/prometheus/mysql.yml:/etc/prometheus/mysql.yml', '/etc/prometheus/ipmi.yml:/etc/prometheus/ipmi.yml', + '/etc/prometheus/etcd.yml:/etc/prometheus/etcd.yml', '/etc/prometheus/tls:/tls', '/opt/prometheus:/prometheus', ], @@ -105,6 +106,13 @@ Concat_fragment <<| tag == "${::datacenter}_prometheus_ipmi_exporter" |>> + concat_file { '/etc/prometheus/etcd.yml': + notify => Docker::Run['prometheus'], + require => File['/etc/prometheus'], + } + + Concat_fragment <<| tag == "${::datacenter}_prometheus_etcd_service_list" |>> + file { '/etc/prometheus': ensure => 'directory', } diff --git a/spec/classes/profile/kubernetes/destination_port_spec.rb b/spec/classes/profile/kubernetes/destination_port_spec.rb index 0ae8c827b..285e1553a 100644 --- a/spec/classes/profile/kubernetes/destination_port_spec.rb +++ b/spec/classes/profile/kubernetes/destination_port_spec.rb @@ -31,6 +31,14 @@ .with_content(" server #{facts[:hostname]} #{facts[:ipaddress]}:#{port} #{options}\n") .with_tag("first_cluster_haproxy_kubernetes_#{service}") end + + if service == 'etcd' + it do + is_expected.to contain_concat_fragment("prometheus #{service.tr('_', ' ')} service #{facts[:hostname]}") + .with_target("/etc/prometheus/#{service}.yml") + .with_tag("mydatacenter_prometheus_etcd_service_list") + end + end end end end diff --git a/spec/classes/profile/kubernetes/kubelet_spec.rb b/spec/classes/profile/kubernetes/kubelet_spec.rb index a0349910a..0ca8c0df5 100644 --- a/spec/classes/profile/kubernetes/kubelet_spec.rb +++ b/spec/classes/profile/kubernetes/kubelet_spec.rb @@ -87,14 +87,14 @@ end [ - [22, 'ssh', 'tcp'], - [179, 'BGP', 'tcp'], - [4789, 'VXLAN', 'udp'], - [%w[2379 2380], 'etcd', 'tcp'], - [10250, 'kubelet', 'tcp'], - [6443, 'kubernetes API', 'tcp'], - ['30000-32767', 'NodePorts', 'tcp'], - [9100, 'Prometheus', 'tcp'], + [22, 'ssh', 'tcp'], + [179, 'BGP', 'tcp'], + [4789, 'VXLAN', 'udp'], + [%w[2379 2380 2381], 'etcd', 'tcp'], + [10250, 'kubelet', 'tcp'], + [6443, 'kubernetes API', 'tcp'], + ['30000-32767', 'NodePorts', 'tcp'], + [9100, 'Prometheus', 'tcp'], ].each do |ports, purpose, proto| it do is_expected.to contain_firewall("200 Cluster #{purpose}") diff --git a/spec/classes/profile/prometheus_spec.rb b/spec/classes/profile/prometheus_spec.rb index c2bf66914..99143f941 100644 --- a/spec/classes/profile/prometheus_spec.rb +++ b/spec/classes/profile/prometheus_spec.rb @@ -23,6 +23,7 @@ '/etc/prometheus/haproxy.yml:/etc/prometheus/haproxy.yml', '/etc/prometheus/mysql.yml:/etc/prometheus/mysql.yml', '/etc/prometheus/ipmi.yml:/etc/prometheus/ipmi.yml', + '/etc/prometheus/etcd.yml:/etc/prometheus/etcd.yml', '/etc/prometheus/tls:/tls', '/opt/prometheus:/prometheus']) .that_requires('File[/opt/prometheus]') diff --git a/templates/profile/prometheus/config.yml.erb b/templates/profile/prometheus/config.yml.erb index 35689ebd5..f569045a1 100644 --- a/templates/profile/prometheus/config.yml.erb +++ b/templates/profile/prometheus/config.yml.erb @@ -50,5 +50,8 @@ scrape_configs: <% end -%> <% end -%> <% end -%> +- job_name: etcd + file_sd_configs: + - files: [ etcd.yml ] scrape_config_files: - "ipmi.yml" diff --git a/templates/profile/prometheus/exporter/etcd/target.yaml.erb b/templates/profile/prometheus/exporter/etcd/target.yaml.erb new file mode 100644 index 000000000..66943ef15 --- /dev/null +++ b/templates/profile/prometheus/exporter/etcd/target.yaml.erb @@ -0,0 +1,4 @@ +- targets: [ '<%= @ipaddress %>:2381' ] + labels: + datacenter: '<%= @datacenter %>' + hostname: '<%= @fqdn %>'