Skip to content

Commit

Permalink
Allow the ability to disable or specify custom host ports for OTLP (#…
Browse files Browse the repository at this point in the history
…1440)

* add the ability to disable hostPorts for otlp and specify custom hostPorts

* revise documentation to note that host ports are enabled by default for otlp

* fix single container host port logic

* refactor some of the logic

* fix the logic in the datadogagent defaults for otlp hostports

* Update api/datadoghq/v2alpha1/test/builder.go

Co-authored-by: khewonc <[email protected]>

* refactor otlp feature.go a bit more

Signed-off-by: mrmcpat <[email protected]>

* tweaking some otlp host port test cases for more clarity

Signed-off-by: mrmcpat <[email protected]>

---------

Signed-off-by: mrmcpat <[email protected]>
Co-authored-by: khewonc <[email protected]>
  • Loading branch information
mrdoggopat and khewonc authored Oct 4, 2024
1 parent 0d97b8a commit 7fe7979
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 123 deletions.
28 changes: 24 additions & 4 deletions api/datadoghq/v2alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ const (
defaultDogstatsdSocketEnabled bool = true
defaultDogstatsdHostSocketPath string = apicommon.DogstatsdAPMSocketHostPath + "/" + apicommon.DogstatsdSocketName

defaultOTLPGRPCEnabled bool = false
defaultOTLPGRPCEndpoint string = "0.0.0.0:4317"
defaultOTLPHTTPEnabled bool = false
defaultOTLPHTTPEndpoint string = "0.0.0.0:4318"
defaultOTLPGRPCEnabled bool = false
defaultOTLPGRPCHostPortEnabled bool = true
defaultOTLPGRPCEndpoint string = "0.0.0.0:4317"
defaultOTLPHTTPEnabled bool = false
defaultOTLPHTTPHostPortEnabled bool = true
defaultOTLPHTTPEndpoint string = "0.0.0.0:4318"

defaultRemoteConfigurationEnabled bool = true

Expand Down Expand Up @@ -381,13 +383,31 @@ func defaultFeaturesConfig(ddaSpec *DatadogAgentSpec) {
if ddaSpec.Features.OTLP.Receiver.Protocols.GRPC == nil {
ddaSpec.Features.OTLP.Receiver.Protocols.GRPC = &OTLPGRPCConfig{}
}

apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Enabled, defaultOTLPGRPCEnabled)

if apiutils.BoolValue(ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Enabled) {
if ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig == nil {
ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig = &HostPortConfig{}
}
apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.HostPortConfig.Enabled, defaultOTLPGRPCHostPortEnabled)
}

apiutils.DefaultStringIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.GRPC.Endpoint, defaultOTLPGRPCEndpoint)

if ddaSpec.Features.OTLP.Receiver.Protocols.HTTP == nil {
ddaSpec.Features.OTLP.Receiver.Protocols.HTTP = &OTLPHTTPConfig{}
}

apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Enabled, defaultOTLPHTTPEnabled)

if apiutils.BoolValue(ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Enabled) {
if ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig == nil {
ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig = &HostPortConfig{}
}
apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.HostPortConfig.Enabled, defaultOTLPHTTPHostPortEnabled)
}

apiutils.DefaultStringIfUnset(&ddaSpec.Features.OTLP.Receiver.Protocols.HTTP.Endpoint, defaultOTLPHTTPEndpoint)

