-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Ingest Manager] Retryable downloads of beats #19102
Merged
michalpristas
merged 6 commits into
elastic:master
from
michalpristas:agent-remove-on-failed-verification
Jun 12, 2020
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b77bccf
retryable downloads
michalpristas 5729ecb
removed debug
michalpristas 9c3bb15
unit tests
michalpristas ea010e9
Merge branch 'master' into agent-remove-on-failed-verification
michalpristas f76b8a9
retryable matches operation interface update
michalpristas abafd11
fmt
michalpristas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
x-pack/elastic-agent/pkg/agent/operation/operation_retryable.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package operation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" | ||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/plugin/retry" | ||
) | ||
|
||
// retryableOperations consists of multiple operations which are | ||
// retryable as a whole. | ||
// if nth operation fails all preceding are retried as well | ||
type retryableOperations struct { | ||
logger *logger.Logger | ||
operations []operation | ||
retryConfig *retry.Config | ||
} | ||
|
||
func newRetryableOperations( | ||
logger *logger.Logger, | ||
retryConfig *retry.Config, | ||
operations ...operation) *retryableOperations { | ||
|
||
return &retryableOperations{ | ||
logger: logger, | ||
retryConfig: retryConfig, | ||
operations: operations, | ||
} | ||
} | ||
|
||
// Name is human readable name identifying an operation | ||
func (o *retryableOperations) Name() string { | ||
names := make([]string, 0, len(o.operations)) | ||
for _, op := range o.operations { | ||
names = append(names, op.Name()) | ||
} | ||
return fmt.Sprintf("retryable block: %s", strings.Join(names, " ")) | ||
} | ||
|
||
// Check checks whether operation needs to be run | ||
// examples: | ||
// - Start does not need to run if process is running | ||
// - Fetch does not need to run if package is already present | ||
func (o *retryableOperations) Check() (bool, error) { | ||
for _, op := range o.operations { | ||
// finish early if at least one operation needs to be run or errored out | ||
if run, err := op.Check(); err != nil || run { | ||
return run, err | ||
} | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
// Run runs the operation | ||
func (o *retryableOperations) Run(ctx context.Context, application Application) (err error) { | ||
return retry.Do(ctx, o.retryConfig, o.runOnce(application)) | ||
} | ||
|
||
// Run runs the operation | ||
func (o *retryableOperations) runOnce(application Application) func(context.Context) error { | ||
return func(ctx context.Context) error { | ||
for _, op := range o.operations { | ||
if ctx.Err() != nil { | ||
return ctx.Err() | ||
} | ||
|
||
shouldRun, err := op.Check() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !shouldRun { | ||
continue | ||
} | ||
|
||
o.logger.Debugf("running operation '%s' of the block '%s'", op.Name(), o.Name()) | ||
if err := op.Run(ctx, application); err != nil { | ||
o.logger.Errorf("operation %s failed", op.Name()) | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
x-pack/elastic-agent/pkg/artifact/download/fs/testdata/drop/beat-8.0.0-darwin-x86_64.tar.gz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sample | ||
content | ||
of | ||
a | ||
file |
1 change: 1 addition & 0 deletions
1
...astic-agent/pkg/artifact/download/fs/testdata/drop/beat-8.0.0-darwin-x86_64.tar.gz.sha512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9af9aa016f3349aa248034629e4336ca2f4d31317bfb8c9a23a9d924c18969cf43ad93727e784da010a272690b2b5ce4c4ded3a5d2039e4408e93e1e18d113db beat-8.0.0-darwin-x86_64.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check()
has becomeCheck(app Application)
. Need to update this.