From 65fff8488740448141cf1ccd99a2602321b684c8 Mon Sep 17 00:00:00 2001 From: Abhishek Kapoor Date: Fri, 5 Dec 2025 21:05:52 +0100 Subject: [PATCH 1/2] Fix guest labels --- ...-config.yaml => otel-collector-config.yaml.j2} | 12 ++---------- .../common/salt/state/monitoring/otelcol/init.sls | 3 ++- components/guest/instance/common.sh | 15 +++++++++------ 3 files changed, 13 insertions(+), 17 deletions(-) rename components/common/salt/state/monitoring/otelcol/etc/{otel-collector-config.yaml => otel-collector-config.yaml.j2} (79%) diff --git a/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml b/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 similarity index 79% rename from components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml rename to components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 index 7687b1c..d4a9bd3 100644 --- a/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml +++ b/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 @@ -42,18 +42,10 @@ processors: attributes: - key: "url.domain" action: "insert" - ### The following section will be updated by init_logging_facilities in common.sh - ### BEGIN AUTO SECTION, DO NOT EDIT - # This is the domain of the URL that the logs are coming from - value: "" - ### END AUTO SECTION + value: "{{ grains.get('otel_url_domain', grains.get('fqdn', '')) }}" - key: "lit.subnet.id" action: "insert" - ### The following section will be updated by init_logging_facilities in common.sh - ### BEGIN AUTO SECTION, DO NOT EDIT - # This is the subnet ID of the GCP project - value: "" - ### END AUTO SECTION + value: "{{ grains.get('otel_subnet_id', pillar.get('subnet_id', '')) }}" exporters: googlecloud: diff --git a/components/common/salt/state/monitoring/otelcol/init.sls b/components/common/salt/state/monitoring/otelcol/init.sls index 80842b5..ee85ec8 100644 --- a/components/common/salt/state/monitoring/otelcol/init.sls +++ b/components/common/salt/state/monitoring/otelcol/init.sls @@ -38,7 +38,8 @@ print_otelcol_notification: /etc/monitoring/otelcol/otel-collector-config.yaml: file.managed: - - source: salt://monitoring/otelcol/etc/otel-collector-config.yaml + - source: salt://monitoring/otelcol/etc/otel-collector-config.yaml.j2 + - template: jinja - mode: 0644 - makedirs: True diff --git a/components/guest/instance/common.sh b/components/guest/instance/common.sh index 49b713d..96bbf90 100755 --- a/components/guest/instance/common.sh +++ b/components/guest/instance/common.sh @@ -187,13 +187,16 @@ services: - ${INSTANCE_LOGS_DIR}:/logs EOF - # We also need to update the latest guest / subnet information in the otelcol config file. - local otel_collector_config_file="/etc/monitoring/otelcol/otel-collector-config.yaml" + # Set Salt grains with the guest's subnet and IP information for OTEL Collector config. # Extract IP without CIDR notation (remove /XX suffix) local ip_no_cidr="${NET4_IP%/*}" - sed -i "/# This is the domain of the URL that the logs are coming from/{n;s|.*| value: \"${ip_no_cidr}\"|}" ${otel_collector_config_file} - sed -i "/# This is the subnet ID of the GCP project/{n;s|.*| value: \"${local_subnet_id}\"|}" ${otel_collector_config_file} - systemctl stop otelcol - systemctl start otelcol + # Set grains for otel-collector config template + salt-call --local grains.setval otel_url_domain "${ip_no_cidr}" + salt-call --local grains.setval otel_subnet_id "${local_subnet_id}" + + # Re-apply the otelcol state to regenerate the config with new grain values + salt-call --local state.apply monitoring.otelcol + + systemctl restart otelcol } From 0be1c08307ffc5b7d5f3525c83f51417ec9af5fc Mon Sep 17 00:00:00 2001 From: Abhishek Kapoor Date: Fri, 12 Dec 2025 13:36:04 +0100 Subject: [PATCH 2/2] Update variables --- .../monitoring/otelcol/etc/otel-collector-config.yaml.j2 | 4 ++-- components/guest/instance/common.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 b/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 index d4a9bd3..1384f56 100644 --- a/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 +++ b/components/common/salt/state/monitoring/otelcol/etc/otel-collector-config.yaml.j2 @@ -42,10 +42,10 @@ processors: attributes: - key: "url.domain" action: "insert" - value: "{{ grains.get('otel_url_domain', grains.get('fqdn', '')) }}" + value: "{{ grains.get('otel_guest_ip', '') }}" - key: "lit.subnet.id" action: "insert" - value: "{{ grains.get('otel_subnet_id', pillar.get('subnet_id', '')) }}" + value: "{{ grains.get('otel_guest_subnet_id', '') }}" exporters: googlecloud: diff --git a/components/guest/instance/common.sh b/components/guest/instance/common.sh index 96bbf90..79cfaa5 100755 --- a/components/guest/instance/common.sh +++ b/components/guest/instance/common.sh @@ -192,8 +192,8 @@ EOF local ip_no_cidr="${NET4_IP%/*}" # Set grains for otel-collector config template - salt-call --local grains.setval otel_url_domain "${ip_no_cidr}" - salt-call --local grains.setval otel_subnet_id "${local_subnet_id}" + salt-call --local grains.setval otel_guest_ip "${ip_no_cidr}" + salt-call --local grains.setval otel_guest_subnet_id "${local_subnet_id}" # Re-apply the otelcol state to regenerate the config with new grain values salt-call --local state.apply monitoring.otelcol