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
[Heartbeat] Fix hint-based monitor gen #34376
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
} | ||
|
||
if p != port { | ||
// Different static port, skip |
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 line would not solve an extra bug that I discovered while investigating this issue.
we could have a use case where a container export a port 80 that is remapped to a nodePort 30000 (or any other port different from 80) like in the following snippet
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
namespace: default
annotations:
co.elastic.monitor/1.hosts: 127.0.0.1:30000
co.elastic.monitor/1.schedule: '@every 5s'
co.elastic.monitor/1.type: tcp
spec:
selector:
app: nginx-svc
type: NodePort
ports:
- protocol: TCP
port: 80
nodePort: 30000
name: main
In that case the hint port (here 30000) needs to match the node port (here 30000) and not the container port (here 80).
If the previous code is not change 80 != 30000
will skip adding this heartbeat in this case.
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 believe that this extra check for the containerPort (aka port
here) and the hints port is just not useful and it might cause issues when that containerPort is mapped to another port
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.
TBH, I'm not too worried about this scenario, considering the limitations autodiscovery actually has
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 am not sure what limitations you are referring to but this is clearly a bug to me.
if mType == "icmp" && strings.Contains(h, ":") { | ||
hb.logger.Warnf("ICMP scheme does not support port specification: %s", h) | ||
continue | ||
} else if strings.Contains(h, ":") && strings.Contains(h, "data.port") && port == 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.
are we removing the check for data.host
altogether?
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.
also I don't think we should check for data.port
in any part of the string. We should check it for :${data.port}
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.
are we removing the check for data.host altogether?
IMO, the complicated thing here is building a general case. Pods are usually addresed via ip, services can be addressed by dns, some monitors might make sense for a single pod, others will be broken for a replica set.
@andrewvc I think we have two paths to solve this, wdyt?:
- allow any value combination in without trying to match host-port, should fix errors like the ones listed here with the downside that it can have unexpected results to be handled by the user, eg: generating a unique monitor config for a replica set will delete the monitor if a pod is removed from the set.
- Fix the empty host error and effectively have an even stricter matching host-port approach.
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.
Can you provide some more detail on the stricter matching approach? What would that look like?
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.
Sure, it would involve making sure that the monitor generated is dynamic in relation to the hint event data. It's basically what we do now by checking ${data.host}
and ${data.port}
but fixing the empty config scenario we have.
The problem with this approach is that it prevents some common use cases, that's why there're so many request to remove the restriction altogether.
Pinging @elastic/uptime (Team:Uptime) |
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 pending changelog
* ignore matching event port with hints port * fixed compilation error * Refactor hint-based monitor gen * Update heartbeat/autodiscover/builder/hints/monitors.go * Remove host-port matching from hint generator * Add changelog --------- Co-authored-by: gsantoro <giuseppe.santoro@elastic.co> Co-authored-by: Andrew Cholakian <andrewvc@elastic.co> (cherry picked from commit 9d9f8dc) # Conflicts: # heartbeat/autodiscover/builder/hints/monitors.go # heartbeat/autodiscover/builder/hints/monitors_test.go
* ignore matching event port with hints port * fixed compilation error * Refactor hint-based monitor gen * Update heartbeat/autodiscover/builder/hints/monitors.go * Remove host-port matching from hint generator * Add changelog --------- Co-authored-by: gsantoro <giuseppe.santoro@elastic.co> Co-authored-by: Andrew Cholakian <andrewvc@elastic.co> (cherry picked from commit 9d9f8dc)
* [Heartbeat] Fix hint-based monitor gen (#34376) * ignore matching event port with hints port * fixed compilation error * Refactor hint-based monitor gen * Update heartbeat/autodiscover/builder/hints/monitors.go * Remove host-port matching from hint generator * Add changelog --------- Co-authored-by: gsantoro <giuseppe.santoro@elastic.co> Co-authored-by: Andrew Cholakian <andrewvc@elastic.co> (cherry picked from commit 9d9f8dc) * removed dependency to `elastic-agent-autodiscover` * linter fixes from PR * new line * Fix linter --------- Co-authored-by: Emilio Alvarez Piñeiro <95703246+emilioalvap@users.noreply.github.com>
* ignore matching event port with hints port * fixed compilation error * Refactor hint-based monitor gen * Update heartbeat/autodiscover/builder/hints/monitors.go * Remove host-port matching from hint generator * Add changelog --------- Co-authored-by: gsantoro <giuseppe.santoro@elastic.co> Co-authored-by: Andrew Cholakian <andrewvc@elastic.co>
What does this PR do?
Make hint generator more flexible by removing host/port matching requirements.
Closes #17771.
Closes #34214.
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
Deploy the following config and check that exactly one monitor is generated with an unmatched host/port: