MCPcopy
hub / github.com/prometheus/prometheus / shouldReshard

Method shouldReshard

storage/remote/queue_manager.go:1130–1150  ·  view source on GitHub ↗

shouldReshard returns whether resharding should occur.

(desiredShards int)

Source from the content-addressed store, hash-verified

1128
1129// shouldReshard returns whether resharding should occur.
1130func (t *QueueManager) shouldReshard(desiredShards int) bool {
1131 if desiredShards == t.numShards {
1132 return false
1133 }
1134 // We shouldn't reshard if Prometheus hasn't been able to send
1135 // since the last time it checked if it should reshard.
1136 minSendTimestamp := time.Now().Add(-1 * shardUpdateDuration).Unix()
1137 lsts := t.lastSendTimestamp.Load()
1138 if lsts < minSendTimestamp {
1139 t.logger.Warn("Skipping resharding, last successful send was beyond threshold", "lastSendTimestamp", lsts, "minSendTimestamp", minSendTimestamp)
1140 return false
1141 }
1142 if disableTimestamp := t.reshardDisableEndTimestamp.Load(); time.Now().Unix() < disableTimestamp {
1143 disabledAt := time.Unix(t.reshardDisableStartTimestamp.Load(), 0)
1144 disabledFor := time.Until(time.Unix(disableTimestamp, 0))
1145
1146 t.logger.Warn("Skipping resharding, resharding is disabled while waiting for recoverable errors", "disabled_at", disabledAt, "disabled_for", disabledFor)
1147 return false
1148 }
1149 return true
1150}
1151
1152// calculateDesiredShards returns the number of desired shards, which will be
1153// the current QueueManager.numShards if resharding should not occur for reasons

Callers 3

updateShardsLoopMethod · 0.95
TestShouldReshardFunction · 0.80

Calls 2

AddMethod · 0.65
LoadMethod · 0.65

Tested by 2

TestShouldReshardFunction · 0.64