Yea, that's some inconsistency we should fix. I agree, we should allow square brackets everywhere, but only require them if a port is required.
Consistently using https://pkg.go.dev/net#SplitHostPort should help. On Thu, Dec 14, 2023 at 7:01 PM 'Brian Candler' via Prometheus Users < prometheus-users@googlegroups.com> wrote: > I'd like to raise this as a general issue for discussion. I am working > with these: > > blackbox_exporter, version 0.24.0 (branch: HEAD, revision: > 0b0467473916fd9e8526e2635c2a0b1c56011dff) > build user: root@e5bbfcc8184e > build date: 20230516-11:07:25 > go version: go1.20.4 > platform: linux/amd64 > tags: netgo > > snmp_exporter, version 0.25.0 (branch: HEAD, revision: > 9c42d6c874d479314e612bca69558c81f8e26287) > build user: root@880115266f70 > build date: 20231210-10:05:18 > go version: go1.21.5 > platform: linux/amd64 > tags: netgo > > In blackbox_exporter, it's inconsistent whether IPv6 literals need to be > enclosed in square brackets or not. > > - With the icmp prober, IPv6 literals *must not* be enclosed in brackets > AFAICS > - With the dns prober, IPv6 literals *must not* be enclosed in brackets, > unless you also provide a port. e.g. [::1] is invalid, but [::1]:53 is OK, > as far as I can tell > - With the tcp prober, I don't think the port can be omitted anyway; hence > IPv6 literals *must* be enclosed in brackets and followed by :port > > This makes it difficult to write generic code to map a device to a target > plus module, because it depends on what underlying prober the module is > using. > > Looking at the wider Prometheus ecosystem: > > - Prometheus service discovery requires square brackets, because > __address__ is an address:port combination > - snmp_exporter does *not* allow the square brackets in the target address > if it doesn't have a port. Conversely, you can add the square brackets, but > if you do you *must* add a port; it doesn't add :161 automatically. (This > is like the dns prober in blackbox_exporter) > > # curl -vsS > 'localhost:9116/snmp?target=[2001:db8::1]&module=mikrotik&auth=workshop_v3' > error collecting metric Desc{fqName: "snmp_error", help: "Error scraping > target", constLabels: {module="mikrotik"}, variableLabels: {}}: error > connecting to target [2001:db8::1]: error establishing connection to host: > dial udp: address [[2001:db8::1]]:161: missing port in address > > That looks like a straightforward bug to me: it seems to be attempting to > add the :161 port, but is mangling it with an extra set of brackets. > > If that can be fixed (and maybe it's the same issue in dns prober), then > it will be possible to use brackets around IPv6 addresses without ports. > > That leaves the icmp prober in blackbox exporter. I think it should allow > square brackets, if not actually require them (there's no useful concept of > "port" here, it will always send an echo-request). It might be more > consistent to require square brackets > > P.S. I would expect the blackbox_exporter http prober to require square > brackets around IPv6 literals in URLs, but I can't them to work: e.g. > curl -g > 'localhost:9115/probe?target=http:%2f%2f%5b2001:db8::1%5d&module=http_2xx_example' > doesn't make an outbound connection to 2001:db8::1. But quite possibly I'm > doing something wrong. > > -- > You received this message because you are subscribed to the Google Groups > "Prometheus Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to prometheus-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/prometheus-users/433eea9b-2b74-4375-9112-ca671baf84c9n%40googlegroups.com > <https://groups.google.com/d/msgid/prometheus-users/433eea9b-2b74-4375-9112-ca671baf84c9n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CABbyFmryF8oW%3DQAsdqJoNXbF18X%2Bz58c3MZVFp7RYf7%2BP2Mz_A%40mail.gmail.com.