Skip to content

Commit

Permalink
refactor otlp feature.go a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoggopat committed Oct 2, 2024
1 parent 8fa212a commit 546b744
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
10 changes: 5 additions & 5 deletions api/datadoghq/v2alpha1/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,21 +607,21 @@ func (builder *DatadogAgentBuilder) WithOTLPGRPCSettings(enabled bool, hostPortE
builder.datadogAgent.Spec.Features.OTLP.Receiver.Protocols.GRPC = &v2alpha1.OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(enabled),
HostPortConfig: &v2alpha1.HostPortConfig{
Enabled: apiutils.NewBoolPointer(hostportenabled),
Port: apiutils.NewInt32Pointer(customhostport),
Enabled: apiutils.NewBoolPointer(hostPortEnabled),
Port: apiutils.NewInt32Pointer(customHostPort),
},
Endpoint: apiutils.NewStringPointer(endpoint),
}
return builder
}

func (builder *DatadogAgentBuilder) WithOTLPHTTPSettings(enabled bool, hostportenabled bool, customhostport int32, endpoint string) *DatadogAgentBuilder {
func (builder *DatadogAgentBuilder) WithOTLPHTTPSettings(enabled bool, hostPortEnabled bool, customHostPort int32, endpoint string) *DatadogAgentBuilder {
builder.initOTLP()
builder.datadogAgent.Spec.Features.OTLP.Receiver.Protocols.HTTP = &v2alpha1.OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(enabled),
HostPortConfig: &v2alpha1.HostPortConfig{
Enabled: apiutils.NewBoolPointer(hostportenabled),
Port: apiutils.NewInt32Pointer(customhostport),
Enabled: apiutils.NewBoolPointer(hostPortEnabled),
Port: apiutils.NewInt32Pointer(customHostPort),
},
Endpoint: apiutils.NewStringPointer(endpoint),
}
Expand Down
23 changes: 9 additions & 14 deletions internal/controller/datadogagent/feature/otlp/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req
f.grpcEnabled = true
}
if otlp.Receiver.Protocols.GRPC.HostPortConfig != nil {
if apiutils.BoolValue(otlp.Receiver.Protocols.GRPC.HostPortConfig.Enabled) {
f.grpcHostPortEnabled = *otlp.Receiver.Protocols.GRPC.HostPortConfig.Enabled
}
f.grpcHostPortEnabled = apiutils.BoolValue(otlp.Receiver.Protocols.GRPC.HostPortConfig.Enabled)
if otlp.Receiver.Protocols.GRPC.HostPortConfig.Port != nil {
f.grpcCustomHostPort = *otlp.Receiver.Protocols.GRPC.HostPortConfig.Port
}
Expand All @@ -90,9 +88,7 @@ func (f *otlpFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Req
f.httpEnabled = true
}
if otlp.Receiver.Protocols.HTTP.HostPortConfig != nil {
if apiutils.BoolValue(otlp.Receiver.Protocols.HTTP.HostPortConfig.Enabled) {
f.httpHostPortEnabled = *otlp.Receiver.Protocols.HTTP.HostPortConfig.Enabled
}
f.httpHostPortEnabled = apiutils.BoolValue(otlp.Receiver.Protocols.HTTP.HostPortConfig.Enabled)
if otlp.Receiver.Protocols.HTTP.HostPortConfig.Port != nil {
f.httpCustomHostPort = *otlp.Receiver.Protocols.HTTP.HostPortConfig.Port
}
Expand Down Expand Up @@ -294,9 +290,9 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov
Protocol: corev1.ProtocolTCP,
}
if f.grpcHostPortEnabled {
otlpgrpcPort.HostPort = f.grpcCustomHostPort
if f.grpcCustomHostPort == 0 {
otlpgrpcPort.HostPort = port
otlpgrpcPort.HostPort = port
if f.grpcCustomHostPort != 0 {
otlpgrpcPort.HostPort = f.grpcCustomHostPort
}
}
envVar := &corev1.EnvVar{
Expand All @@ -322,17 +318,16 @@ func (f *otlpFeature) ManageNodeAgent(managers feature.PodTemplateManagers, prov
Protocol: corev1.ProtocolTCP,
}
if f.httpHostPortEnabled {
otlphttpPort.HostPort = f.httpCustomHostPort
if f.httpCustomHostPort == 0 {
otlphttpPort.HostPort = port
otlphttpPort.HostPort = port
if f.httpCustomHostPort != 0 {
otlphttpPort.HostPort = f.httpCustomHostPort
}
}
managers.Port().AddPortToContainer(apicommon.CoreAgentContainerName, otlphttpPort)
envVar := &corev1.EnvVar{
Name: apicommon.DDOTLPHTTPEndpoint,
Value: f.httpEndpoint,
}

managers.Port().AddPortToContainer(apicommon.CoreAgentContainerName, otlphttpPort)
managers.EnvVar().AddEnvVarToContainer(apicommon.CoreAgentContainerName, envVar)
if f.usingAPM {
managers.EnvVar().AddEnvVarToContainer(apicommon.TraceAgentContainerName, envVar)
Expand Down

0 comments on commit 546b744

Please sign in to comment.