Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hints' based autodiscovery in kubernetes provider #698

Merged
merged 36 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4cffe56
WIP: Initial save commit
ChrsMark Jul 8, 2022
c048a33
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Aug 31, 2022
9d3e2f8
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Aug 31, 2022
3761e5b
Pass down managed/standalone info
ChrsMark Aug 31, 2022
d3df8e3
fix config file
ChrsMark Sep 1, 2022
ac84106
Fix calls to resource eventers
ChrsMark Sep 1, 2022
697d427
Complete list of hints
ChrsMark Sep 5, 2022
065224e
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Sep 5, 2022
a6028d9
Add container_id in top level
ChrsMark Sep 5, 2022
30bab5e
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Sep 6, 2022
8fb9369
Properly handle pods' and container's emission
ChrsMark Sep 6, 2022
f131822
Fix tests
ChrsMark Sep 6, 2022
45afd95
fix lint errors
ChrsMark Sep 6, 2022
a6add48
fix more tests
ChrsMark Sep 6, 2022
aeb6220
Fix modules
ChrsMark Sep 6, 2022
a5f1703
Fix spelling
ChrsMark Sep 6, 2022
2d62ebc
fix more lint issues
ChrsMark Sep 6, 2022
1c2d74c
fix linter
ChrsMark Sep 6, 2022
4d9aad3
fiiiix linter errors
ChrsMark Sep 6, 2022
3ba71fa
fixxx more
ChrsMark Sep 6, 2022
06aefb6
one more to go
ChrsMark Sep 6, 2022
9f002f9
Add test for hints generation
ChrsMark Sep 7, 2022
1a9802a
Fix NOTICE
ChrsMark Sep 7, 2022
d79590e
Add warning message about BETA and changelog
ChrsMark Sep 7, 2022
3ab461c
Fix linter
ChrsMark Sep 7, 2022
314bffb
Extend unit test to cover a complete scenario
ChrsMark Sep 8, 2022
ec68794
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Sep 9, 2022
3e6b8fc
Add default fallback for container logs
ChrsMark Sep 9, 2022
8b50e76
Add explanatory comment for meta replacements
ChrsMark Sep 9, 2022
3fbaf83
Proper logging in hints extraction
ChrsMark Sep 9, 2022
1e0a4a6
Fix log level
ChrsMark Sep 13, 2022
0ee7cdc
Add log stream as supported hint
ChrsMark Sep 13, 2022
05052bd
Add tests
ChrsMark Sep 13, 2022
c0bf8f5
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Sep 13, 2022
cc3e6a6
Update licence
ChrsMark Sep 13, 2022
33d9083
Merge remote-tracking branch 'upstream/main' into hints_based_autodis…
ChrsMark Sep 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,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]
90 changes: 45 additions & 45 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Elastic Beats
Copyright 2014-2022 Elasticsearch BV

This product includes software developed by The Apache Software
This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).

================================================================================
Expand Down 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 Expand Up @@ -6936,27 +6936,27 @@ Licence type (autodetected): MIT

Contents of probable licence file $GOMODCACHE/github.com/akavel/[email protected]/LICENSE.txt:

The MIT License (MIT)
Copyright (c) 2013-2017 The rsrc Authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The MIT License (MIT)

Copyright (c) 2013-2017 The rsrc Authors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


--------------------------------------------------------------------------------
Expand Down Expand Up @@ -8676,27 +8676,27 @@ Contents of probable licence file $GOMODCACHE/github.com/evanphx/[email protected]
Copyright (c) 2014, Evan Phoenix
All rights reserved.

Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Evan Phoenix nor the names of its contributors
may be used to endorse or promote products derived from this software
* Neither the name of the Evan Phoenix nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Expand Down Expand Up @@ -15816,19 +15816,19 @@ Licence type (autodetected): BSD-2-Clause
Contents of probable licence file $GOMODCACHE/gopkg.in/[email protected]/LICENSE:

Gocheck - A rich testing framework for Go

Copyright (c) 2010-2013 Gustavo Niemeyer <[email protected]>

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand Down Expand Up @@ -16013,13 +16013,13 @@ Contents of probable licence file $GOMODCACHE/howett.net/[email protected]/LICENSE:
Copyright (c) 2013, Dustin L. Howett. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -16033,7 +16033,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -17428,4 +17428,4 @@ Contents of the file that refers to the licence https://opensource.apple.com/sou
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
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
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ 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=
Expand Down Expand Up @@ -946,7 +946,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
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 @@ -141,7 +141,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
}
Loading