Skip to content

Commit

Permalink
Emit vars even if provider data is empty from the start
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
swiatekm committed Jan 24, 2025
1 parent c0caacd commit 60117ae
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
32 changes: 32 additions & 0 deletions changelog/fragments/1737735780-fix-empty-provider-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: Emit vars even if provider data is empty from the start

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: elastic-agent

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
7 changes: 4 additions & 3 deletions internal/pkg/composable/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ func New(log *logger.Logger, c *config.Config, managed bool) (Controller, error)
if err != nil {
return nil, errors.New(err, fmt.Sprintf("failed to build provider '%s'", name), errors.TypeConfig, errors.M("provider", name))
}
emptyMapping, _ := transpiler.NewAST(nil)
contextProviders[name] = &contextProviderState{
// Safe for Context to be nil here because it will be filled in
// by (*controller).Run before the provider is started.
provider: provider,
mapping: emptyMapping,
}
}

Expand Down Expand Up @@ -279,7 +277,10 @@ func (c *controller) generateVars(fetchContextProviders mapstr.M) []*transpiler.
vars := make([]*transpiler.Vars, 1)
mapping, _ := transpiler.NewAST(map[string]any{})
for name, state := range c.contextProviders {
_ = mapping.Insert(state.Current(), name)
providerMapping := state.Current()
if providerMapping != nil { // the provider may not have emitted any data yet
_ = mapping.Insert(providerMapping, name)
}
}
// this is ensured not to error, by how the mappings states are verified
vars[0] = transpiler.NewVarsFromAst("", mapping, fetchContextProviders)
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/composable/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ func TestProvidersDefaultDisabled(t *testing.T) {
},
want: 0,
},
{
name: "default disabled, local provider without data",
cfg: map[string]interface{}{
"agent.providers.initial_default": "false",
"providers": map[string]any{
"local": map[string]any{},
},
},
want: 1,
},
{
name: "default enabled",
cfg: map[string]interface{}{
Expand Down

0 comments on commit 60117ae

Please sign in to comment.