Skip to content

Commit 834167f

Browse files
authored
[SNMP] Retrieve device profiles from remote config (#32543)
1 parent b051f31 commit 834167f

File tree

12 files changed

+483
-74
lines changed

12 files changed

+483
-74
lines changed

cmd/agent/subcommands/run/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ func startAgent(
589589
jmxfetch.RegisterWith(ac)
590590

591591
// Set up check collector
592-
commonchecks.RegisterChecks(wmeta, tagger, cfg, telemetry)
592+
commonchecks.RegisterChecks(wmeta, tagger, cfg, telemetry, rcclient)
593593
ac.AddScheduler("check", pkgcollector.InitCheckScheduler(option.New(collector), demultiplexer, logReceiver, tagger), true)
594594

595595
demultiplexer.AddAgentStartupTelemetry(version.AgentVersion)

pkg/cli/subcommands/check/command.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ func run(
294294
// TODO: (components) - Until the checks are components we set there context so they can depends on components.
295295
check.InitializeInventoryChecksContext(invChecks)
296296
pkgcollector.InitPython(common.GetPythonPaths()...)
297-
commonchecks.RegisterChecks(wmeta, tagger, config, telemetry)
297+
// TODO Ideally we would support RC in the check subcommand,
298+
// but at the moment this is not possible - only one process can access the RC database at a time,
299+
// so the subcommand can't read the RC database if the agent is also running.
300+
commonchecks.RegisterChecks(wmeta, tagger, config, telemetry, nil)
298301

299302
common.LoadComponents(secretResolver, wmeta, ac, pkgconfigsetup.Datadog().GetString("confd_path"))
300303
ac.LoadAndRun(context.Background())

pkg/collector/corechecks/snmp/internal/checkconfig/config.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package checkconfig
99
import (
1010
"context"
1111
"fmt"
12+
"github.com/DataDog/datadog-agent/comp/remote-config/rcclient"
1213
"hash/fnv"
1314
"net"
1415
"sort"
@@ -83,6 +84,7 @@ type DeviceDigest string
8384
// InitConfig is used to deserialize integration init config
8485
type InitConfig struct {
8586
Profiles profile.ProfileConfigMap `yaml:"profiles"`
87+
UseRCProfiles bool `yaml:"use_remote_config_profiles"`
8688
GlobalMetrics []profiledefinition.MetricsConfig `yaml:"global_metrics"`
8789
OidBatchSize Number `yaml:"oid_batch_size"`
8890
BulkMaxRepetitions Number `yaml:"bulk_max_repetitions"`
@@ -266,7 +268,8 @@ func (c *CheckConfig) ToString() string {
266268
}
267269

268270
// NewCheckConfig builds a new check config
269-
func NewCheckConfig(rawInstance integration.Data, rawInitConfig integration.Data) (*CheckConfig, error) {
271+
func NewCheckConfig(rawInstance integration.Data, rawInitConfig integration.Data, rcClient rcclient.Component) (*CheckConfig,
272+
error) {
270273
instance := InstanceConfig{}
271274
initConfig := InitConfig{}
272275

@@ -430,11 +433,25 @@ func NewCheckConfig(rawInstance integration.Data, rawInitConfig integration.Data
430433
return nil, err
431434
}
432435

433-
profiles, err := profile.GetProfileProvider(initConfig.Profiles)
436+
if initConfig.UseRCProfiles {
437+
if rcClient == nil {
438+
return nil, fmt.Errorf("rc client not initialized, cannot use rc profiles")
439+
}
440+
if len(initConfig.Profiles) > 0 {
441+
// We don't support merging inline profiles with profiles fetched via remote
442+
// config - this would create too much potential for confusing scenarios where
443+
// different agents with the same remote config setup disagree on what common
444+
// profiles look like.
445+
log.Warnf("SNMP init config contains %d inline profile(s); these will be "+
446+
"ignored because use_remote_config_profiles is set", len(initConfig.Profiles))
447+
}
448+
c.ProfileProvider, err = profile.NewRCProvider(rcClient)
449+
} else {
450+
c.ProfileProvider, err = profile.GetProfileProvider(initConfig.Profiles)
451+
}
434452
if err != nil {
435453
return nil, err
436454
}
437-
c.ProfileProvider = profiles
438455

439456
// profile configs
440457
c.ProfileName = instance.Profile

0 commit comments

Comments
 (0)