// RemoteConfiguration feature
Expand Down
130 changes: 78 additions & 52 deletions api/datadoghq/v2alpha1/datadogagent_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -430,12 +432,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
EventCollection: &EventCollectionFeatureConfig{
Expand Down Expand Up @@ -551,12 +555,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -681,12 +687,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -806,12 +814,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -933,12 +943,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1065,12 +1077,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(valueTrue),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(valueTrue),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)},
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(valueTrue),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(valueTrue),
HostPortConfig: &HostPortConfig{Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCHostPortEnabled)},
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1190,12 +1204,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1318,12 +1334,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1447,12 +1465,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1574,12 +1594,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1721,12 +1743,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down Expand Up @@ -1859,12 +1883,14 @@ func Test_defaultFeatures(t *testing.T) {
},
OTLP: &OTLPFeatureConfig{Receiver: OTLPReceiverConfig{Protocols: OTLPProtocolsConfig{
GRPC: &OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPGRPCEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPGRPCEndpoint),
},
HTTP: &OTLPHTTPConfig{
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
Enabled: apiutils.NewBoolPointer(defaultOTLPHTTPEnabled),
HostPortConfig: nil,
Endpoint: apiutils.NewStringPointer(defaultOTLPHTTPEndpoint),
},
}}},
RemoteConfiguration: &RemoteConfigurationFeatureConfig{
Expand Down
15 changes: 12 additions & 3 deletions api/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,15 @@ type OTLPProtocolsConfig struct {
// OTLPGRPCConfig contains configuration for the OTLP ingest OTLP/gRPC receiver.
// +k8s:openapi-gen=true
type OTLPGRPCConfig struct {
// Enable the OTLP/gRPC endpoint.
// Enable the OTLP/gRPC endpoint. Host port is enabled by default and can be disabled.
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Enable hostPort for OTLP/gRPC
// Default: true
// +optional
HostPortConfig *HostPortConfig `json:"hostPortConfig,omitempty"`

// Endpoint for OTLP/gRPC.
// gRPC supports several naming schemes: https://github.com/grpc/grpc/blob/master/doc/naming.md
// The Datadog Operator supports only 'host:port' (usually `0.0.0.0:port`).
Expand All @@ -564,10 +569,15 @@ type OTLPGRPCConfig struct {
// OTLPHTTPConfig contains configuration for the OTLP ingest OTLP/HTTP receiver.
// +k8s:openapi-gen=true
type OTLPHTTPConfig struct {
// Enable the OTLP/HTTP endpoint.
// Enable the OTLP/HTTP endpoint. Host port is enabled by default and can be disabled.
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Enable hostPorts for OTLP/HTTP
// Default: true
// +optional
HostPortConfig *HostPortConfig `json:"hostPortConfig,omitempty"`

// Endpoint for OTLP/HTTP.
// Default: '0.0.0.0:4318'.
// +optional
Expand Down Expand Up @@ -967,7 +977,6 @@ type KubeletConfig struct {
// HostPortConfig contains host port configuration.
type HostPortConfig struct {
// Enabled enables host port configuration
// Default: false
// +optional
Enabled *bool `json:"enabled,omitempty"`

Expand Down
16 changes: 12 additions & 4 deletions api/datadoghq/v2alpha1/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,19 +602,27 @@ func (builder *DatadogAgentBuilder) initOTLP() {
}
}

func (builder *DatadogAgentBuilder) WithOTLPGRPCSettings(enabled bool, endpoint string) *DatadogAgentBuilder {
func (builder *DatadogAgentBuilder) WithOTLPGRPCSettings(enabled bool, hostPortEnabled bool, customHostPort int32, endpoint string) *DatadogAgentBuilder {
builder.initOTLP()
builder.datadogAgent.Spec.Features.OTLP.Receiver.Protocols.GRPC = &v2alpha1.OTLPGRPCConfig{
Enabled: apiutils.NewBoolPointer(enabled),
Enabled: apiutils.NewBoolPointer(enabled),
HostPortConfig: &v2alpha1.HostPortConfig{
Enabled: apiutils.NewBoolPointer(hostPortEnabled),
Port: apiutils.NewInt32Pointer(customHostPort),
},
Endpoint: apiutils.NewStringPointer(endpoint),
}
return builder
}

func (builder *DatadogAgentBuilder) WithOTLPHTTPSettings(enabled bool, 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),
Enabled: apiutils.NewBoolPointer(enabled),
HostPortConfig: &v2alpha1.HostPortConfig{
Enabled: apiutils.NewBoolPointer(hostPortEnabled),
Port: apiutils.NewInt32Pointer(customHostPort),
},
Endpoint: apiutils.NewStringPointer(endpoint),
}
return builder
Expand Down
10 changes: 10 additions & 0 deletions api/datadoghq/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7fe7979

Please sign in to comment.