-
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
[Elastic Agent] Fix invalid log level sent to endpoint #25854
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// 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 storage | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/hectane/go-acl" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/file" | ||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" | ||
) | ||
|
||
// NewDiskStore creates an unencrypted disk store. | ||
func NewDiskStore(target string) *DiskStore { | ||
return &DiskStore{target: target} | ||
} | ||
|
||
// Exists check if the store file exists on the disk | ||
func (d *DiskStore) Exists() (bool, error) { | ||
_, err := os.Stat(d.target) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
// Delete deletes the store file on the disk | ||
func (d *DiskStore) Delete() error { | ||
return os.Remove(d.target) | ||
} | ||
|
||
// Save accepts a persistedConfig and saved it to a target file, to do so we will | ||
// make a temporary files if the write is successful we are replacing the target file with the | ||
// original content. | ||
func (d *DiskStore) Save(in io.Reader) error { | ||
tmpFile := d.target + ".tmp" | ||
|
||
fd, err := os.OpenFile(tmpFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, perms) | ||
if err != nil { | ||
return errors.New(err, | ||
fmt.Sprintf("could not save to %s", tmpFile), | ||
errors.TypeFilesystem, | ||
errors.M(errors.MetaKeyPath, tmpFile)) | ||
} | ||
|
||
// Always clean up the temporary file and ignore errors. | ||
defer os.Remove(tmpFile) | ||
|
||
if _, err := io.Copy(fd, in); err != nil { | ||
return errors.New(err, "could not save content on disk", | ||
errors.TypeFilesystem, | ||
errors.M(errors.MetaKeyPath, tmpFile)) | ||
} | ||
|
||
if err := fd.Close(); err != nil { | ||
urso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return errors.New(err, "could not close temporary file", | ||
errors.TypeFilesystem, | ||
errors.M(errors.MetaKeyPath, tmpFile)) | ||
} | ||
|
||
if err := file.SafeFileRotate(d.target, tmpFile); err != nil { | ||
return errors.New(err, | ||
fmt.Sprintf("could not replace target file %s", d.target), | ||
errors.TypeFilesystem, | ||
errors.M(errors.MetaKeyPath, d.target)) | ||
} | ||
|
||
if err := acl.Chmod(d.target, perms); err != nil { | ||
return errors.New(err, | ||
fmt.Sprintf("could not set permissions target file %s", d.target), | ||
errors.TypeFilesystem, | ||
errors.M(errors.MetaKeyPath, d.target)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Load return a io.ReadCloser for the target file. | ||
func (d *DiskStore) Load() (io.ReadCloser, error) { | ||
fd, err := os.OpenFile(d.target, os.O_RDONLY|os.O_CREATE, perms) | ||
if err != nil { | ||
return nil, errors.New(err, | ||
fmt.Sprintf("could not open %s", d.target), | ||
errors.TypeFilesystem, | ||
errors.M(errors.MetaKeyPath, d.target)) | ||
} | ||
return fd, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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 storage | ||
|
||
import "io" | ||
|
||
type handlerFunc func(io.Reader) error | ||
|
||
// HandlerStore take a function handler and wrap it into the store interface. | ||
type HandlerStore struct { | ||
fn handlerFunc | ||
} | ||
|
||
// NewHandlerStore takes a function and wrap it into an handlerStore. | ||
func NewHandlerStore(fn handlerFunc) *HandlerStore { | ||
return &HandlerStore{fn: fn} | ||
} | ||
|
||
// Save calls the handler. | ||
func (h *HandlerStore) Save(in io.Reader) error { | ||
return h.fn(in) | ||
} |
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,15 @@ | ||
// 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 storage | ||
|
||
import "io" | ||
|
||
// NullStore this is only use to split the work into multiples PRs. | ||
type NullStore struct{} | ||
|
||
// Save takes the fleetConfig and persist it, will return an errors on failure. | ||
func (m *NullStore) Save(_ io.Reader) error { | ||
return nil | ||
} |
Oops, something went wrong.
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.
You might want to open your file with
O_DIRECT
.