| 243 | } |
| 244 | |
| 245 | func NewWithStoreClientAndStrategy(cfg Config, name, key string, store kv.Client, strategy ReplicationStrategy, reg prometheus.Registerer, logger log.Logger) (*Ring, error) { |
| 246 | if cfg.ReplicationFactor <= 0 { |
| 247 | return nil, fmt.Errorf("ReplicationFactor must be greater than zero: %d", cfg.ReplicationFactor) |
| 248 | } |
| 249 | |
| 250 | r := &Ring{ |
| 251 | key: key, |
| 252 | cfg: cfg, |
| 253 | KVClient: store, |
| 254 | strategy: strategy, |
| 255 | ringDesc: &Desc{}, |
| 256 | shuffledSubringCache: map[subringCacheKey]*Ring{}, |
| 257 | memberOwnershipGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{ |
| 258 | Name: "ring_member_ownership_percent", |
| 259 | Help: "The percent ownership of the ring by member", |
| 260 | ConstLabels: map[string]string{"name": name}}, |
| 261 | []string{"member"}), |
| 262 | numMembersGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{ |
| 263 | Name: "ring_members", |
| 264 | Help: "Number of members in the ring", |
| 265 | ConstLabels: map[string]string{"name": name}}, |
| 266 | []string{"state", "zone"}), |
| 267 | totalTokensGauge: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ |
| 268 | Name: "ring_tokens_total", |
| 269 | Help: "Number of tokens in the ring", |
| 270 | ConstLabels: map[string]string{"name": name}}), |
| 271 | numTokensGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{ |
| 272 | Name: "ring_tokens_owned", |
| 273 | Help: "The number of tokens in the ring owned by the member", |
| 274 | ConstLabels: map[string]string{"name": name}}, |
| 275 | []string{"member"}), |
| 276 | oldestTimestampGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{ |
| 277 | Name: "ring_oldest_member_timestamp", |
| 278 | Help: "Timestamp of the oldest member in the ring.", |
| 279 | ConstLabels: map[string]string{"name": name}}, |
| 280 | []string{"state"}), |
| 281 | logger: logger, |
| 282 | } |
| 283 | |
| 284 | r.Service = services.NewBasicService(r.starting, r.loop, nil).WithName(fmt.Sprintf("%s ring client", name)) |
| 285 | return r, nil |
| 286 | } |
| 287 | |
| 288 | func (r *Ring) starting(ctx context.Context) error { |
| 289 | // Get the initial ring state so that, as soon as the service will be running, the in-memory |