Skip to content

Commit

Permalink
texas: set otel resource attributes
Browse files Browse the repository at this point in the history
Co-authored-by: sindrerh2 <[email protected]>
  • Loading branch information
tronghn and sindrerh2 committed Feb 17, 2025
1 parent e36c9cd commit e09543d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
8 changes: 1 addition & 7 deletions pkg/resourcecreator/testdata/texas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ tests:
env:
- name: BIND_ADDRESS
value: ^127.0.0.1:7164$
- name: DOWNSTREAM_APP_NAME
value: myapplication
- name: DOWNSTREAM_APP_NAMESPACE
value: mynamespace
- name: DOWNSTREAM_APP_CLUSTER
value: mycluster
- name: NAIS_POD_NAME
valueFrom:
fieldRef:
Expand All @@ -85,7 +79,7 @@ tests:
- name: OTEL_SERVICE_NAME
value: ^texas$
- name: OTEL_RESOURCE_ATTRIBUTES
value: service.name=texas,service.namespace=mynamespace
value: ^service.name=texas,service.namespace=mynamespace,downstream.app.name=myapplication,downstream.app.namespace=mynamespace,downstream.cluster.name=mycluster,nais.pod.name=\$\(NAIS_POD_NAME\)$
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://my-collector.system-namespace:4317
- name: OTEL_EXPORTER_OTLP_PROTOCOL
Expand Down
12 changes: 5 additions & 7 deletions pkg/resourcecreator/testdata/texas_on_premises.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,16 @@ tests:
value: "-Dhttp.proxyHost=foo.bar -Dhttps.proxyHost=foo.bar -Dhttp.proxyPort=5224 -Dhttps.proxyPort=5224 -Dhttp.nonProxyHosts=foo|bar|baz"
- name: BIND_ADDRESS
value: ^127.0.0.1:7164$
- name: DOWNSTREAM_APP_NAME
value: myapplication
- name: DOWNSTREAM_APP_NAMESPACE
value: mynamespace
- name: DOWNSTREAM_APP_CLUSTER
value: mycluster
- name: NAIS_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: MASKINPORTEN_ENABLED
value: ^true$
- name: OTEL_SERVICE_NAME
value: ^texas$
- name: OTEL_RESOURCE_ATTRIBUTES
value: service.name=texas,service.namespace=mynamespace
value: ^service.name=texas,service.namespace=mynamespace,downstream.app.name=myapplication,downstream.app.namespace=mynamespace,downstream.cluster.name=mycluster,nais.pod.name=\$\(NAIS_POD_NAME\)$
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://my-collector.system-namespace:4317
- name: OTEL_EXPORTER_OTLP_PROTOCOL
Expand Down
23 changes: 10 additions & 13 deletions pkg/resourcecreator/texas/texas.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,6 @@ func sidecar(source Source, cfg Config, providers Providers) (*corev1.Container,
Name: "BIND_ADDRESS",
Value: fmt.Sprintf("127.0.0.1:%d", Port),
},
{
Name: "DOWNSTREAM_APP_NAME",
Value: source.GetName(),
},
{
Name: "DOWNSTREAM_APP_NAMESPACE",
Value: source.GetNamespace(),
},
{
Name: "DOWNSTREAM_APP_CLUSTER",
Value: cfg.GetClusterName(),
},
{
Name: "NAIS_POD_NAME",
ValueFrom: &corev1.EnvVarSource{
Expand All @@ -171,7 +159,16 @@ func sidecar(source Source, cfg Config, providers Providers) (*corev1.Container,
},
}
envs = append(envs, providers.EnvVars()...)
envs = append(envs, observability.OtelEnvVars("texas", source.GetNamespace(), nil, nil, cfg.GetObservability().Otel)...)
otelEnvs := []corev1.EnvVar{
{
Name: "OTEL_RESOURCE_ATTRIBUTES",
Value: fmt.Sprintf(
"downstream.app.name=%s,downstream.app.namespace=%s,downstream.cluster.name=%s,nais.pod.name=$(NAIS_POD_NAME)",
source.GetName(), source.GetNamespace(), cfg.GetClusterName(),
),
},
}
envs = append(envs, observability.OtelEnvVars("texas", source.GetNamespace(), otelEnvs, nil, cfg.GetObservability().Otel)...)

// If GCP is unconfigured, it means we are running on-premises, and we need the web proxy config.
// Note that we need the web proxy regardless of whether the app has requested one, so we don't care about `.spec.webProxy`.
Expand Down

0 comments on commit e09543d

Please sign in to comment.