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

Add a site property to explicitly enable health checks #1347

Merged
merged 4 commits into from
Dec 2, 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
5 changes: 5 additions & 0 deletions changelog/unreleased/mentix-checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Support property to enable health checking on a service

This update introduces a new service property called `ENABLE_HEALTH_CHECKS` that must be explicitly set to `true` if a service should be checked for its health status. This allows us to only enable these checks for partner sites only, skipping vendor sites.

https://github.com/cs3org/reva/pull/1347
27 changes: 23 additions & 4 deletions pkg/mentix/exchangers/exporters/promsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/rs/zerolog"

Expand All @@ -46,7 +47,7 @@ type PrometheusSDExporter struct {
}

func createMetricsSDScrapeConfig(site *meshdata.Site, host string, endpoint *meshdata.ServiceEndpoint) *prometheus.ScrapeConfig {
labels := getScrapeTargetLabels(site, endpoint)
labels := getScrapeTargetLabels(site, host, endpoint)

// If a metrics path was specified as a property, use that one by setting the corresponding label
if metricsPath := meshdata.GetPropertyValue(endpoint.Properties, meshdata.PropertyMetricsPath, ""); len(metricsPath) > 0 {
Expand All @@ -66,22 +67,40 @@ func createBlackboxSDScrapeConfig(site *meshdata.Site, host string, endpoint *me
return nil
}

labels := getScrapeTargetLabels(site, endpoint)
// Check if health checks are enabled for the endpoint; if they aren't, skip this endpoint
if enableHealthChecks := meshdata.GetPropertyValue(endpoint.Properties, meshdata.PropertyEnableHealthChecks, "false"); !strings.EqualFold(enableHealthChecks, "true") {
return nil
}

labels := getScrapeTargetLabels(site, host, endpoint)

// For health checks, the gRPC port must be set
if _, ok := labels["__meta_mentix_grpc_port"]; !ok {
return nil
}

return &prometheus.ScrapeConfig{
Targets: []string{target},
Labels: labels,
}
}

func getScrapeTargetLabels(site *meshdata.Site, endpoint *meshdata.ServiceEndpoint) map[string]string {
return map[string]string{
func getScrapeTargetLabels(site *meshdata.Site, host string, endpoint *meshdata.ServiceEndpoint) map[string]string {
labels := map[string]string{
"__meta_mentix_site": site.Name,
"__meta_mentix_site_type": meshdata.GetSiteTypeName(site.Type),
"__meta_mentix_site_id": site.GetID(),
"__meta_mentix_host": host,
"__meta_mentix_country": site.CountryCode,
"__meta_mentix_service_type": endpoint.Type.Name,
}

// Get the gRPC port if the corresponding property has been set
if port := meshdata.GetPropertyValue(endpoint.Properties, meshdata.PropertyGRPCPort, ""); len(port) > 0 {
labels["__meta_mentix_grpc_port"] = port
}

return labels
}

func (exporter *PrometheusSDExporter) registerScrapeCreators(conf *config.Configuration) error {
Expand Down
4 changes: 4 additions & 0 deletions pkg/mentix/meshdata/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const (
PropertyOrganization = "organization"
// PropertyMetricsPath identifies the metrics path property.
PropertyMetricsPath = "metrics_path"
// PropertyGRPCPort identifies the gRPC port property.
PropertyGRPCPort = "grpc_port"
// PropertyEnableHealthChecks identifies the enable health checks property.
PropertyEnableHealthChecks = "enable_health_checks"
// PropertyAPIVersion identifies the API version property.
PropertyAPIVersion = "api_version"
)
Expand Down