Skip to content

Commit 472eca4

Browse files
haywoodshpdabelf5
authored andcommitted
accept otel configmap keys
Signed-off-by: Haywood Shannon <[email protected]> Signed-off-by: Haywood Shannon <[email protected]>
1 parent a427d3d commit 472eca4

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

internal/configs/config_params.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ type ConfigParams struct {
3434
MainLogFormat []string
3535
MainLogFormatEscaping string
3636
MainMainSnippets []string
37+
MainOtelEnabled bool
38+
MainOtelLoadModule bool
39+
MainOtelGlobalTraceEnabled bool
40+
MainOtelExporterEndpoint string
41+
MainOtelExporterTrustedCA string
42+
MainOtelExporterHeaderName string
43+
MainOtelExporterHeaderValue string
44+
MainOtelServiceName string
3745
MainServerNamesHashBucketSize string
3846
MainServerNamesHashMaxSize string
3947
MainStreamLogFormat []string

internal/configs/configmaps.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,71 @@ func ParseConfigMap(ctx context.Context, cfgm *v1.ConfigMap, nginxPlus bool, has
530530
}
531531
}
532532

533+
if otelExporterEndpoint, exists := cfgm.Data["otel-exporter-endpoint"]; exists {
534+
otelExporterEndpoint = strings.TrimSpace(otelExporterEndpoint)
535+
if otelExporterEndpoint != "" {
536+
cfgParams.MainOtelExporterEndpoint = otelExporterEndpoint
537+
}
538+
}
539+
540+
if otelExporterTrustedCA, exists := cfgm.Data["otel-exporter-trusted-ca"]; exists {
541+
otelExporterTrustedCA = strings.TrimSpace(otelExporterTrustedCA)
542+
if otelExporterTrustedCA != "" {
543+
cfgParams.MainOtelExporterTrustedCA = otelExporterTrustedCA
544+
}
545+
}
546+
547+
if otelExporterHeaderName, exists := cfgm.Data["otel-exporter-header-name"]; exists {
548+
otelExporterHeaderName = strings.TrimSpace(otelExporterHeaderName)
549+
if otelExporterHeaderName != "" {
550+
cfgParams.MainOtelExporterHeaderName = otelExporterHeaderName
551+
}
552+
}
553+
554+
if otelExporterHeaderValue, exists := cfgm.Data["otel-exporter-header-value"]; exists {
555+
otelExporterHeaderValue = strings.TrimSpace(otelExporterHeaderValue)
556+
if otelExporterHeaderValue != "" {
557+
cfgParams.MainOtelExporterHeaderValue = otelExporterHeaderValue
558+
}
559+
}
560+
561+
if otelServiceName, exists := cfgm.Data["otel-service-name"]; exists {
562+
otelServiceName = strings.TrimSpace(otelServiceName)
563+
if otelServiceName != "" {
564+
cfgParams.MainOtelServiceName = otelServiceName
565+
}
566+
}
567+
568+
if otelGlobalTraceEnabled, exists, err := GetMapKeyAsBool(cfgm.Data, "otel-global-trace-enabled", cfgm); exists {
569+
if err != nil {
570+
nl.Error(l, err)
571+
eventLog.Event(cfgm, v1.EventTypeWarning, nl.EventReasonInvalidValue, err.Error())
572+
configOk = false
573+
}
574+
cfgParams.MainOtelGlobalTraceEnabled = otelGlobalTraceEnabled
575+
}
576+
577+
if cfgParams.MainOtelExporterEndpoint != "" {
578+
cfgParams.MainOtelLoadModule = true
579+
}
580+
581+
if otelEnabled, exists, err := GetMapKeyAsBool(cfgm.Data, "otel-enabled", cfgm); exists {
582+
if err != nil {
583+
nl.Error(l, err)
584+
eventLog.Event(cfgm, v1.EventTypeWarning, nl.EventReasonInvalidValue, err.Error())
585+
configOk = false
586+
} else {
587+
if cfgParams.MainOtelLoadModule {
588+
cfgParams.MainOtelEnabled = otelEnabled
589+
} else {
590+
errorText := fmt.Sprintf("ConfigMap %s/%s: 'otel-enabled' is ignored because 'otel-exporter-endpoint' is not set, ignoring", cfgm.GetNamespace(), cfgm.GetName())
591+
nl.Error(l, errorText)
592+
eventLog.Event(cfgm, v1.EventTypeWarning, nl.EventReasonInvalidValue, errorText)
593+
configOk = false
594+
}
595+
}
596+
}
597+
533598
if hasAppProtect {
534599
if appProtectFailureModeAction, exists := cfgm.Data["app-protect-failure-mode-action"]; exists {
535600
if appProtectFailureModeAction == "pass" || appProtectFailureModeAction == "drop" {
@@ -913,6 +978,14 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
913978
NginxStatus: staticCfgParams.NginxStatus,
914979
NginxStatusAllowCIDRs: staticCfgParams.NginxStatusAllowCIDRs,
915980
NginxStatusPort: staticCfgParams.NginxStatusPort,
981+
MainOtelEnabled: config.MainOtelEnabled,
982+
MainOtelLoadModule: config.MainOtelLoadModule,
983+
MainOtelGlobalTraceEnabled: config.MainOtelGlobalTraceEnabled,
984+
MainOtelExporterEndpoint: config.MainOtelExporterEndpoint,
985+
MainOtelExporterTrustedCA: config.MainOtelExporterTrustedCA,
986+
MainOtelExporterHeaderName: config.MainOtelExporterHeaderName,
987+
MainOtelExporterHeaderValue: config.MainOtelExporterHeaderValue,
988+
MainOtelServiceName: config.MainOtelServiceName,
916989
ProxyProtocol: config.ProxyProtocol,
917990
ResolverAddresses: config.ResolverAddresses,
918991
ResolverIPV6: config.ResolverIPV6,

internal/configs/version1/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ type MainConfig struct {
240240
NginxStatus bool
241241
NginxStatusAllowCIDRs []string
242242
NginxStatusPort int
243+
MainOtelEnabled bool
244+
MainOtelLoadModule bool
245+
MainOtelGlobalTraceEnabled bool
246+
MainOtelExporterEndpoint string
247+
MainOtelExporterTrustedCA string
248+
MainOtelExporterHeaderName string
249+
MainOtelExporterHeaderValue string
250+
MainOtelServiceName string
243251
ProxyProtocol bool
244252
ResolverAddresses []string
245253
ResolverIPV6 bool

internal/configs/version1/nginx-plus.tmpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ daemon off;
1212
error_log stderr {{.ErrorLogLevel}};
1313
pid /var/lib/nginx/nginx.pid;
1414

15+
{{- if .MainOtelLoadModule}}
16+
#load_module modules/ngx_otel_module.so;
17+
{{- end}}
1518
{{- if .AppProtectLoadModule}}
1619
load_module modules/ngx_http_app_protect_module.so;
1720
{{- end}}
@@ -142,6 +145,22 @@ http {
142145
{{- if .SSLDHParam}}
143146
ssl_dhparam {{.SSLDHParam}};
144147
{{- end}}
148+
149+
{{- if .MainOtelEnabled}}
150+
# otel_exporter {
151+
# endpoint {{ .MainOtelExporterEndpoint}};
152+
# header {{ .MainOtelExporterHeaderName }} {{ .MainOtelExporterHeaderValue }};
153+
{{ if .MainOtelExporterTrustedCA}}
154+
# trusted_certificate <path>;
155+
{{- end }}
156+
{{ if .MainOtelServiceName}}
157+
# otel_service_name {{ .MainOtelServiceName }};
158+
# }
159+
{{- end }}
160+
{{ if .MainOtelGlobalTraceEnabled }}
161+
# otel_trace on;
162+
{{- end}}
163+
{{- end}}
145164

146165
{{ $resolverIPV6HTTPBool := boolToPointerBool .ResolverIPV6 -}}
147166
{{ makeResolver .ResolverAddresses .ResolverValid $resolverIPV6HTTPBool }}

0 commit comments

Comments
 (0)