@@ -37,6 +37,48 @@ type HeadersProvider interface {
3737
3838type RuntimeManager string
3939
40+ type RuntimeConfig struct {
41+ Default string `yaml:"default" config:"default" json:"default"`
42+ InputType map [string ]string `yaml:",inline,omitempty" config:",inline,omitempty" json:",inline,omitempty"`
43+ }
44+
45+ func DefaultRuntimeConfig () * RuntimeConfig {
46+ return & RuntimeConfig {
47+ Default : string (DefaultRuntimeManager ),
48+ }
49+ }
50+
51+ func (r * RuntimeConfig ) Validate () error {
52+ validateRuntime := func (val string ) error {
53+ switch RuntimeManager (val ) {
54+ case OtelRuntimeManager , ProcessRuntimeManager :
55+ return nil
56+ default :
57+ return fmt .Errorf ("invalid runtime manager: %s, must be either %s or %s" ,
58+ val , OtelRuntimeManager , ProcessRuntimeManager )
59+ }
60+ }
61+ if err := validateRuntime (r .Default ); err != nil {
62+ return err
63+ }
64+ for _ , val := range r .InputType {
65+ if err := validateRuntime (val ); err != nil {
66+ return err
67+ }
68+ }
69+ return nil
70+ }
71+
72+ func (r * RuntimeConfig ) RuntimeManagerForInputType (inputType string ) RuntimeManager {
73+ if manager , ok := r .InputType [inputType ]; ok {
74+ return RuntimeManager (manager )
75+ }
76+ if r .Default != "" {
77+ return RuntimeManager (r .Default )
78+ }
79+ return DefaultRuntimeManager
80+ }
81+
4082const (
4183 // defaultUnitLogLevel is the default log level that a unit will get if one is not defined.
4284 defaultUnitLogLevel = client .UnitLogLevelInfo
@@ -339,12 +381,13 @@ type Model struct {
339381// the current runtime specification.
340382func (r * RuntimeSpecs ) ToComponents (
341383 policy map [string ]interface {},
384+ runtimeCfg * RuntimeConfig ,
342385 monitoringInjector GenerateMonitoringCfgFn ,
343386 ll logp.Level ,
344387 headers HeadersProvider ,
345388 currentServiceCompInts map [string ]uint64 ,
346389) ([]Component , error ) {
347- components , err := r .PolicyToComponents (policy , ll , headers )
390+ components , err := r .PolicyToComponents (policy , runtimeCfg , ll , headers )
348391 if err != nil {
349392 return nil , err
350393 }
@@ -357,7 +400,7 @@ func (r *RuntimeSpecs) ToComponents(
357400
358401 if monitoringCfg != nil {
359402 // monitoring is enabled
360- monitoringComps , err := r .PolicyToComponents (monitoringCfg , ll , headers )
403+ monitoringComps , err := r .PolicyToComponents (monitoringCfg , runtimeCfg , ll , headers )
361404 if err != nil {
362405 return nil , fmt .Errorf ("failed to generate monitoring components: %w" , err )
363406 }
@@ -499,6 +542,7 @@ func (r *RuntimeSpecs) componentsForOutput(output outputI, featureFlags *feature
499542// PolicyToComponents takes the policy and generates a component model.
500543func (r * RuntimeSpecs ) PolicyToComponents (
501544 policy map [string ]interface {},
545+ runtimeCfg * RuntimeConfig ,
502546 ll logp.Level ,
503547 headers HeadersProvider ,
504548) ([]Component , error ) {
@@ -508,7 +552,7 @@ func (r *RuntimeSpecs) PolicyToComponents(
508552 return nil , fmt .Errorf ("could not parse feature flags from policy: %w" , err )
509553 }
510554
511- outputsMap , err := toIntermediate (policy , r .aliasMapping , ll , headers )
555+ outputsMap , err := toIntermediate (policy , runtimeCfg , r .aliasMapping , ll , headers )
512556 if err != nil {
513557 return nil , err
514558 }
@@ -576,7 +620,13 @@ func injectInputPolicyID(fleetPolicy map[string]interface{}, inputConfig map[str
576620
577621// toIntermediate takes the policy and returns it into an intermediate representation that is easier to map into a set
578622// of components.
579- func toIntermediate (policy map [string ]interface {}, aliasMapping map [string ]string , ll logp.Level , headers HeadersProvider ) (map [string ]outputI , error ) {
623+ func toIntermediate (
624+ policy map [string ]interface {},
625+ runtimeCfg * RuntimeConfig ,
626+ aliasMapping map [string ]string ,
627+ ll logp.Level ,
628+ headers HeadersProvider ,
629+ ) (map [string ]outputI , error ) {
580630 const (
581631 outputsKey = "outputs"
582632 enabledKey = "enabled"
@@ -728,7 +778,7 @@ func toIntermediate(policy map[string]interface{}, aliasMapping map[string]strin
728778 return nil , fmt .Errorf ("invalid 'inputs.%d.log_level', %w" , idx , err )
729779 }
730780
731- runtimeManager := DefaultRuntimeManager
781+ runtimeManager := runtimeCfg . RuntimeManagerForInputType ( t )
732782 // determine the runtime manager for the input
733783 if runtimeManagerRaw , ok := input [runtimeManagerKey ]; ok {
734784 runtimeManagerStr , ok := runtimeManagerRaw .(string )
0 commit comments