Skip to content

Commit 30e22b0

Browse files
kangyilimx-psi
andauthored
add orchestrator explorer support in pkg/datadog/config (open-telemetry#44105)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This change introduces a new orchestrator_explorer configuration in pkg/datadog/config, which is disabled by default. The configuration will be used to collect Kubernetes resource data and send it to Datadog. This functionality is currently a work in progress. The overall goal is to keep it aligned with the configuration used in the Datadog agent: https://github.com/DataDog/helm-charts/blob/main/charts/datadog/values.yaml#L887-L892 <!--Describe what testing was performed and which tests were added.--> #### Testing It is covered by unit test `TestValidate` Co-authored-by: Pablo Baeyens <[email protected]>
1 parent 90bb3d6 commit 30e22b0

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: pkg/datadog
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: add orchestrator explorer support in pkg/datadog/config
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [44105]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

pkg/datadog/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ type Config struct {
110110
// `use_resource_metadata`, or `host_metadata::hostname_source != first_resource`
111111
OnlyMetadata bool `mapstructure:"only_metadata"`
112112

113+
OrchestratorExplorer OrchestratorExplorerConfig `mapstructure:"orchestrator_explorer"`
114+
113115
// Non-fatal warnings found during configuration loading.
114116
warnings []error
115117
}
@@ -175,6 +177,10 @@ func (c *Config) Validate() error {
175177
return errors.New("reporter_period must be 5 minutes or higher")
176178
}
177179

180+
if err := c.OrchestratorExplorer.Validate(); err != nil {
181+
return err
182+
}
183+
178184
return nil
179185
}
180186

@@ -403,6 +409,10 @@ func CreateDefaultConfig() component.Config {
403409
ReporterPeriod: 30 * time.Minute,
404410
},
405411

412+
OrchestratorExplorer: OrchestratorExplorerConfig{
413+
Enabled: false,
414+
},
415+
406416
HostnameDetectionTimeout: 25 * time.Second, // set to 25 to prevent 30-second pod restart on K8s as reported in issue #40372 and #40373
407417
}
408418
}

pkg/datadog/config/config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ func TestValidate(t *testing.T) {
201201
},
202202
err: "reporter_period must be 5 minutes or higher",
203203
},
204+
{
205+
name: "empty cluster_name when orchestrator_explorer is enabled",
206+
cfg: &Config{
207+
API: APIConfig{Key: "abcdef0"},
208+
HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute},
209+
OrchestratorExplorer: OrchestratorExplorerConfig{
210+
Enabled: true,
211+
ClusterName: "",
212+
},
213+
},
214+
err: "'cluster_name' is required when 'orchestrator_explorer' is enabled",
215+
},
204216
}
205217
for _, testInstance := range tests {
206218
t.Run(testInstance.name, func(t *testing.T) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog/config"
5+
6+
import "errors"
7+
8+
// OrchestratorExplorerConfig defines configuration for the Datadog orchestrator explorer.
9+
type OrchestratorExplorerConfig struct {
10+
// Enabled enables the orchestrator explorer.
11+
Enabled bool `mapstructure:"enabled"`
12+
13+
// ClusterName defines the kubernetes cluster name.
14+
ClusterName string `mapstructure:"cluster_name"`
15+
}
16+
17+
// Validate the configuration for errors.
18+
func (c *OrchestratorExplorerConfig) Validate() error {
19+
if c.Enabled && c.ClusterName == "" {
20+
return errors.New("'cluster_name' is required when 'orchestrator_explorer' is enabled")
21+
}
22+
return nil
23+
}

0 commit comments

Comments
 (0)