Skip to content

Commit

Permalink
feat(fleet): Support integrations configuration in the Fleet Policies…
Browse files Browse the repository at this point in the history
… dir (#31263)
  • Loading branch information
BaptisteFoy authored Dec 18, 2024
1 parent 52f0517 commit 5615184
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/agent/common/autodiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"errors"
"fmt"
"path/filepath"
"time"

"go.uber.org/atomic"
Expand Down Expand Up @@ -41,6 +42,10 @@ var (
)

func setupAutoDiscovery(confSearchPaths []string, wmeta workloadmeta.Component, ac autodiscovery.Component) {
if pkgconfigsetup.Datadog().GetString("fleet_policies_dir") != "" {
confSearchPaths = append(confSearchPaths, filepath.Join(pkgconfigsetup.Datadog().GetString("fleet_policies_dir"), "conf.d"))
}

providers.InitConfigFilesReader(confSearchPaths)

acTelemetryStore := ac.GetTelemetryStore()
Expand Down
1 change: 1 addition & 0 deletions comp/core/flare/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (f *flare) collectLogsFiles(fb types.FlareBuilder) error {
func (f *flare) collectConfigFiles(fb types.FlareBuilder) error {
confSearchPaths := map[string]string{
"": f.config.GetString("confd_path"),
"fleet": filepath.Join(f.config.GetString("fleet_policies_dir"), "conf.d"),
"dist": filepath.Join(f.params.distPath, "conf.d"),
"checksd": f.params.pythonChecksPath,
}
Expand Down
17 changes: 16 additions & 1 deletion comp/core/gui/guiimpl/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ var (
filepath.Join(defaultpaths.GetDistPath(), "checks.d"), // Custom checks
pkgconfigsetup.Datadog().GetString("additional_checksd"), // Custom checks
defaultpaths.PyChecksPath, // Integrations-core checks
getFleetPoliciesPath(), // Fleet Policies
}
)

// getFleetPoliciesPath returns the path to the fleet policies directory if it is set in the configuration
// otherwise it returns an empty string
func getFleetPoliciesPath() string {
if len(pkgconfigsetup.Datadog().GetString("fleet_policies_dir")) > 0 {
return filepath.Join(pkgconfigsetup.Datadog().GetString("fleet_policies_dir"), "conf.d")
}
return ""
}

// Adds the specific handlers for /checks/ endpoints
func checkHandler(r *mux.Router, collector collector.Component, ac autodiscovery.Component) {
r.HandleFunc("/running", http.HandlerFunc(sendRunningChecks)).Methods("POST")
Expand Down Expand Up @@ -208,6 +218,9 @@ func getCheckConfigFile(w http.ResponseWriter, r *http.Request) {
var file []byte
var e error
for _, path := range configPaths {
if len(path) == 0 {
continue
}
filePath, err := securejoin.SecureJoin(path, fileName)
if err != nil {
log.Errorf("Error: Unable to join config path with the file name: %s", fileName)
Expand Down Expand Up @@ -443,7 +456,9 @@ func getConfigsInPath(path string) ([]string, error) {
func listConfigs(w http.ResponseWriter, _ *http.Request) {
filenames := []string{}
for _, path := range configPaths {

if len(path) == 0 {
continue
}
configs, e := getConfigsInPath(path)
if e != nil {
log.Errorf("Unable to list configurations from %s: %v", path, e)
Expand Down

0 comments on commit 5615184

Please sign in to comment.