@@ -80,19 +80,19 @@ func newReplicatedStates(userID string, rf int, re Replicator, st alertstore.Ale
80
80
partialStateMergesTotal : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
81
81
Name : "alertmanager_partial_state_merges_total" ,
82
82
Help : "Number of times we have received a partial state to merge for a key." ,
83
- }, []string {"key " }),
83
+ }, []string {"type " }),
84
84
partialStateMergesFailed : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
85
85
Name : "alertmanager_partial_state_merges_failed_total" ,
86
86
Help : "Number of times we have failed to merge a partial state received for a key." ,
87
- }, []string {"key " }),
87
+ }, []string {"type " }),
88
88
stateReplicationTotal : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
89
89
Name : "alertmanager_state_replication_total" ,
90
90
Help : "Number of times we have tried to replicate a state to other alertmanagers." ,
91
- }, []string {"key " }),
91
+ }, []string {"type " }),
92
92
stateReplicationFailed : promauto .With (r ).NewCounterVec (prometheus.CounterOpts {
93
93
Name : "alertmanager_state_replication_failed_total" ,
94
94
Help : "Number of times we have failed to replicate a state to other alertmanagers." ,
95
- }, []string {"key " }),
95
+ }, []string {"type " }),
96
96
fetchReplicaStateTotal : promauto .With (r ).NewCounter (prometheus.CounterOpts {
97
97
Name : "alertmanager_state_fetch_replica_state_total" ,
98
98
Help : "Number of times we have tried to read and merge the full state from another replica." ,
@@ -132,10 +132,10 @@ func (s *state) AddState(key string, cs cluster.State, _ prometheus.Registerer)
132
132
133
133
s .states [key ] = cs
134
134
135
- s .partialStateMergesTotal .WithLabelValues (getKeyWithoutUser (key ))
136
- s .partialStateMergesFailed .WithLabelValues (getKeyWithoutUser (key ))
137
- s .stateReplicationTotal .WithLabelValues (getKeyWithoutUser (key ))
138
- s .stateReplicationFailed .WithLabelValues (getKeyWithoutUser (key ))
135
+ s .partialStateMergesTotal .WithLabelValues (getStateTypeFromKey (key ))
136
+ s .partialStateMergesFailed .WithLabelValues (getStateTypeFromKey (key ))
137
+ s .stateReplicationTotal .WithLabelValues (getStateTypeFromKey (key ))
138
+ s .stateReplicationFailed .WithLabelValues (getStateTypeFromKey (key ))
139
139
140
140
return & stateChannel {
141
141
s : s ,
@@ -145,18 +145,18 @@ func (s *state) AddState(key string, cs cluster.State, _ prometheus.Registerer)
145
145
146
146
// MergePartialState merges a received partial message with an internal state.
147
147
func (s * state ) MergePartialState (p * clusterpb.Part ) error {
148
- s .partialStateMergesTotal .WithLabelValues (getKeyWithoutUser (p .Key )).Inc ()
148
+ s .partialStateMergesTotal .WithLabelValues (getStateTypeFromKey (p .Key )).Inc ()
149
149
150
150
s .mtx .Lock ()
151
151
defer s .mtx .Unlock ()
152
152
st , ok := s .states [p .Key ]
153
153
if ! ok {
154
- s .partialStateMergesFailed .WithLabelValues (getKeyWithoutUser (p .Key )).Inc ()
154
+ s .partialStateMergesFailed .WithLabelValues (getStateTypeFromKey (p .Key )).Inc ()
155
155
return fmt .Errorf ("key not found while merging" )
156
156
}
157
157
158
158
if err := st .Merge (p .Data ); err != nil {
159
- s .partialStateMergesFailed .WithLabelValues (getKeyWithoutUser (p .Key )).Inc ()
159
+ s .partialStateMergesFailed .WithLabelValues (getStateTypeFromKey (p .Key )).Inc ()
160
160
return err
161
161
}
162
162
@@ -286,9 +286,9 @@ func (s *state) running(ctx context.Context) error {
286
286
return nil
287
287
}
288
288
289
- s .stateReplicationTotal .WithLabelValues (getKeyWithoutUser (p .Key )).Inc ()
289
+ s .stateReplicationTotal .WithLabelValues (getStateTypeFromKey (p .Key )).Inc ()
290
290
if err := s .replicator .ReplicateStateForUser (ctx , s .userID , p ); err != nil {
291
- s .stateReplicationFailed .WithLabelValues (getKeyWithoutUser (p .Key )).Inc ()
291
+ s .stateReplicationFailed .WithLabelValues (getStateTypeFromKey (p .Key )).Inc ()
292
292
level .Error (s .logger ).Log ("msg" , "failed to replicate state to other alertmanagers" , "user" , s .userID , "key" , p .Key , "err" , err )
293
293
}
294
294
case <- ctx .Done ():
@@ -316,8 +316,8 @@ func (c *stateChannel) Broadcast(b []byte) {
316
316
c .s .broadcast (c .key , b )
317
317
}
318
318
319
- // getKeyWithoutUser used for trim the userID out of the metric label value .
320
- func getKeyWithoutUser (key string ) string {
319
+ // getStateTypeFromKey used for get the state type out of the state key .
320
+ func getStateTypeFromKey (key string ) string {
321
321
if strings .IndexByte (key , ':' ) < 0 {
322
322
return key
323
323
}
0 commit comments