Skip to content

Commit

Permalink
Remove unused metrics exported by ring lifecycler and client (#162)
Browse files Browse the repository at this point in the history
* Remove unused metrics exported by ring lifecycler and client

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Removed unused fields

Signed-off-by: Marco Pracucci <marco@pracucci.com>
  • Loading branch information
pracucci authored Apr 29, 2022
1 parent ec983e9 commit 25baa36
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 75 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
* [CHANGE] Minor cosmetic changes in ring and memberlist HTTP status templates. #149
* [CHANGE] flagext.Secret: `value` field is no longer exported. Value can be read using `String()` method and set using `Set` method. #154
* [CHANGE] spanlogger.SpanLogger: Log the user ID from the context with the `user` label instead of `org_id`. #156
* [CHANGE] ring: removed the following metrics from ring client and lifecycler: #161
* `member_ring_tokens_owned`
* `member_ring_tokens_to_own`
* `ring_tokens_owned`
* `ring_member_ownership_percent`
* [ENHANCEMENT] Add middleware package. #38
* [ENHANCEMENT] Add the ring package #45
* [ENHANCEMENT] Add limiter package. #41
Expand Down
2 changes: 1 addition & 1 deletion ring/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *ringPageHandler) handle(w http.ResponseWriter, req *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
_, ownedTokens := ringDesc.countTokens()
ownedTokens := ringDesc.countTokens()

var ingesterIDs []string
for id := range ringDesc.Ingesters {
Expand Down
4 changes: 0 additions & 4 deletions ring/lifecycler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ func NewLifecycler(cfg LifecyclerConfig, flushTransferer FlushTransferer, ringNa
logger: logger,
}

l.lifecyclerMetrics.tokensToOwn.Set(float64(cfg.NumTokens))

l.BasicService = services.
NewBasicService(nil, l.loop, l.stopping).
WithName(fmt.Sprintf("%s ring lifecycler", ringName))
Expand Down Expand Up @@ -304,8 +302,6 @@ func (i *Lifecycler) getTokens() Tokens {
}

func (i *Lifecycler) setTokens(tokens Tokens) {
i.lifecyclerMetrics.tokensOwned.Set(float64(len(tokens)))

i.stateMtx.Lock()
defer i.stateMtx.Unlock()

Expand Down
12 changes: 0 additions & 12 deletions ring/lifecycler_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

type LifecyclerMetrics struct {
consulHeartbeats prometheus.Counter
tokensOwned prometheus.Gauge
tokensToOwn prometheus.Gauge
shutdownDuration *prometheus.HistogramVec
}

Expand All @@ -19,16 +17,6 @@ func NewLifecyclerMetrics(ringName string, reg prometheus.Registerer) *Lifecycle
Help: "The total number of heartbeats sent to consul.",
ConstLabels: prometheus.Labels{"name": ringName},
}),
tokensOwned: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Name: "member_ring_tokens_owned",
Help: "The number of tokens owned in the ring.",
ConstLabels: prometheus.Labels{"name": ringName},
}),
tokensToOwn: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Name: "member_ring_tokens_to_own",
Help: "The number of tokens to own in the ring.",
ConstLabels: prometheus.Labels{"name": ringName},
}),
shutdownDuration: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
Name: "shutdown_duration_seconds",
Help: "Duration (in seconds) of shutdown procedure (ie transfer or flush).",
Expand Down
40 changes: 4 additions & 36 deletions ring/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,9 @@ type Ring struct {
// If set to nil, no caching is done (used by tests, and subrings).
shuffledSubringCache map[subringCacheKey]*Ring

memberOwnershipGaugeVec *prometheus.GaugeVec
numMembersGaugeVec *prometheus.GaugeVec
totalTokensGauge prometheus.Gauge
numTokensGaugeVec *prometheus.GaugeVec
oldestTimestampGaugeVec *prometheus.GaugeVec
reportedOwners map[string]struct{}

logger log.Logger
}
Expand Down Expand Up @@ -227,11 +224,6 @@ func NewWithStoreClientAndStrategy(cfg Config, name, key string, store kv.Client
strategy: strategy,
ringDesc: &Desc{},
shuffledSubringCache: map[subringCacheKey]*Ring{},
memberOwnershipGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "ring_member_ownership_percent",
Help: "The percent ownership of the ring by member",
ConstLabels: map[string]string{"name": name}},
[]string{"member"}),
numMembersGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "ring_members",
Help: "Number of members in the ring",
Expand All @@ -241,11 +233,6 @@ func NewWithStoreClientAndStrategy(cfg Config, name, key string, store kv.Client
Name: "ring_tokens_total",
Help: "Number of tokens in the ring",
ConstLabels: map[string]string{"name": name}}),
numTokensGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "ring_tokens_owned",
Help: "The number of tokens in the ring owned by the member",
ConstLabels: map[string]string{"name": name}},
[]string{"member"}),
oldestTimestampGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "ring_oldest_member_timestamp",
Help: "Timestamp of the oldest member in the ring.",
Expand Down Expand Up @@ -514,12 +501,10 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro
}, nil
}

