DNS SD: add srv record target and port meta labels (#7678)
* DNS SD: add srv record target and port meta labels Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
348ff4285f
commit
88bdb13c55
|
@ -35,7 +35,10 @@ import (
|
|||
const (
|
||||
resolvConf = "/etc/resolv.conf"
|
||||
|
||||
dnsNameLabel = model.MetaLabelPrefix + "dns_name"
|
||||
dnsNameLabel = model.MetaLabelPrefix + "dns_name"
|
||||
dnsSrvRecordPrefix = model.MetaLabelPrefix + "dns_srv_record_"
|
||||
dnsSrvRecordTargetLabel = dnsSrvRecordPrefix + "target"
|
||||
dnsSrvRecordPortLabel = dnsSrvRecordPrefix + "port"
|
||||
|
||||
// Constants for instrumentation.
|
||||
namespace = "prometheus"
|
||||
|
@ -183,9 +186,13 @@ func (d *Discovery) refreshOne(ctx context.Context, name string, ch chan<- *targ
|
|||
}
|
||||
|
||||
for _, record := range response.Answer {
|
||||
var target model.LabelValue
|
||||
var target, dnsSrvRecordTarget, dnsSrvRecordPort model.LabelValue
|
||||
|
||||
switch addr := record.(type) {
|
||||
case *dns.SRV:
|
||||
dnsSrvRecordTarget = model.LabelValue(addr.Target)
|
||||
dnsSrvRecordPort = model.LabelValue(fmt.Sprintf("%d", addr.Port))
|
||||
|
||||
// Remove the final dot from rooted DNS names to make them look more usual.
|
||||
addr.Target = strings.TrimRight(addr.Target, ".")
|
||||
|
||||
|
@ -199,8 +206,10 @@ func (d *Discovery) refreshOne(ctx context.Context, name string, ch chan<- *targ
|
|||
continue
|
||||
}
|
||||
tg.Targets = append(tg.Targets, model.LabelSet{
|
||||
model.AddressLabel: target,
|
||||
dnsNameLabel: model.LabelValue(name),
|
||||
model.AddressLabel: target,
|
||||
dnsNameLabel: model.LabelValue(name),
|
||||
dnsSrvRecordTargetLabel: dnsSrvRecordTarget,
|
||||
dnsSrvRecordPortLabel: dnsSrvRecordPort,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,12 @@ func TestDNS(t *testing.T) {
|
|||
{
|
||||
Source: "web.example.com.",
|
||||
Targets: []model.LabelSet{
|
||||
{"__address__": "192.0.2.2:80", "__meta_dns_name": "web.example.com."},
|
||||
{
|
||||
"__address__": "192.0.2.2:80",
|
||||
"__meta_dns_name": "web.example.com.",
|
||||
"__meta_dns_srv_record_target": "",
|
||||
"__meta_dns_srv_record_port": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -100,7 +105,12 @@ func TestDNS(t *testing.T) {
|
|||
{
|
||||
Source: "web.example.com.",
|
||||
Targets: []model.LabelSet{
|
||||
{"__address__": "[::1]:80", "__meta_dns_name": "web.example.com."},
|
||||
{
|
||||
"__address__": "[::1]:80",
|
||||
"__meta_dns_name": "web.example.com.",
|
||||
"__meta_dns_srv_record_target": "",
|
||||
"__meta_dns_srv_record_port": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -125,8 +135,18 @@ func TestDNS(t *testing.T) {
|
|||
{
|
||||
Source: "_mysql._tcp.db.example.com.",
|
||||
Targets: []model.LabelSet{
|
||||
{"__address__": "db1.example.com:3306", "__meta_dns_name": "_mysql._tcp.db.example.com."},
|
||||
{"__address__": "db2.example.com:3306", "__meta_dns_name": "_mysql._tcp.db.example.com."},
|
||||
{
|
||||
"__address__": "db1.example.com:3306",
|
||||
"__meta_dns_name": "_mysql._tcp.db.example.com.",
|
||||
"__meta_dns_srv_record_target": "db1.example.com.",
|
||||
"__meta_dns_srv_record_port": "3306",
|
||||
},
|
||||
{
|
||||
"__address__": "db2.example.com:3306",
|
||||
"__meta_dns_name": "_mysql._tcp.db.example.com.",
|
||||
"__meta_dns_srv_record_target": "db2.example.com.",
|
||||
"__meta_dns_srv_record_port": "3306",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -150,7 +170,12 @@ func TestDNS(t *testing.T) {
|
|||
{
|
||||
Source: "_mysql._tcp.db.example.com.",
|
||||
Targets: []model.LabelSet{
|
||||
{"__address__": "db1.example.com:3306", "__meta_dns_name": "_mysql._tcp.db.example.com."},
|
||||
{
|
||||
"__address__": "db1.example.com:3306",
|
||||
"__meta_dns_name": "_mysql._tcp.db.example.com.",
|
||||
"__meta_dns_srv_record_target": "db1.example.com.",
|
||||
"__meta_dns_srv_record_port": "3306",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -589,9 +589,11 @@ This service discovery method only supports basic DNS A, AAAA and SRV record
|
|||
queries, but not the advanced DNS-SD approach specified in
|
||||
[RFC6763](https://tools.ietf.org/html/rfc6763).
|
||||
|
||||
During the [relabeling phase](#relabel_config), the meta label
|
||||
`__meta_dns_name` is available on each target and is set to the
|
||||
record name that produced the discovered target.
|
||||
The following meta labels are available on targets during [relabeling](#relabel_config):
|
||||
|
||||
* `__meta_dns_name`: the record name that produced the discovered target.
|
||||
* `__meta_dns_srv_record_target`: the target field of the SRV record
|
||||
* `__meta_dns_srv_record_port`: the port field of the SRV record
|
||||
|
||||
```yaml
|
||||
# A list of DNS domain names to be queried.
|
||||
|
|
Loading…
Reference in New Issue