Skip to content
Draft
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
24 changes: 21 additions & 3 deletions pkg/query/endpointset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/model/labels"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -217,9 +218,10 @@ type EndpointSet struct {

updateMtx sync.Mutex

endpointsMtx sync.RWMutex
endpoints map[string]*endpointRef
endpointsMetric *endpointSetNodeCollector
endpointsMtx sync.RWMutex
endpoints map[string]*endpointRef
endpointsMetric *endpointSetNodeCollector
endpointsStatusCount *prometheus.GaugeVec

// Track if the first update has completed
firstUpdateOnce sync.Once
Expand Down Expand Up @@ -270,6 +272,13 @@ func NewEndpointSet(
},
endpoints: make(map[string]*endpointRef),
firstUpdateChan: make(chan struct{}),
endpointsStatusCount: promauto.With(reg).NewGaugeVec(
prometheus.GaugeOpts{
Name: "thanos_query_endpoints",
Help: "Number of endpoints connected to the querier categorized by healthy/unhealthy. Strict endpoints are never considered as unhealthy.",
},
[]string{"status"},
),
}
}

Expand Down Expand Up @@ -394,6 +403,15 @@ func (e *EndpointSet) Update(ctx context.Context) {

e.endpointsMetric.Update(stats)

activeCount := len(e.endpoints)
specsCount := len(e.endpointSpecs())
inactiveCount := specsCount - activeCount
if inactiveCount < 0 {
inactiveCount = 0
}
e.endpointsStatusCount.WithLabelValues("healthy").Set(float64(activeCount))
e.endpointsStatusCount.WithLabelValues("unhealthy").Set(float64(inactiveCount))

// Signal that the first update has completed
e.firstUpdateOnce.Do(func() {
close(e.firstUpdateChan)
Expand Down
Loading