Skip to content

Commit 8ea9439

Browse files
authored
Emit vars even if provider data is empty from the start (#6598)
We only signal from providers if the emitted data is different from the current state. This caused a bug where the data wasn't ever emitted if it was empty. The provider controller now distinguishes between no data (yet) and empty data. As a result, it's again possible to effectively disable all providers by using a local provider with no data. This is a regression caused by #6114. It doesn't apply to the main and 8.x branches due to #6169 refactoring provider initialisation in those.
1 parent 25fc10a commit 8ea9439

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Emit vars even if provider data is empty from the start
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: elastic-agent
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
#pr: https://github.com/owner/repo/1234
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

internal/pkg/composable/controller.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ func New(log *logger.Logger, c *config.Config, managed bool) (Controller, error)
7979
if err != nil {
8080
return nil, errors.New(err, fmt.Sprintf("failed to build provider '%s'", name), errors.TypeConfig, errors.M("provider", name))
8181
}
82-
emptyMapping, _ := transpiler.NewAST(nil)
8382
contextProviders[name] = &contextProviderState{
8483
// Safe for Context to be nil here because it will be filled in
8584
// by (*controller).Run before the provider is started.
8685
provider: provider,
87-
mapping: emptyMapping,
8886
}
8987
}
9088

@@ -279,7 +277,10 @@ func (c *controller) generateVars(fetchContextProviders mapstr.M) []*transpiler.
279277
vars := make([]*transpiler.Vars, 1)
280278
mapping, _ := transpiler.NewAST(map[string]any{})
281279
for name, state := range c.contextProviders {
282-
_ = mapping.Insert(state.Current(), name)
280+
providerMapping := state.Current()
281+
if providerMapping != nil { // the provider may not have emitted any data yet
282+
_ = mapping.Insert(providerMapping, name)
283+
}
283284
}
284285
// this is ensured not to error, by how the mappings states are verified
285286
vars[0] = transpiler.NewVarsFromAst("", mapping, fetchContextProviders)

internal/pkg/composable/controller_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ func TestProvidersDefaultDisabled(t *testing.T) {
146146
},
147147
want: 0,
148148
},
149+
{
150+
name: "default disabled, local provider without data",
151+
cfg: map[string]interface{}{
152+
"agent.providers.initial_default": "false",
153+
"providers": map[string]any{
154+
"local": map[string]any{},
155+
},
156+
},
157+
want: 1,
158+
},
149159
{
150160
name: "default enabled",
151161
cfg: map[string]interface{}{

0 commit comments

Comments
 (0)