Skip to content

Commit

Permalink
Added support for differing metrics path for Prometheus to Mentix (#875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT authored Jun 24, 2020
1 parent db5e663 commit 26bb0e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/mentix/config/ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ const (
ExporterIDWebAPI = "webapi"
ExporterIDPrometheusFileSD = "prom_filesd"
)

const (
PropertyMetricsPath = "metrics_path"
)
15 changes: 11 additions & 4 deletions pkg/mentix/exporters/promfilesd.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,19 @@ func (exporter *PrometheusFileSDExporter) createScrapeConfigs() []*prometheus.Sc
}

func (exporter *PrometheusFileSDExporter) createScrapeConfig(site *meshdata.Site, host string, endpoint *meshdata.ServiceEndpoint) *prometheus.ScrapeConfig {
labels := map[string]string{
"site": site.Name,
"service_type": endpoint.Type.Name,
}

// If a metrics path was specified as a property, use that one by setting the corresponding label
if metricsPath := endpoint.GetPropertyValue(config.PropertyMetricsPath, ""); len(metricsPath) > 0 {
labels["__metrics_path__"] = metricsPath
}

return &prometheus.ScrapeConfig{
Targets: []string{host},
Labels: map[string]string{
"site": site.Name,
"service_type": endpoint.Type.Name,
},
Labels: labels,
}
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/mentix/meshdata/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package meshdata

import "strings"

// Service represents a service managed by Mentix.
type Service struct {
ServiceEndpoint
Expand All @@ -40,3 +42,14 @@ type ServiceEndpoint struct {
IsMonitored bool
Properties map[string]string
}

// GetPropertyValue performs a case-insensitive search for the given property.
func (endpoint *ServiceEndpoint) GetPropertyValue(id string, defValue string) string {
for key := range endpoint.Properties {
if strings.EqualFold(key, id) {
return endpoint.Properties[key]
}
}

return defValue
}

0 comments on commit 26bb0e9

Please sign in to comment.