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..1384f56 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_guest_ip', '') }}" - 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_guest_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..79cfaa5 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_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 + + systemctl restart otelcol }