-
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
Make docker input check if container strings are empty #7960
Conversation
5790b47
to
4546b84
Compare
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
filebeat/input/docker/input.go
Outdated
// Docker input should make sure that no callers should ever pass empty strings as container IDs | ||
// Hence we explicitly make sure that we catch such things and print stack traces in the event of | ||
// an invocation so that it can be fixed. | ||
ids := make([]string, 0) |
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.
Use var ids []string
. https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices
filebeat/input/docker/input.go
Outdated
ids = append(ids, containerID) | ||
} else { | ||
logp.Err("Docker container ID can't be empty for Docker input config") | ||
logp.Debug("docker", "stack trace for empty docker container ID is %v", string(debug.Stack())) |
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.
fyi: The structured logger has support for logging a stack trace. No obligation to change anything - just fyi.
Normally you would create a logger instance and use it for the life of your struct/object, but this code hasn't been update to do this and it's still using the global logger. But the form would be
log := logp.NewLogger("docker")
log.Error("Docker container ID can't be empty for Docker input config")
log.Debugw("Empty Docker container container ID was received", logp.Stack("stacktrace"))
or to use the structured logger in an ad-hoc manner
logp.L().Named("docker").Debugw("Empty Docker container container ID was received", logp.Stack("stacktrace"))
filebeat/input/docker/input.go
Outdated
if containerID != "" { | ||
ids = append(ids, containerID) | ||
} else { | ||
logp.Err("Docker container ID can't be empty for Docker input config") |
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.
In what cases is the container id empty? I wonder if we should log it on the error level, meaning it's something the user can fix and then the error will disappear or it's something that just happens from time to time. In this case we better log it on the info level.
Do we really need 2 log entries or could we have just one?
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.
the 2 log entries are just to have something on record for via err
and dig further in case of a debug scenario.
we havent really figured out what the scenario is for an empty container. hence the reasoning for adding stack trace to figure out what that place could be.
4546b84
to
8980d9e
Compare
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.
Code LGTM. See fmt
comment.
filebeat/input/docker/input.go
Outdated
"github.com/elastic/beats/filebeat/input/log" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/common/cfgwarn" | ||
"fmt" |
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.
This will need make fmt
to clean up the identation.
filebeat/input/docker/input.go
Outdated
@@ -37,6 +40,10 @@ func init() { | |||
} | |||
} | |||
|
|||
var ( | |||
logger = logp.NewLogger("docker") |
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.
Move this into NewInput
. See the documentation of NewLogger
for the reason.
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.
makes sense why i didnt see that log message lol :)
8980d9e
to
130b0cf
Compare
130b0cf
to
b4b8c06
Compare
We have seen certain docker inputs being spun up with the config:
This is because of empty container IDs. This PR makes sure that we do a check of empty strings to avoid this as there might be serious repercussions if that path had a valid file.