Filippo Giunchedi has submitted this change and it was merged.

Change subject: prometheus: generate varnish targets from get_clusters()
......................................................................


prometheus: generate varnish targets from get_clusters()

Pull a map of varnish host => varnish cluster from conftool data, use that map
to generate Prometheus per-varnish-cluster targets configuration.

Our varnish configuration is 2layer everywhere, therefore also 'service' is
used to distinguish frontend varnish from backend varnish. Two instances of
prometheus-varnish-exporter are ran per machine, one for each fe/be.

Bug: T147424
Change-Id: I76acecafdc5cc4a9472a79b5f3514daebf043471
---
A modules/prometheus/manifests/varnish_config.pp
A modules/prometheus/templates/varnish_config.erb
M modules/role/manifests/prometheus/ops.pp
3 files changed, 86 insertions(+), 1 deletion(-)

Approvals:
  Filippo Giunchedi: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/prometheus/manifests/varnish_config.pp 
b/modules/prometheus/manifests/varnish_config.pp
new file mode 100644
index 0000000..e93cbe8
--- /dev/null
+++ b/modules/prometheus/manifests/varnish_config.pp
@@ -0,0 +1,48 @@
+# == Define: prometheus::varnish_config
+#
+# Generate prometheus targets configuration for varnish clusters.
+# Data is gathered using get_clusters()
+
+# == Parameters
+# $dest:    The output file where to write the result.
+# $site:    The site to use.
+# $cluster: The cluster to use.
+# $port:    The port varnish_exporter is listening on.
+# $labels:  Labels to attach to the cluster's hosts.
+
+# == Example
+#
+#  prometheus::varnish_config{ 'maps_fe':
+#      dest    => "${targets_path}/varnish-maps_${::site}_frontend.yaml",
+#      site    => $::site,
+#      cluster => 'cache_maps',
+#      port    => '9331',
+#      labels  => {'layer' => 'frontend' },
+#  }
+
+define prometheus::varnish_config(
+  $dest,
+  $site,
+  $cluster,
+  $port,
+  $labels,
+) {
+    validate_string($dest)
+    validate_string($site)
+    validate_string($cluster)
+    validate_re($port, '^[0-9]+$')
+    validate_hash($labels)
+
+    $hosts = get_clusters({
+      'site' => $site,
+      'cluster' => $cluster,
+    })
+
+    file { $dest:
+        ensure  => present,
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0444',
+        content => template('prometheus/varnish_config.erb'),
+    }
+}
diff --git a/modules/prometheus/templates/varnish_config.erb 
b/modules/prometheus/templates/varnish_config.erb
new file mode 100644
index 0000000..cf24f51
--- /dev/null
+++ b/modules/prometheus/templates/varnish_config.erb
@@ -0,0 +1,9 @@
+<%
+  targets_config = []
+  targets_config.push({
+    labels  => @labels,
+    targets => @hosts[@site][@cluster].map{ |x| "#{x}:#{@port}" }
+  })
+-%>
+
+<%= scope.function_ordered_yaml(targets_config) -%>
diff --git a/modules/role/manifests/prometheus/ops.pp 
b/modules/role/manifests/prometheus/ops.pp
index eabc97e..472a770 100644
--- a/modules/role/manifests/prometheus/ops.pp
+++ b/modules/role/manifests/prometheus/ops.pp
@@ -42,9 +42,37 @@
       },
     ]
 
+    # one job per varnish cache 'role'
+    $varnish_jobs = [
+      {
+        'job_name'        => 'varnish-text',
+        'file_sd_configs' => [
+          { 'names' => [ "${targets_path}/varnish-text_*.yaml"] },
+        ]
+      },
+      {
+        'job_name'        => 'varnish-upload',
+        'file_sd_configs' => [
+          { 'names' => [ "${targets_path}/varnish-upload_*.yaml"] },
+        ]
+      },
+      {
+        'job_name'        => 'varnish-maps',
+        'file_sd_configs' => [
+          { 'names' => [ "${targets_path}/varnish-maps_*.yaml"] },
+        ]
+      },
+      {
+        'job_name'        => 'varnish-misc',
+        'file_sd_configs' => [
+          { 'names' => [ "${targets_path}/varnish-misc_*.yaml"] },
+        ]
+      },
+    ]
+
     prometheus::server { 'ops':
         listen_address       => '127.0.0.1:9900',
-        scrape_configs_extra => $mysql_jobs,
+        scrape_configs_extra => array_concat($mysql_jobs, $varnish_jobs),
     }
 
     prometheus::web { 'ops':

-- 
To view, visit https://gerrit.wikimedia.org/r/310819
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I76acecafdc5cc4a9472a79b5f3514daebf043471
Gerrit-PatchSet: 8
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Ema <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to