Skip to content

Commit

Permalink
Add support for hints' based autodiscovery in kubernetes provider (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark authored Sep 14, 2022
1 parent eb3a698 commit 59f9ac4
Show file tree
Hide file tree
Showing 40 changed files with 745 additions and 96 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,4 @@
- Redact sensitive information on diagnostics collect command. {issue}[241] {pull}[566]
- Fix incorrectly creating a filebeat redis input when a policy contains a packetbeat redis input. {issue}[427] {pull}[700]
- Add `lumberjack` input type to the Filebeat spec. {pull}[959]
- Add support for hints' based autodiscovery in kubernetes provider. {pull}[698]
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,11 @@ you may not use this file except in compliance with the Elastic License.

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-autodiscover
Version: v0.0.0-20220404145827-89887023c1ab
Version: v0.2.1
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.0.0-20220404145827-89887023c1ab/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.2.1/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/coreos/go-systemd/v22 v22.3.2
github.com/docker/go-units v0.4.0
github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4
github.com/elastic/elastic-agent-autodiscover v0.0.0-20220404145827-89887023c1ab
github.com/elastic/elastic-agent-autodiscover v0.2.1
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6
github.com/elastic/elastic-agent-libs v0.2.6
github.com/elastic/elastic-agent-system-metrics v0.3.0
Expand Down Expand Up @@ -119,7 +119,6 @@ require (
go.elastic.co/apm/v2 v2.0.0 // indirect
go.elastic.co/fastjson v1.1.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ github.com/Microsoft/hcsshim v0.8.14/go.mod h1:NtVKoYxQuTLx6gEq0L96c9Ju4JbRJ4nY2
github.com/Microsoft/hcsshim v0.8.15/go.mod h1:x38A4YbHbdxJtc0sF6oIz+RG0npwSCAvn69iY6URG00=
github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600=
github.com/Microsoft/hcsshim v0.8.21/go.mod h1:+w2gRZ5ReXQhFOrvSQeNfhrYB/dg3oDwTOcER2fw4I4=
github.com/Microsoft/hcsshim v0.8.24/go.mod h1:4zegtUJth7lAvFyc6cH2gGQ5B3OFQim01nnU2M8jKDg=
github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU=
github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
Expand Down Expand Up @@ -227,6 +228,7 @@ github.com/containerd/cgroups v0.0.0-20200710171044-318312a37340/go.mod h1:s5q4S
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4SojHctfxANBDvMeIaIovkq29IP48TKAxnhYRxvo=
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8=
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE=
Expand All @@ -240,6 +242,7 @@ github.com/containerd/containerd v1.3.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMX
github.com/containerd/containerd v1.4.0-beta.2.0.20200729163537-40b22ef07410/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.4.1/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.4.3/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.4.9/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.5.0-beta.1/go.mod h1:5HfvG1V2FsKesEGQ17k5/T7V960Tmcumvqn8Mc+pCYQ=
github.com/containerd/containerd v1.5.0-beta.3/go.mod h1:/wr9AVtEM7x9c+n0+stptlo/uBBoBORwEx6ardVcmKU=
github.com/containerd/containerd v1.5.0-beta.4/go.mod h1:GmdgZd2zA2GYIBZ0w09ZvgqEq8EfBp/m3lcVZIvPHhI=
Expand Down Expand Up @@ -281,6 +284,7 @@ github.com/containerd/ttrpc v0.0.0-20190828172938-92c8520ef9f8/go.mod h1:PvCDdDG
github.com/containerd/ttrpc v0.0.0-20191028202541-4f1b8fe65a5c/go.mod h1:LPm1u0xBw8r8NOKoOdNMeVHSawSsltak+Ihv+etqsE8=
github.com/containerd/ttrpc v1.0.1/go.mod h1:UAxOpgT9ziI0gJrmKvgcZivgxOp8iFPSk8httJEt98Y=
github.com/containerd/ttrpc v1.0.2/go.mod h1:UAxOpgT9ziI0gJrmKvgcZivgxOp8iFPSk8httJEt98Y=
github.com/containerd/ttrpc v1.1.0/go.mod h1:XX4ZTnoOId4HklF4edwc4DcqskFZuvXB1Evzy5KFQpQ=
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc=
github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd/go.mod h1:GeKYzf2pQcqv7tJ0AoCuuhtnqhva5LNU3U+OyKxxJpk=
github.com/containerd/typeurl v1.0.1/go.mod h1:TB1hUtrpaiO88KEK56ijojHS1+NeF0izUACaJW2mdXg=
Expand Down Expand Up @@ -375,11 +379,11 @@ github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:Htrtb
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4 h1:uYT+Krd8dsvnhnLK9pe/JHZkYtXEGPfbV4Wt1JPPol0=
github.com/elastic/e2e-testing v1.99.2-0.20220117192005-d3365c99b9c4/go.mod h1:UcNuf4pX/qDVNQr0zybm1NL2YoWik+jKBaINZqQCA40=
github.com/elastic/elastic-agent-autodiscover v0.0.0-20220404145827-89887023c1ab h1:Jk6Mfk5BF8gtfE7X0bNCiDGBtwJVxRI79b4wLCAsP+A=
github.com/elastic/elastic-agent-autodiscover v0.0.0-20220404145827-89887023c1ab/go.mod h1:Gg1fsQI+rVms9FJ2DefBSojfPIzgkV8xlyG8fPG0DE8=
github.com/elastic/elastic-agent-autodiscover v0.2.1 h1:Nbeayh3vq2FNm6xaFo34mhUdOu0EVlpj53CqCsbU0E4=
github.com/elastic/elastic-agent-autodiscover v0.2.1/go.mod h1:gPnzzfdYNdgznAb+iG9eyyXaQXBbAMHa+Y6Z8hXfcGY=
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6 h1:nFvXHBjYK3e9+xF0WKDeAKK4aOO51uC28s+L9rBmilo=
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6/go.mod h1:uh/Gj9a0XEbYoM4NYz4LvaBVARz3QXLmlNjsrKY9fTc=
github.com/elastic/elastic-agent-libs v0.0.0-20220303160015-5b4e674da3dd/go.mod h1://82M1l73IHx0wDbS2Tzkq6Fx9fkmytS1KgkIyzvNTM=
github.com/elastic/elastic-agent-libs v0.2.5/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
github.com/elastic/elastic-agent-libs v0.2.6 h1:DpcUcCVYZ7lNtHLUlyT1u/GtGAh49wpL15DTH7+8O5o=
github.com/elastic/elastic-agent-libs v0.2.6/go.mod h1:chO3rtcLyGlKi9S0iGVZhYCzDfdDsAQYBc+ui588AFE=
github.com/elastic/elastic-agent-system-metrics v0.3.0 h1:W8L0E8lWJmdguH+oIR7OzuFgopvw8ucZAE9w6iqVlpE=
Expand All @@ -390,6 +394,7 @@ github.com/elastic/go-elasticsearch/v8 v8.0.0-20210317102009-a9d74cec0186/go.mod
github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ=
github.com/elastic/go-licenser v0.4.0 h1:jLq6A5SilDS/Iz1ABRkO6BHy91B9jBora8FwGRsDqUI=
github.com/elastic/go-licenser v0.4.0/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU=
github.com/elastic/go-structform v0.0.9/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
github.com/elastic/go-structform v0.0.10 h1:oy08o/Ih2hHTkNcRY/1HhaYvIp5z6t8si8gnCJPDo1w=
github.com/elastic/go-structform v0.0.10/go.mod h1:CZWf9aIRYY5SuKSmOhtXScE5uQiLZNqAFnwKR4OrIM4=
github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0=
Expand Down Expand Up @@ -946,7 +951,6 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.0/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
Expand Down Expand Up @@ -1397,6 +1401,7 @@ golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/local_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func newLocal(
}
localApplication.router = router

composableCtrl, err := composable.New(log, rawConfig)
composableCtrl, err := composable.New(log, rawConfig, false)
if err != nil {
return nil, errors.New(err, "failed to initialize composable controller")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/managed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func newManaged(
}
managedApplication.router = router

composableCtrl, err := composable.New(log, rawConfig)
composableCtrl, err := composable.New(log, rawConfig, true)
if err != nil {
return nil, errors.New(err, "failed to initialize composable controller")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/managed_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestManagedModeRouting(t *testing.T) {
router, _ := router.New(log, streamFn)
agentInfo, _ := info.NewAgentInfo(true)
nullStore := &storage.NullStore{}
composableCtrl, _ := composable.New(log, nil)
composableCtrl, _ := composable.New(log, nil, true)
emit, err := emitter.New(ctx, log, agentInfo, composableCtrl, router, &pipeline.ConfigModifiers{Decorators: []pipeline.DecoratorFunc{modifiers.InjectMonitoring}}, nil)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func getProgramsFromConfig(log *logger.Logger, agentInfo *info.AgentInfo, cfg *c
router := &inmemRouter{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
composableCtrl, err := composable.New(log, cfg)
composableCtrl, err := composable.New(log, cfg, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func applyDynamics(ctx context.Context, log *logger.Logger, cfg *config.Config)
})
}

ctrl, err := composable.New(log, cfg)
ctrl, err := composable.New(log, cfg, false)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion internal/pkg/composable/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

// ContextProviderBuilder creates a new context provider based on the given config and returns it.
type ContextProviderBuilder func(log *logger.Logger, config *config.Config) (corecomp.ContextProvider, error)
type ContextProviderBuilder func(log *logger.Logger, config *config.Config, managed bool) (corecomp.ContextProvider, error)

//nolint:dupl,goimports,nolintlint // false positive
// AddContextProvider adds a new ContextProviderBuilder
func (r *providerRegistry) AddContextProvider(name string, builder ContextProviderBuilder) error {
r.lock.Lock()
Expand All @@ -24,11 +25,14 @@ func (r *providerRegistry) AddContextProvider(name string, builder ContextProvid
if name == "" {
return fmt.Errorf("provider name is required")
}

if strings.ToLower(name) != name {
return fmt.Errorf("provider name must be lowercase")
}

_, contextExists := r.contextProviders[name]
_, dynamicExists := r.dynamicProviders[name]

if contextExists || dynamicExists {
return fmt.Errorf("provider '%s' is already registered", name)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/composable/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type controller struct {
}

// New creates a new controller.
func New(log *logger.Logger, c *config.Config) (Controller, error) {
func New(log *logger.Logger, c *config.Config, managed bool) (Controller, error) {
l := log.Named("composable")

var providersCfg Config
Expand All @@ -59,7 +59,7 @@ func New(log *logger.Logger, c *config.Config) (Controller, error) {
// explicitly disabled; skipping
continue
}
provider, err := builder(l, pCfg)
provider, err := builder(l, pCfg, managed)
if err != nil {
return nil, errors.New(err, fmt.Sprintf("failed to build provider '%s'", name), errors.TypeConfig, errors.M("provider", name))
}
Expand All @@ -76,7 +76,7 @@ func New(log *logger.Logger, c *config.Config) (Controller, error) {
// explicitly disabled; skipping
continue
}
provider, err := builder(l.Named(strings.Join([]string{"providers", name}, ".")), pCfg)
provider, err := builder(l.Named(strings.Join([]string{"providers", name}, ".")), pCfg, managed)
if err != nil {
return nil, errors.New(err, fmt.Sprintf("failed to build provider '%s'", name), errors.TypeConfig, errors.M("provider", name))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/composable/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestController(t *testing.T) {

log, err := logger.New("", false)
require.NoError(t, err)
c, err := composable.New(log, cfg)
c, err := composable.New(log, cfg, false)
require.NoError(t, err)

var wg sync.WaitGroup
Expand All @@ -99,14 +99,14 @@ func TestController(t *testing.T) {
_, envExists := setVars[0].Lookup("env")
assert.False(t, envExists)
local, _ := setVars[0].Lookup("local")
localMap := local.(map[string]interface{})
localMap, _ := local.(map[string]interface{})
assert.Equal(t, "value1", localMap["key1"])

local, _ = setVars[1].Lookup("local_dynamic")
localMap = local.(map[string]interface{})
localMap, _ = local.(map[string]interface{})
assert.Equal(t, "value1", localMap["key1"])

local, _ = setVars[2].Lookup("local_dynamic")
localMap = local.(map[string]interface{})
localMap, _ = local.(map[string]interface{})
assert.Equal(t, "value2", localMap["key1"])
}
25 changes: 13 additions & 12 deletions internal/pkg/composable/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,31 @@ type DynamicProvider interface {
}

// DynamicProviderBuilder creates a new dynamic provider based on the given config and returns it.
type DynamicProviderBuilder func(log *logger.Logger, config *config.Config) (DynamicProvider, error)
type DynamicProviderBuilder func(log *logger.Logger, config *config.Config, managed bool) (DynamicProvider, error)

//nolint:dupl,goimports,nolintlint // false positive
// AddDynamicProvider adds a new DynamicProviderBuilder
func (r *providerRegistry) AddDynamicProvider(name string, builder DynamicProviderBuilder) error {
func (r *providerRegistry) AddDynamicProvider(providerName string, builder DynamicProviderBuilder) error {
r.lock.Lock()
defer r.lock.Unlock()

if name == "" {
return fmt.Errorf("provider name is required")
if providerName == "" {
return fmt.Errorf("provider providerName is required")
}
if strings.ToLower(name) != name {
return fmt.Errorf("provider name must be lowercase")
if strings.ToLower(providerName) != providerName {
return fmt.Errorf("provider providerName must be lowercase")
}
_, contextExists := r.contextProviders[name]
_, dynamicExists := r.dynamicProviders[name]
_, contextExists := r.contextProviders[providerName]
_, dynamicExists := r.dynamicProviders[providerName]
if contextExists || dynamicExists {
return fmt.Errorf("provider '%s' is already registered", name)
return fmt.Errorf("provider '%s' is already registered", providerName)
}
if builder == nil {
return fmt.Errorf("provider '%s' cannot be registered with a nil factory", name)
return fmt.Errorf("provider '%s' cannot be registered with a nil factory", providerName)
}

r.dynamicProviders[name] = builder
r.logger.Debugf("Registered provider: %s", name)
r.dynamicProviders[providerName] = builder
r.logger.Debugf("Registered provider: %s", providerName)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/composable/providers/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func init() {
composable.Providers.AddContextProvider("agent", ContextProviderBuilder)
_ = composable.Providers.AddContextProvider("agent", ContextProviderBuilder)
}

type contextProvider struct{}
Expand All @@ -42,6 +42,6 @@ func (*contextProvider) Run(comm corecomp.ContextProviderComm) error {
}

// ContextProviderBuilder builds the context provider.
func ContextProviderBuilder(_ *logger.Logger, _ *config.Config) (corecomp.ContextProvider, error) {
func ContextProviderBuilder(_ *logger.Logger, _ *config.Config, managed bool) (corecomp.ContextProvider, error) {
return &contextProvider{}, nil
}
2 changes: 1 addition & 1 deletion internal/pkg/composable/providers/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestContextProvider(t *testing.T) {
testutils.InitStorage(t)

builder, _ := composable.Providers.GetContextProvider("agent")
provider, err := builder(nil, nil)
provider, err := builder(nil, nil, true)
require.NoError(t, err)

comm := ctesting.NewContextComm(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/composable/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *dynamicProvider) Run(comm composable.DynamicProviderComm) error {
}

// DynamicProviderBuilder builds the dynamic provider.
func DynamicProviderBuilder(logger *logger.Logger, c *config.Config) (composable.DynamicProvider, error) {
func DynamicProviderBuilder(logger *logger.Logger, c *config.Config, managed bool) (composable.DynamicProvider, error) {
var cfg Config
if c == nil {
c = config.New()
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/composable/providers/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func init() {
composable.Providers.AddContextProvider("env", ContextProviderBuilder)
_ = composable.Providers.AddContextProvider("env", ContextProviderBuilder)
}

type contextProvider struct{}
Expand All @@ -31,7 +31,7 @@ func (*contextProvider) Run(comm corecomp.ContextProviderComm) error {
}

// ContextProviderBuilder builds the context provider.
func ContextProviderBuilder(_ *logger.Logger, _ *config.Config) (corecomp.ContextProvider, error) {
func ContextProviderBuilder(_ *logger.Logger, _ *config.Config, managed bool) (corecomp.ContextProvider, error) {
return &contextProvider{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/composable/providers/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

func TestContextProvider(t *testing.T) {
builder, _ := composable.Providers.GetContextProvider("env")
provider, err := builder(nil, nil)
provider, err := builder(nil, nil, true)
require.NoError(t, err)

comm := ctesting.NewContextComm(context.Background())
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/composable/providers/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const DefaultCheckInterval = 5 * time.Minute

func init() {
composable.Providers.AddContextProvider("host", ContextProviderBuilder)
_ = composable.Providers.AddContextProvider("host", ContextProviderBuilder)
}

type infoFetcher func() (map[string]interface{}, error)
Expand Down Expand Up @@ -81,7 +81,7 @@ func (c *contextProvider) Run(comm corecomp.ContextProviderComm) error {
}

// ContextProviderBuilder builds the context provider.
func ContextProviderBuilder(log *logger.Logger, c *config.Config) (corecomp.ContextProvider, error) {
func ContextProviderBuilder(log *logger.Logger, c *config.Config, managed bool) (corecomp.ContextProvider, error) {
p := &contextProvider{
logger: log,
fetcher: getHostInfo,
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/composable/providers/host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func TestContextProvider(t *testing.T) {
builder, _ := composable.Providers.GetContextProvider("host")
log, err := logger.New("host_test", false)
require.NoError(t, err)
provider, err := builder(log, c)
provider, err := builder(log, c, true)
require.NoError(t, err)

hostProvider := provider.(*contextProvider)
hostProvider, _ := provider.(*contextProvider)
hostProvider.fetcher = returnHostMapping()
require.Equal(t, 100*time.Millisecond, hostProvider.CheckInterval)

Expand Down
Loading

0 comments on commit 59f9ac4

Please sign in to comment.