Skip to content

Commit

Permalink
Add a site property to explicitly enable health checks (cs3org#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-WWU-IT authored Dec 2, 2020
1 parent 0ff299d commit 0caf15a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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

0 comments on commit 0caf15a

Please sign in to comment.