acl: acl replication routine to report the last error message

This commit is contained in:
Giulio Micheloni 2021-07-14 11:50:23 +02:00
parent e91996f130
commit 529fe737ef
4 changed files with 7 additions and 3 deletions

View File

@ -484,11 +484,12 @@ func (s *Server) IsACLReplicationEnabled() bool {
s.config.ACLTokenReplication
}
func (s *Server) updateACLReplicationStatusError() {
func (s *Server) updateACLReplicationStatusError(errorMsg error) {
s.aclReplicationStatusLock.Lock()
defer s.aclReplicationStatusLock.Unlock()
s.aclReplicationStatus.LastError = time.Now().Round(time.Second).UTC()
s.aclReplicationStatus.LastErrorMessage = errorMsg
}
func (s *Server) updateACLReplicationStatusIndex(replicationType structs.ACLReplicationType, index uint64) {

View File

@ -1,6 +1,7 @@
package consul
import (
"errors"
"fmt"
"os"
"strconv"
@ -780,6 +781,7 @@ func TestACLReplication_TokensRedacted(t *testing.T) {
require.True(r, status.ReplicatedTokenIndex < token2.CreateIndex, "ReplicatedTokenIndex is not less than the token2s create index")
// ensures that token replication is erroring
require.True(r, status.LastError.After(minErrorTime), "Replication LastError not after the minErrorTime")
require.Equal(r, status.LastErrorMessage, errors.New("failed to retrieve unredacted tokens - replication token in use does not grant acl:write"))
})
}

View File

@ -810,7 +810,7 @@ func (s *Server) runLegacyACLReplication(ctx context.Context) error {
0,
)
lastRemoteIndex = 0
s.updateACLReplicationStatusError()
s.updateACLReplicationStatusError(err)
legacyACLLogger.Warn("Legacy ACL replication error (will retry if still leader)", "error", err)
} else {
metrics.SetGauge([]string{"leader", "replication", "acl-legacy", "status"},
@ -927,7 +927,7 @@ func (s *Server) runACLReplicator(
0,
)
lastRemoteIndex = 0
s.updateACLReplicationStatusError()
s.updateACLReplicationStatusError(err)
logger.Warn("ACL replication error (will retry if still leader)",
"error", err,
)

View File

@ -1269,6 +1269,7 @@ type ACLReplicationStatus struct {
ReplicatedTokenIndex uint64
LastSuccess time.Time
LastError time.Time
LastErrorMessage error
}
// ACLTokenSetRequest is used for token creation and update operations