-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[receiver/prometheusreceiver] Do not add host.name
to metrics from localhost/unspecified targets
#6476
[receiver/prometheusreceiver] Do not add host.name
to metrics from localhost/unspecified targets
#6476
Conversation
What's up with the instance value? Shouldn't it be
|
I don't have a strong opinion about this. I see a couple arguments in favor of keeping it as |
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 approving, as I also don't see a problem with instance having 0.0.0.0. If you decide to leave it as it is, let me know and I'll merge this.
I would leave it as it is, but maybe let's wait a bit in case @Aneurysm9 or @dashpole have a different opinion, since they are CODEOWNERS? |
func createNodeAndResourcePdata(job, instance, scheme string) pdata.Resource { | ||
host, port, err := net.SplitHostPort(instance) | ||
if err != nil { | ||
host = instance | ||
} | ||
host = sanitizeHost(host) |
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.
Wouldn't it be better to remove the host name Attribute when its value is 0.0.0.0
, localhost
, 127.0.0.1
or ::1
(or any variation of this) and let the resourcedetection processor do the job or setting this attribute properly (with the actual host name of the system).
Because eventually, the metric is going to be stored somewhere else, where localhost will be either meaningless or misleading.
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 certainly would prefer that (e.g. the way we as a vendor use host.name
makes it so localhost
and similar attributes are practically useless), but I was assuming these attributes were necessary for something Prometheus-related.
Maybe @dashpole can comment on this?
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.
If you are using the resource detection processor, it overrides the existing values by default anyways. I double-checked, and host.name isn't used for anything prometheus-related
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.
If you are using the resource detection processor, it overrides the existing values by default anyways.
There are valid use cases where you don't want the resourcedetectionprocessor
to override the hostname (e.g. chaining multiple Collectors), or maybe you can't/don't want to use it at all (e.g. your Collector distro doesn't support it or you don't want the performance hit).
I double-checked, and host.name isn't used for anything prometheus-related
Personally I would prefer removing it then, if everyone is on board with this. I agree with @bertysentry that having a localhost-like value for host.name
is, while spec-compliant, not very useful in practice.
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.
Removing it only when its a localhost equivalent? Or removing it entirely?
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.
resourcedetectionprocessor has an override
option that can be set to false
to prevent it from overwriting attributes that are already set.
Removing the host.name
attributes in prometheusreceiver when its value is localhost
(or any variation of localhost, incl. 0.0.0.0
) will then work very well in combination with resourcedetectionprocessor (and override: false
).
Typical example: the internal otelcol Prometheus exporter, whose metrics are currently attached to 0.0.0.0
, which are not usable once these metrics from several collectors are aggregated into a Prometheus server.
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.
Removing it only when its a localhost equivalent?
Only when localhost or equivalent, yes
Edit: Looking more closely, we preserve instance anyways, so the above doesn't apply here. |
From what I understood, there's an agreement then in removing the label when the value is localhost (127.*, 0.0.0.0), right? |
…ified `host.name`s
host.name
to 127.0.0.1 for 0.0.0.0 targetshost.name
attribute to localhost/unspecified metrics
Updated PR diff, name and description after discussion above. PTAL! |
host.name
attribute to localhost/unspecified metricshost.name
to metrics from localhost/unspecified targets
Unit test was expecting `host.name` attribute and panicking after not finding it.
- Fix typo - Avoid double negative
Description:
Do not add
host.name
for Prometheus receiver metrics that come from scraping a localhost or unspecified (0.0.0.0
) target.Link to tracking Issue: Fixes #6465.
Testing: Amended unit test. Ran example on linked issue to manually check this fixed the problem:
logging exporter when running example on linked issue