| 43 | } |
| 44 | |
| 45 | func NewPartitionRingWatcherWithOptions(name, key string, kv kv.Client, opts PartitionRingOptions, logger log.Logger, reg prometheus.Registerer) *PartitionRingWatcher { |
| 46 | emptyRing, err := NewPartitionRingWithOptions(*NewPartitionRingDesc(), opts) |
| 47 | if err != nil { |
| 48 | panic(err) // This should never executes. |
| 49 | } |
| 50 | r := &PartitionRingWatcher{ |
| 51 | key: key, |
| 52 | kv: kv, |
| 53 | logger: logger, |
| 54 | ring: emptyRing, |
| 55 | numPartitionsGaugeVec: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{ |
| 56 | Name: "partition_ring_partitions", |
| 57 | Help: "Number of partitions by state in the partitions ring.", |
| 58 | ConstLabels: map[string]string{"name": name}, |
| 59 | }, []string{"state"}), |
| 60 | opts: opts, |
| 61 | } |
| 62 | |
| 63 | r.Service = services.NewBasicService(r.starting, r.loop, nil).WithName("partitions-ring-watcher") |
| 64 | return r |
| 65 | } |
| 66 | |
| 67 | // WithDelegate adds the delegate to be called when the partition ring changes. |
| 68 | // |