// countTokens returns the number of tokens and tokens within the range for each instance.
func (r *Desc) countTokens() (map[string]uint32, map[string]uint32) {
// countTokens returns the number tokens within the range for each instance.
func (r *Desc) countTokens() map[string]uint32 {
var (
owned = map[string]uint32{}
numTokens = map[string]uint32{}

owned = map[string]uint32{}
ringTokens = r.GetTokens()
ringInstanceByToken = r.getTokensInfo()
)
Expand All @@ -535,19 +520,17 @@ func (r *Desc) countTokens() (map[string]uint32, map[string]uint32) {
}

info := ringInstanceByToken[token]
numTokens[info.InstanceID] = numTokens[info.InstanceID] + 1
owned[info.InstanceID] = owned[info.InstanceID] + diff
}

// Set to 0 the number of owned tokens by instances which don't have tokens yet.
for id := range r.Ingesters {
if _, ok := owned[id]; !ok {
owned[id] = 0
numTokens[id] = 0
}
}

return numTokens, owned
return owned
}

// updateRingMetrics updates ring metrics. Caller must be holding the Write lock!
Expand Down Expand Up @@ -587,21 +570,6 @@ func (r *Ring) updateRingMetrics(compareResult CompareResult) {
return
}

prevOwners := r.reportedOwners
r.reportedOwners = make(map[string]struct{})
numTokens, ownedRange := r.ringDesc.countTokens()
for id, totalOwned := range ownedRange {
r.memberOwnershipGaugeVec.WithLabelValues(id).Set(float64(totalOwned) / float64(math.MaxUint32))
r.numTokensGaugeVec.WithLabelValues(id).Set(float64(numTokens[id]))
delete(prevOwners, id)
r.reportedOwners[id] = struct{}{}
}

for k := range prevOwners {
r.memberOwnershipGaugeVec.DeleteLabelValues(k)
r.numTokensGaugeVec.DeleteLabelValues(k)
}

r.totalTokensGauge.Set(float64(len(r.ringTokens)))
}

Expand Down
22 changes: 0 additions & 22 deletions ring/ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2247,10 +2247,6 @@ func TestUpdateMetrics(t *testing.T) {
ring.updateRingState(&ringDesc)

err = testutil.GatherAndCompare(registry, bytes.NewBufferString(`
# HELP ring_member_ownership_percent The percent ownership of the ring by member
# TYPE ring_member_ownership_percent gauge
ring_member_ownership_percent{member="A",name="test"} 0.500000000349246
ring_member_ownership_percent{member="B",name="test"} 0.49999999965075403
# HELP ring_members Number of members in the ring
# TYPE ring_members gauge
ring_members{name="test",state="ACTIVE"} 2
Expand All @@ -2265,10 +2261,6 @@ func TestUpdateMetrics(t *testing.T) {
ring_oldest_member_timestamp{name="test",state="LEAVING"} 0
ring_oldest_member_timestamp{name="test",state="PENDING"} 0
ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0
# HELP ring_tokens_owned The number of tokens in the ring owned by the member
# TYPE ring_tokens_owned gauge
ring_tokens_owned{member="A",name="test"} 2
ring_tokens_owned{member="B",name="test"} 2
# HELP ring_tokens_total Number of tokens in the ring
# TYPE ring_tokens_total gauge
ring_tokens_total{name="test"} 4
Expand Down Expand Up @@ -2299,10 +2291,6 @@ func TestUpdateMetricsWithRemoval(t *testing.T) {
ring.updateRingState(&ringDesc)

err = testutil.GatherAndCompare(registry, bytes.NewBufferString(`
# HELP ring_member_ownership_percent The percent ownership of the ring by member
# TYPE ring_member_ownership_percent gauge
ring_member_ownership_percent{member="A",name="test"} 0.500000000349246
ring_member_ownership_percent{member="B",name="test"} 0.49999999965075403
# HELP ring_members Number of members in the ring
# TYPE ring_members gauge
ring_members{name="test",state="ACTIVE"} 2
Expand All @@ -2317,10 +2305,6 @@ func TestUpdateMetricsWithRemoval(t *testing.T) {
ring_oldest_member_timestamp{name="test",state="LEAVING"} 0
ring_oldest_member_timestamp{name="test",state="PENDING"} 0
ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0
# HELP ring_tokens_owned The number of tokens in the ring owned by the member
# TYPE ring_tokens_owned gauge
ring_tokens_owned{member="A",name="test"} 2
ring_tokens_owned{member="B",name="test"} 2
# HELP ring_tokens_total Number of tokens in the ring
# TYPE ring_tokens_total gauge
ring_tokens_total{name="test"} 4
Expand All @@ -2335,9 +2319,6 @@ func TestUpdateMetricsWithRemoval(t *testing.T) {
ring.updateRingState(&ringDescNew)

err = testutil.GatherAndCompare(registry, bytes.NewBufferString(`
# HELP ring_member_ownership_percent The percent ownership of the ring by member
# TYPE ring_member_ownership_percent gauge
ring_member_ownership_percent{member="A",name="test"} 1
# HELP ring_members Number of members in the ring
# TYPE ring_members gauge
ring_members{name="test",state="ACTIVE"} 1
Expand All @@ -2352,9 +2333,6 @@ func TestUpdateMetricsWithRemoval(t *testing.T) {
ring_oldest_member_timestamp{name="test",state="LEAVING"} 0
ring_oldest_member_timestamp{name="test",state="PENDING"} 0
ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0
# HELP ring_tokens_owned The number of tokens in the ring owned by the member
# TYPE ring_tokens_owned gauge
ring_tokens_owned{member="A",name="test"} 2
# HELP ring_tokens_total Number of tokens in the ring
# TYPE ring_tokens_total gauge
ring_tokens_total{name="test"} 2
Expand Down

0 comments on commit 25baa36

Please sign in to comment.