newReplicatedStates creates a new state struct, which manages state to be replicated between alertmanagers.
(userID string, rf int, re Replicator, st alertstore.AlertStore, l log.Logger, r prometheus.Registerer)
| 66 | |
| 67 | // newReplicatedStates creates a new state struct, which manages state to be replicated between alertmanagers. |
| 68 | func newReplicatedStates(userID string, rf int, re Replicator, st alertstore.AlertStore, l log.Logger, r prometheus.Registerer) *state { |
| 69 | |
| 70 | s := &state{ |
| 71 | logger: l, |
| 72 | userID: userID, |
| 73 | replicationFactor: rf, |
| 74 | replicator: re, |
| 75 | store: st, |
| 76 | states: make(map[string]cluster.State, 2), // we use two, one for the notifications and one for silences. |
| 77 | msgc: make(chan *clusterpb.Part), |
| 78 | reg: r, |
| 79 | settleReadTimeout: defaultSettleReadTimeout, |
| 80 | storeReadTimeout: defaultStoreReadTimeout, |
| 81 | partialStateMergesTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ |
| 82 | Name: "alertmanager_partial_state_merges_total", |
| 83 | Help: "Number of times we have received a partial state to merge for a key.", |
| 84 | }, []string{"type"}), |
| 85 | partialStateMergesFailed: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ |
| 86 | Name: "alertmanager_partial_state_merges_failed_total", |
| 87 | Help: "Number of times we have failed to merge a partial state received for a key.", |
| 88 | }, []string{"type"}), |
| 89 | stateReplicationTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ |
| 90 | Name: "alertmanager_state_replication_total", |
| 91 | Help: "Number of times we have tried to replicate a state to other alertmanagers.", |
| 92 | }, []string{"type"}), |
| 93 | stateReplicationFailed: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ |
| 94 | Name: "alertmanager_state_replication_failed_total", |
| 95 | Help: "Number of times we have failed to replicate a state to other alertmanagers.", |
| 96 | }, []string{"type"}), |
| 97 | fetchReplicaStateTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{ |
| 98 | Name: "alertmanager_state_fetch_replica_state_total", |
| 99 | Help: "Number of times we have tried to read and merge the full state from another replica.", |
| 100 | }), |
| 101 | fetchReplicaStateFailed: promauto.With(r).NewCounter(prometheus.CounterOpts{ |
| 102 | Name: "alertmanager_state_fetch_replica_state_failed_total", |
| 103 | Help: "Number of times we have failed to read and merge the full state from another replica.", |
| 104 | }), |
| 105 | initialSyncTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{ |
| 106 | Name: "alertmanager_state_initial_sync_total", |
| 107 | Help: "Number of times we have tried to sync initial state from peers or remote storage.", |
| 108 | }), |
| 109 | initialSyncCompleted: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ |
| 110 | Name: "alertmanager_state_initial_sync_completed_total", |
| 111 | Help: "Number of times we have completed syncing initial state for each possible outcome.", |
| 112 | }, []string{"outcome"}), |
| 113 | initialSyncDuration: promauto.With(r).NewHistogram(prometheus.HistogramOpts{ |
| 114 | Name: "alertmanager_state_initial_sync_duration_seconds", |
| 115 | Help: "Time spent syncing initial state from peers or remote storage.", |
| 116 | Buckets: prometheus.ExponentialBuckets(0.008, 4, 7), |
| 117 | }), |
| 118 | } |
| 119 | s.initialSyncCompleted.WithLabelValues(syncFromReplica) |
| 120 | s.initialSyncCompleted.WithLabelValues(syncFromStorage) |
| 121 | s.initialSyncCompleted.WithLabelValues(syncUserNotFound) |
| 122 | s.initialSyncCompleted.WithLabelValues(syncFailed) |
| 123 | |
| 124 | s.Service = services.NewBasicService(s.starting, s.running, nil) |
| 125 |