Tag original URL for k8s services in prometheus input (#3257)
This commit is contained in:
parent
53522f8eb2
commit
b63f2a1acf
|
@ -93,14 +93,15 @@ func (p *Prometheus) AddressToURL(u *url.URL, address string) string {
|
|||
}
|
||||
|
||||
type UrlAndAddress struct {
|
||||
Url string
|
||||
Address string
|
||||
OriginalUrl string
|
||||
Url string
|
||||
Address string
|
||||
}
|
||||
|
||||
func (p *Prometheus) GetAllURLs() ([]UrlAndAddress, error) {
|
||||
allUrls := make([]UrlAndAddress, 0)
|
||||
for _, url := range p.Urls {
|
||||
allUrls = append(allUrls, UrlAndAddress{Url: url})
|
||||
allUrls = append(allUrls, UrlAndAddress{Url: url, OriginalUrl: url})
|
||||
}
|
||||
for _, service := range p.KubernetesServices {
|
||||
u, err := url.Parse(service)
|
||||
|
@ -114,7 +115,7 @@ func (p *Prometheus) GetAllURLs() ([]UrlAndAddress, error) {
|
|||
}
|
||||
for _, resolved := range resolvedAddresses {
|
||||
serviceUrl := p.AddressToURL(u, resolved)
|
||||
allUrls = append(allUrls, UrlAndAddress{Url: serviceUrl, Address: resolved})
|
||||
allUrls = append(allUrls, UrlAndAddress{Url: serviceUrl, Address: resolved, OriginalUrl: service})
|
||||
}
|
||||
}
|
||||
return allUrls, nil
|
||||
|
@ -213,7 +214,7 @@ func (p *Prometheus) gatherURL(url UrlAndAddress, acc telegraf.Accumulator) erro
|
|||
// Add (or not) collected metrics
|
||||
for _, metric := range metrics {
|
||||
tags := metric.Tags()
|
||||
tags["url"] = url.Url
|
||||
tags["url"] = url.OriginalUrl
|
||||
if url.Address != "" {
|
||||
tags["address"] = url.Address
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ func TestPrometheusGeneratesMetrics(t *testing.T) {
|
|||
assert.True(t, acc.HasFloatField("test_metric", "value"))
|
||||
assert.True(t, acc.HasTimestamp("test_metric", time.Unix(1490802350, 0)))
|
||||
assert.False(t, acc.HasTag("test_metric", "address"))
|
||||
assert.True(t, acc.TagValue("test_metric", "url") == ts.URL)
|
||||
}
|
||||
|
||||
func TestPrometheusGeneratesMetricsWithHostNameTag(t *testing.T) {
|
||||
|
@ -74,6 +75,7 @@ func TestPrometheusGeneratesMetricsWithHostNameTag(t *testing.T) {
|
|||
assert.True(t, acc.HasFloatField("test_metric", "value"))
|
||||
assert.True(t, acc.HasTimestamp("test_metric", time.Unix(1490802350, 0)))
|
||||
assert.True(t, acc.TagValue("test_metric", "address") == tsAddress)
|
||||
assert.True(t, acc.TagValue("test_metric", "url") == ts.URL)
|
||||
}
|
||||
|
||||
func TestPrometheusGeneratesMetricsAlthoughFirstDNSFails(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue