shouldReshard returns whether resharding should occur.
(desiredShards int)
| 1128 | |
| 1129 | // shouldReshard returns whether resharding should occur. |
| 1130 | func (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 |