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

Add support for heartbeat hints builder #13119

Merged
merged 1 commit into from
Sep 23, 2019

Conversation

vjsamuel
Copy link
Contributor

This PR allows hints builder to pick up heartbeat configs from hints like kubernetes annotations and docker labels.

The syntax would be as follows:

co.elastic.heartbeats/type: icmp
co.elastic.heartbeats/hosts: ${data.host}
co.elastic.heartbeats/schedule: "@every 5s"

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:

co.elastic.heartbeats/1.type: tcp
co.elastic.heartbeats/1.hosts: ${data.host}:9090
co.elastic.heartbeats/1.schedule: "@every 5s"

co.elastic.heartbeats/1.type: tcp
co.elastic.heartbeats/2.hosts: ${data.host}:9091
co.elastic.heartbeats/2.schedule: "@every 5s"

@vjsamuel vjsamuel requested review from a team as code owners July 31, 2019 08:55
@elasticmachine
Copy link
Collaborator

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
@elasticmachine
Copy link
Collaborator

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

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 ..."

@exekias exekias added Team:obs-ds-hosted-services Label for the Observability Hosted Services team containers Related to containers use case enhancement Heartbeat labels Jul 31, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime

@exekias
Copy link
Contributor

exekias commented Jul 31, 2019

This is great @vjsamuel! I will dig more into the code, at first sight I wonder if we should use co.elastic.monitor instead of heartbeats. As we advance in agents unification I think that will be a better suited name. Like we did with Filebeat & Metricbeat (logs & metrics).

cc @andrewvc FYI

@andrewvc
Copy link
Contributor

Apologies for the delay, but this is something I'll look into when back from vacation in a few weeks!

Copy link
Contributor

@andrewvc andrewvc left a 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)
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

heartbeat/autodiscover/builder/hints/heartbeats.go Outdated Show resolved Hide resolved
} 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)
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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"
Copy link
Contributor

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",
Copy link
Contributor

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.

Copy link
Contributor Author

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

@andrewvc
Copy link
Contributor

jenkins, retest this please

@vjsamuel vjsamuel force-pushed the heartbeat_hints branch 7 times, most recently from 712594f to af58a1d Compare September 16, 2019 18:06
@vjsamuel
Copy link
Contributor Author

the build should pass now. incorporated most review comments and commented on the rest. please take a look @andrewvc

Copy link
Contributor

@andrewvc andrewvc left a 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
Copy link
Contributor

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
Copy link
Contributor

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)
}
Copy link
Contributor

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.

Copy link
Contributor

@andrewvc andrewvc left a 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")
Copy link
Contributor

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")
Copy link
Contributor

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.

@vjsamuel vjsamuel force-pushed the heartbeat_hints branch 2 times, most recently from b0f3c42 to b77d748 Compare September 23, 2019 19:16
@andrewvc
Copy link
Contributor

jenkins, test this please

Copy link
Contributor

@andrewvc andrewvc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM WFG

@andrewvc
Copy link
Contributor

Build failures unrelated

@andrewvc andrewvc merged commit 3f249f3 into elastic:master Sep 23, 2019
andrewvc added a commit to andrewvc/beats that referenced this pull request Oct 25, 2019
Autodiscover hints were introduced in elastic#13119 but not documented. This
adds the docs.

Resolves elastic#14245
andrewvc added a commit that referenced this pull request Nov 13, 2019
Autodiscover hints were introduced in #13119 but not documented. This adds the docs.

Resolves #14245
andrewvc added a commit to andrewvc/beats that referenced this pull request Nov 19, 2019
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs.

Resolves elastic#14245

(cherry picked from commit 4eb1711)
andrewvc added a commit to andrewvc/beats that referenced this pull request Nov 19, 2019
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs.

Resolves elastic#14245

(cherry picked from commit 4eb1711)
andrewvc added a commit that referenced this pull request Nov 25, 2019
Autodiscover hints were introduced in #13119 but not documented. This adds the docs.

Resolves #14245
andrewvc added a commit that referenced this pull request Nov 25, 2019
* [Uptime] Add docs for autodiscover hints (#14252)

Autodiscover hints were introduced in #13119 but not documented. This adds the docs.

Resolves #14245

(cherry picked from commit 4eb1711)

* Fix double include
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
Autodiscover hints were introduced in elastic#13119 but not documented. This adds the docs.

Resolves elastic#14245
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Related to containers use case enhancement Heartbeat release-highlight Team:obs-ds-hosted-services Label for the Observability Hosted Services team v7.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants