@@ -9,6 +9,7 @@ package checkconfig
99import (
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
8485type 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