Skip to content
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

Added support for differing metrics path for Prometheus to Mentix #875

Merged
merged 4 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported const PropertyMetricsPath should have comment (or a comment on this block) or be unexported

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported const PropertyMetricsPath should have comment (or a comment on this block) or be unexported

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported const PropertyMetricsPath should have comment (or a comment on this block) or be unexported

)
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
}