-
Notifications
You must be signed in to change notification settings - Fork 122
/
group_load.go
73 lines (64 loc) · 2.75 KB
/
group_load.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package runner
import (
"github.com/newrelic/infrastructure-agent/internal/integrations/v4/integration"
"github.com/newrelic/infrastructure-agent/pkg/integrations/cmdrequest"
"github.com/newrelic/infrastructure-agent/pkg/integrations/configrequest"
config2 "github.com/newrelic/infrastructure-agent/pkg/integrations/v4/config"
)
// LoadFn provides a basic, incomplete Group instance to be configured by the NewGroup function.
// InstancesLookup is only required to load v3 integrations from an external definitions folder.
type LoadFn func(dr integration.InstancesLookup, passthroughEnv []string, cfgPath string, cmdReqHandle cmdrequest.HandleFn, configHandle configrequest.HandleFn, terminateDefinitionQ chan string) (Group, FeaturesCache, error)
// NewLoadFn returns a function that provides partial Group holding provided configuration and
// features cache. Optionally agent and integration "features" can be provided to be able to load
// disabled integrations.
func NewLoadFn(cfg config2.YAML, agentAndCCFeatures *Features) LoadFn {
return func(il integration.InstancesLookup, passthroughEnv []string, cfgPath string, cmdReqHandle cmdrequest.HandleFn, configHandle configrequest.HandleFn, terminateDefinitionQ chan string) (g Group, c FeaturesCache, err error) {
dSources, err := cfg.Databind.DataSources()
if err != nil {
return
}
g = Group{
dSources: dSources,
cmdReqHandle: cmdReqHandle,
configHandle: configHandle,
terminateDefinitionQ: terminateDefinitionQ,
}
c = make(FeaturesCache)
for _, cfgEntry := range cfg.Integrations {
var template []byte
template, err = integration.LoadConfigTemplate(cfgEntry.TemplatePath, cfgEntry.Config)
if err != nil {
return
}
var i integration.Definition
i, err = integration.NewDefinition(cfgEntry, il, passthroughEnv, template)
if err != nil {
illog.WithField("integration_name", i.Name).
WithError(err).
Error("Failed to load integration definition")
return
}
if agentAndCCFeatures == nil {
if cfgEntry.When.Feature == "" {
// no features at all => run
g.integrations = append(g.integrations, i)
} else {
// if feature only in OHI => cache for possible later usage via CC
c[cfgEntry.When.Feature] = cfgPath
}
continue
}
// agent cfg or CC have feature, they decide:
c[cfgEntry.When.Feature] = cfgPath
if agentAndCCFeatures.IsOHIExecutable(cfgEntry.When.Feature) {
g.integrations = append(g.integrations, i)
continue
}
// feature is enabled but not executable
illog.WithField("integration_name", i.Name).Debug("Integration feature not enabled, skipping execution")
}
return
}
}