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

Fix/panic with composable renderer #823

Merged
merged 5 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -112,6 +112,7 @@
- Allow the / char in variable names in eql and transpiler. {issue}715[715] {pull}718[718]
- Fix data duplication for standalone agent on Kubernetes using the default manifest {issue-beats}31512[31512] {pull}742[742]
- Agent updates will clean up unneeded artifacts. {issue}693[693] {issue}694[694] {pull}752[752]
- Fix a panic caused by a race condition when installing the Elastic Agent. {issues}806[806]

==== New features

Expand Down
27 changes: 22 additions & 5 deletions internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"runtime"
"strings"
"sync"
"time"

"github.com/kardianos/service"

Expand Down Expand Up @@ -233,19 +234,35 @@ func applyDynamics(ctx context.Context, log *logger.Logger, cfg *config.Config)
inputs, ok := transpiler.Lookup(ast, "inputs")
if ok {
varsArray := make([]*transpiler.Vars, 0)
var wg sync.WaitGroup
wg.Add(1)

// Give some time for the providers to replace the variables
const timeout = 15 * time.Second
var doOnce sync.Once
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

ph marked this conversation as resolved.
Show resolved Hide resolved
// The composable system will continuously run, we are only interested in the first run on of the
// renderer to collect the variables we should stop the execution.
varsCallback := func(vv []*transpiler.Vars) {
varsArray = vv
wg.Done()
doOnce.Do(func() {
varsArray = vv
cancel()
})
}

ctrl, err := composable.New(log, cfg)
if err != nil {
return nil, err
}
_ = ctrl.Run(ctx, varsCallback)
wg.Wait()

// Wait for the first callback to retrieve the variables from the providers.
<-ctx.Done()

// Bail out if callback was not executed in time.
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, errors.New("failed to get transpiler vars", err)
}

renderedInputs, err := transpiler.RenderInputs(inputs, varsArray)
if err != nil {
Expand Down