From d8d558155e47c12cdceab5a1e7603792a3d5e049 Mon Sep 17 00:00:00 2001
From: Nicolas Dandrimont <nicolas@dandrimont.eu>
Date: Wed, 19 Mar 2025 18:18:14 +0100
Subject: [PATCH] sentry: Configure statsd exports

Could help diagnose swh/infra/sysadm-environment#5570
---
 site-modules/profile/manifests/sentry.pp           |  5 ++++-
 .../profile/templates/sentry/relay.yml.erb         | 14 +++++++-------
 .../profile/templates/sentry/sentry.conf.py.erb    | 14 +++++++-------
 .../profile/templates/sentry/symbolicator.yml.erb  |  8 ++++----
 4 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/site-modules/profile/manifests/sentry.pp b/site-modules/profile/manifests/sentry.pp
index a8ba0f24..a900a874 100644
--- a/site-modules/profile/manifests/sentry.pp
+++ b/site-modules/profile/manifests/sentry.pp
@@ -44,7 +44,10 @@ class profile::sentry {
   $vhost_name  = lookup('sentry::vhost::name')
   $mail_host   = lookup('sentry::mail::host')
   $mail_from   = lookup('sentry::mail::from')
-  $mail_list_namespace   = lookup('sentry::mail::list_namespace')
+  $mail_list_namespace = lookup('sentry::mail::list_namespace')
+  $statsd_listen_network = lookup('sentry::statsd::listen_network', {default_value => lookup('internal_network')})
+  $statsd_host = ip_for_network($statsd_listen_network)
+  $statsd_port = lookup('sentry::statsd::port', {default_value => 8125})
 
   file {$config_yml:
     ensure => present,
diff --git a/site-modules/profile/templates/sentry/relay.yml.erb b/site-modules/profile/templates/sentry/relay.yml.erb
index 1382f4c9..5f4c748e 100644
--- a/site-modules/profile/templates/sentry/relay.yml.erb
+++ b/site-modules/profile/templates/sentry/relay.yml.erb
@@ -25,10 +25,10 @@ processing:
 # If you have statsd server, you can utilize that to monitor self-hosted Relay.
 # To start, uncomment the following line and adjust the options as needed.
 #
-# metrics:
-#  statsd: "100.100.123.123:8125" # It is recommended to use IP address instead of domain name
-#  prefix: "sentry.relay" # Adjust this to your needs, default is "sentry.relay"
-#  sample_rate: 1.0 # Adjust this to your needs, default is 1.0
-#  # `periodic_secs` is the interval for periodic metrics emitted from Relay.
-#  #  Setting it to `0` seconds disables the periodic metrics.
-#  periodic_secs: 5
+metrics:
+ statsd: "<%= @statsd_host %>:<%= @statsd_port %>" # It is recommended to use IP address instead of domain name
+ prefix: "sentry.relay" # Adjust this to your needs, default is "sentry.relay"
+ sample_rate: 1.0 # Adjust this to your needs, default is 1.0
+ # `periodic_secs` is the interval for periodic metrics emitted from Relay.
+ #  Setting it to `0` seconds disables the periodic metrics.
+ periodic_secs: 5
diff --git a/site-modules/profile/templates/sentry/sentry.conf.py.erb b/site-modules/profile/templates/sentry/sentry.conf.py.erb
index 39acac51..4c9701db 100644
--- a/site-modules/profile/templates/sentry/sentry.conf.py.erb
+++ b/site-modules/profile/templates/sentry/sentry.conf.py.erb
@@ -410,13 +410,13 @@ JS_SDK_LOADER_DEFAULT_SDK_URL = "https://<%= @vhost_name %>/js-sdk/%s/bundle%s.m
 #
 # To start, uncomment the following line and adjust the options as needed.
 
-# SENTRY_METRICS_BACKEND = 'sentry.metrics.statsd.StatsdMetricsBackend'
-# SENTRY_METRICS_OPTIONS: dict[str, Any] = {
-#     'host': '100.100.123.123', # It is recommended to use IP address instead of domain name
-#     'port': 8125,
-# }
-# SENTRY_METRICS_SAMPLE_RATE = 1.0   # Adjust this to your needs, default is 1.0
-# SENTRY_METRICS_PREFIX = "sentry."  # Adjust this to your needs, default is "sentry."
+SENTRY_METRICS_BACKEND = 'sentry.metrics.statsd.StatsdMetricsBackend'
+SENTRY_METRICS_OPTIONS: dict[str, Any] = {
+    'host': '<%= @statsd_host %>', # It is recommended to use IP address instead of domain name
+    'port': <%= @statsd_port %>,
+}
+SENTRY_METRICS_SAMPLE_RATE = 1.0   # Adjust this to your needs, default is 1.0
+SENTRY_METRICS_PREFIX = "sentry."  # Adjust this to your needs, default is "sentry."
 
 
 #######################
diff --git a/site-modules/profile/templates/sentry/symbolicator.yml.erb b/site-modules/profile/templates/sentry/symbolicator.yml.erb
index 4b321970..667bd69d 100644
--- a/site-modules/profile/templates/sentry/symbolicator.yml.erb
+++ b/site-modules/profile/templates/sentry/symbolicator.yml.erb
@@ -12,7 +12,7 @@ sentry_dsn: null # TODO: Automatically fill this with the internal project DSN
 
 # If you have statsd server, you can utilize that to monitor self-hosted Symbolicator.
 # To start, uncomment the following line and adjust the options as needed.
-#
-# metrics:
-#   statsd: "100.100.123.123:8125" # It is recommended to use IP address instead of domain name
-#   prefix: "sentry.symbolicator" # Adjust this to your needs, default is "symbolicator"
+
+metrics:
+  statsd: "<%= @statsd_host %>:<%= @statsd_port %>" # It is recommended to use IP address instead of domain name
+  prefix: "sentry.symbolicator" # Adjust this to your needs, default is "symbolicator"
-- 
GitLab