Skip to content

Commit

Permalink
move sysprobe config fetcher into subpackage
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Sep 26, 2024
1 parent 13b26f1 commit f027b57
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/pkg/api/util"
"github.com/DataDog/datadog-agent/pkg/config/fetcher"
fetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher/sysprobe"
"github.com/DataDog/datadog-agent/pkg/config/settings"
settingshttp "github.com/DataDog/datadog-agent/pkg/config/settings/http"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl"
"github.com/DataDog/datadog-agent/pkg/config/env"
configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher"
sysprobeConfigFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher/sysprobe"
"github.com/DataDog/datadog-agent/pkg/config/model"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/serializer"
Expand Down Expand Up @@ -60,7 +61,7 @@ var (
fetchSecurityConfig = configFetcher.SecurityAgentConfig
fetchProcessConfig = func(cfg model.Reader) (string, error) { return configFetcher.ProcessAgentConfig(cfg, true) }
fetchTraceConfig = configFetcher.TraceAgentConfig
fetchSystemProbeConfig = configFetcher.SystemProbeConfig
fetchSystemProbeConfig = sysprobeConfigFetcher.SystemProbeConfig
)

type agentMetadata map[string]interface{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher"
sysprobeConfigFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher/sysprobe"
pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/serializer"
Expand Down Expand Up @@ -456,7 +457,7 @@ func TestFetchSystemProbeAgent(t *testing.T) {
}

defer func() {
fetchSystemProbeConfig = configFetcher.SystemProbeConfig
fetchSystemProbeConfig = sysprobeConfigFetcher.SystemProbeConfig
}()
fetchSystemProbeConfig = func(config pkgconfigmodel.Reader) (string, error) {
// test that the system-probe config was passed and not the agent config
Expand Down
2 changes: 1 addition & 1 deletion comp/metadata/systemprobe/impl/system_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/DataDog/datadog-agent/comp/metadata/internal/util"
"github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl"
systemprobemetadata "github.com/DataDog/datadog-agent/comp/metadata/systemprobe/def"
configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher"
configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher/sysprobe"
"github.com/DataDog/datadog-agent/pkg/config/model"
"github.com/DataDog/datadog-agent/pkg/serializer"
"github.com/DataDog/datadog-agent/pkg/serializer/marshaler"
Expand Down
2 changes: 1 addition & 1 deletion comp/metadata/systemprobe/impl/system_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
logmock "github.com/DataDog/datadog-agent/comp/core/log/mock"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher"
configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher/sysprobe"
"github.com/DataDog/datadog-agent/pkg/config/model"
serializermock "github.com/DataDog/datadog-agent/pkg/serializer/mocks"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
Expand Down
17 changes: 0 additions & 17 deletions pkg/config/fetcher/from_processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"time"

"github.com/DataDog/datadog-agent/cmd/system-probe/api/client"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/pkg/api/util"
settingshttp "github.com/DataDog/datadog-agent/pkg/config/settings/http"
Expand Down Expand Up @@ -107,19 +106,3 @@ func ProcessAgentConfig(config config.Reader, getEntireConfig bool) (string, err

return client.FullConfig()
}

// SystemProbeConfig fetch the configuration from the system-probe process by querying its API
func SystemProbeConfig(config config.Reader) (string, error) {
hc := client.Get(config.GetString("system_probe_config.sysprobe_socket"))

c := settingshttp.NewClient(hc, "http://localhost/config", "system-probe", settingshttp.NewHTTPClientOptions(util.CloseConnection))
return c.FullConfig()
}

// SystemProbeConfigBySource fetch the all configuration layers from the system-probe process by querying its API
func SystemProbeConfigBySource(config config.Reader) (string, error) {
hc := client.Get(config.GetString("system_probe_config.sysprobe_socket"))

c := settingshttp.NewClient(hc, "http://localhost/config", "system-probe", settingshttp.NewHTTPClientOptions(util.CloseConnection))
return c.FullConfigBySource()
}
32 changes: 32 additions & 0 deletions pkg/config/fetcher/sysprobe/from_sysprobe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

// Package sysprobe is a collection of high level helpers to pull the configuration from system-probe.
// Is it separated from the other helpers in the parent package to avoid unnecessary imports in processes
// that have no need to directly communicate with system-probe.
package sysprobe

import (
"github.com/DataDog/datadog-agent/cmd/system-probe/api/client"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/pkg/api/util"
settingshttp "github.com/DataDog/datadog-agent/pkg/config/settings/http"
)

// SystemProbeConfig fetch the configuration from the system-probe process by querying its API
func SystemProbeConfig(config config.Reader) (string, error) {
hc := client.Get(config.GetString("system_probe_config.sysprobe_socket"))

c := settingshttp.NewClient(hc, "http://localhost/config", "system-probe", settingshttp.NewHTTPClientOptions(util.CloseConnection))
return c.FullConfig()
}

// SystemProbeConfigBySource fetch the all configuration layers from the system-probe process by querying its API
func SystemProbeConfigBySource(config config.Reader) (string, error) {
hc := client.Get(config.GetString("system_probe_config.sysprobe_socket"))

c := settingshttp.NewClient(hc, "http://localhost/config", "system-probe", settingshttp.NewHTTPClientOptions(util.CloseConnection))
return c.FullConfigBySource()
}

0 comments on commit f027b57

Please sign in to comment.