-
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
Add support for heartbeat hints builder #13119
Conversation
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? |
1 similar comment
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? |
logger *logp.Logger | ||
} | ||
|
||
// NewLogHints builds a log hints builder |
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.
comment on exported function NewHeartbeatHints should be of the form "NewHeartbeatHints ..."
Pinging @elastic/uptime |
06db8ad
to
02939f9
Compare
Apologies for the delay, but this is something I'll look into when back from vacation in a few weeks! |
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.
Thanks for the awesome work and we're looking forward to getting this merged! This is a partial review. I haven't actually run the code yet, and would like to take a second pass.
I left some comments with mostly some minor naming concerns. I do also have some concerns about error handling I left in there. Generally, it's best to avoid any situation where we just skip doing something due to a config error without a good diagnostic log message IMHO. Would be glad to hear your thoughts on that.
|
||
// If explicty disabled, return nothing | ||
if builder.IsDisabled(hints, l.config.Key) { | ||
l.logger.Debugf("heartbeats disabled by hint: %+v", event) |
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.
`s/heartbeats/heartbeat config/
for _, monitor := range monitors { | ||
// Every monitor must have a type associated with it | ||
if _, ok := monitor[montype]; !ok { | ||
continue |
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.
It might be good to log a warning here. Otherwise, debugging config issues could be hard.
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.
i have made it a debug message
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.
Why debug? I was thinking we'd log at warn
or info
at the very least. Would that be too verbose for that use case that precipitated this PR?
} | ||
|
||
// Create config based on input hints in the bus event | ||
func (l *heartBeat) CreateConfig(event bus.Event) []*common.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.
I'm curious as to the choice of the variable name l
for *heartBeat
. Why not just hb
or h
.
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.
lol, i took the logs hints builder as a base and worked on this. copy paste
processors = "processors" | ||
) | ||
|
||
type heartBeat struct { |
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.
given that we have a public Heartbeat
struct in heartbeat.go
this is a bit confusing. Maybe we could find a better name here. One idea is hintsContext
.
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package hints |
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.
It feels odd to name this file heartbeats.go
, That implies that it has some plural relationship to heartbeat
. Maybe hints.go
?
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.
i just followed the convention for logs and metrics hints builder in filebeat and metricbeat.
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.
Ah, I see. Looking at metric beat it named its file metrics
. Given that I think the right name here is monitors.go
. It seems the convention is to name the file the same as the noun of the thing it is generating, which in heartbeat's case is a monitor.
} else if port == 0 && !strings.Contains(h, ":") { | ||
// For ICMP like use cases allow only host to be passed if there is no port | ||
result = append(result, h) | ||
} |
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.
What do you think about adding a default else
case here letting the user know their config won't run? In general, it's good to avoid silent failures since they're hard to debug.
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 reason why this is not defaulted to just else
is because we dont want to create a host
config unless we can make use of it meaningfully. in such scenarios we wont spin up a monitor
because it fits neither host nor host-port patterns.
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.
I think there was a bit of a misunderstanding here. I was saying that we should probably log an error in the else
case.
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/libbeat/logp" |
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.
imports need some cleanup, they should be grouped
result: common.MapStr{}, | ||
}, | ||
{ | ||
message: "Hints without host should return nothing", |
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.
Going back to earlier comments, if there are some heartbeat hints required, but not others, we should log an error. It'd be great to check for that log message in our tests. It might be a bit challenging with our current code structure. One thought is that the builder could return warnings (maybe just as a []string
) in addition to errors. That'd be easy to test.
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.
i have added debug messages to the hint generation code like how the other hints based builders do for filebeat and metricbeat. we can discuss this further when @exekias is back and do it uniformly across all 3 if it is ok
jenkins, retest this please |
712594f
to
af58a1d
Compare
the build should pass now. incorporated most review comments and commented on the rest. please take a look @andrewvc |
af58a1d
to
9ef142b
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.
Great work, this is really close to being merged. I left some comments about the log levels. It's really important we get this right, so that when users make mistakes they can see the issues in their logs and troubleshoot them.
Thanks once again!
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package hints |
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.
Ah, I see. Looking at metric beat it named its file metrics
. Given that I think the right name here is monitors.go
. It seems the convention is to name the file the same as the noun of the thing it is generating, which in heartbeat's case is a monitor.
for _, monitor := range monitors { | ||
// Every monitor must have a type associated with it | ||
if _, ok := monitor[montype]; !ok { | ||
continue |
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.
Why debug? I was thinking we'd log at warn
or info
at the very least. Would that be too verbose for that use case that precipitated this PR?
} else if port == 0 && !strings.Contains(h, ":") { | ||
// For ICMP like use cases allow only host to be passed if there is no port | ||
result = append(result, h) | ||
} |
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.
I think there was a bit of a misunderstanding here. I was saying that we should probably log an error in the else
case.
9ef142b
to
a143932
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.
This is almost ready to merge, but looking at it one last time I'm realizing my prior comments didn't make sense. We should show config errors at a higher level, we're showing them too early here. https://github.com/elastic/beats/pull/13675/files should show an easy to debug message with sensitive variables censored.
Once those two checks are merged, and tests are passing, I can merge.
|
||
h, ok := hb.getHostsWithPort(monitor, port) | ||
if !ok { | ||
hb.logger.Warn("hosts to monitor is mandatory") |
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.
Let's delete this whole check too.
for _, monitor := range monitors { | ||
// Every monitor must have a type associated with it | ||
if _, ok := monitor[montype]; !ok { | ||
hb.logger.Warn("type of monitor is mandatory") |
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.
I don't think we actually need this check here, this should be caught at a higher level where we can also add more context. https://github.com/elastic/beats/pull/13675/files should improve things.
b0f3c42
to
b77d748
Compare
b77d748
to
7971846
Compare
jenkins, test this please |
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.
LGTM WFG
Build failures unrelated |
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs. Resolves elastic#14245
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs. Resolves elastic#14245 (cherry picked from commit 4eb1711)
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs. Resolves elastic#14245 (cherry picked from commit 4eb1711)
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs. Resolves elastic#14245
This PR allows hints builder to pick up heartbeat configs from hints like kubernetes annotations and docker labels.
The syntax would be as follows:
Heartbeat seems to be a unique use case as a user might want more than one check on his/her pod/container. So i have added the following: