Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acl: acl replication routine to report the last error message #10612

Merged
merged 3 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion agent/consul/acl_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,12 @@ func (s *Server) IsACLReplicationEnabled() bool {
s.config.ACLTokenReplication
}

func (s *Server) updateACLReplicationStatusError() {
func (s *Server) updateACLReplicationStatusError(errorMsg error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are already doing a err != nil check in the caller, we were thinking it would be safer to accept a string here instead of an error. That way no new callers can accidentally pass a nil error.

Suggested change
func (s *Server) updateACLReplicationStatusError(errorMsg error) {
func (s *Server) updateACLReplicationStatusError(errorMsg string) {

which I guess will requires a change to the line below that uses errorMsg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

s.aclReplicationStatusLock.Lock()
defer s.aclReplicationStatusLock.Unlock()

s.aclReplicationStatus.LastError = time.Now().Round(time.Second).UTC()
s.aclReplicationStatus.LastErrorMessage = errorMsg.Error()
}

func (s *Server) updateACLReplicationStatusIndex(replicationType structs.ACLReplicationType, index uint64) {
Expand Down
1 change: 1 addition & 0 deletions agent/consul/acl_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,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, "failed to retrieve unredacted tokens - replication token in use does not grant acl:write")
})
}

Expand Down
4 changes: 2 additions & 2 deletions agent/consul/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions agent/structs/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ type ACLReplicationStatus struct {
ReplicatedTokenIndex uint64
LastSuccess time.Time
LastError time.Time
LastErrorMessage string
dnephin marked this conversation as resolved.
Show resolved Hide resolved
}

// ACLTokenSetRequest is used for token creation and update operations
Expand Down