Skip to content

Commit

Permalink
go/control/api: Improve node registration status clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Apr 26, 2023
1 parent 5950615 commit d243d97
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .changelog/5256.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
go/control/api: Improve node registration status clarity

Two new fields have been added to the node's control status output
under the registration status section:

- `successful` - true if the registration succeeded.
- `error` - error message if the registration failed.

Also, if the registration descriptor is expired, it is no longer
shown in the output.
6 changes: 6 additions & 0 deletions go/control/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ type IdentityStatus struct {

// RegistrationStatus is the node registration status.
type RegistrationStatus struct {
// Successful is true if the current registration has been successful.
Successful bool `json:"successful"`

// Error contains the error message if the current registration has not been successful.
Error string `json:"error,omitempty"`

// LastRegistration is the time of the last successful registration with the consensus registry
// service. In case the node did not successfully register yet, it will be the zero timestamp.
LastRegistration time.Time `json:"last_registration"`
Expand Down
68 changes: 64 additions & 4 deletions go/worker/registration/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,16 @@ func (w *Worker) registerNode(epoch beacon.EpochTime, hook RegisterNodeHook) err
}

if err := hook(&nodeDesc); err != nil {
w.Lock()
w.status.Successful = false
w.status.Error = err.Error()
if w.status.Descriptor != nil {
if w.status.Descriptor.Expiration < uint64(epoch) {
w.status.Descriptor = nil

Check warning on line 907 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L902-L907

Added lines #L902 - L907 were not covered by tests
}
}
w.Unlock()

Check warning on line 910 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L910

Added line #L910 was not covered by tests

return err
}

Expand All @@ -908,7 +918,20 @@ func (w *Worker) registerNode(epoch beacon.EpochTime, hook RegisterNodeHook) err
w.logger.Error("not registering: no runtimes provided while runtimes are required",
"node_descriptor", nodeDesc,
)
return fmt.Errorf("registration: no runtimes provided while runtimes are required")

err := fmt.Errorf("registration: no runtimes provided while runtimes are required")

Check warning on line 922 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L922

Added line #L922 was not covered by tests

w.Lock()
w.status.Successful = false
w.status.Error = err.Error()
if w.status.Descriptor != nil {
if w.status.Descriptor.Expiration < uint64(epoch) {
w.status.Descriptor = nil

Check warning on line 929 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L924-L929

Added lines #L924 - L929 were not covered by tests
}
}
w.Unlock()

Check warning on line 932 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L932

Added line #L932 was not covered by tests

return err

Check warning on line 934 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L934

Added line #L934 was not covered by tests
}

sentryConsensusAddrs := w.querySentries()
Expand All @@ -917,7 +940,19 @@ func (w *Worker) registerNode(epoch beacon.EpochTime, hook RegisterNodeHook) err
if nodeDesc.HasRoles(registry.ConsensusAddressRequiredRoles) {
addrs, err := w.gatherConsensusAddresses(sentryConsensusAddrs)
if err != nil {
return fmt.Errorf("error gathering consensus addresses: %w", err)
err = fmt.Errorf("error gathering consensus addresses: %w", err)

Check warning on line 943 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L943

Added line #L943 was not covered by tests

w.Lock()
w.status.Successful = false
w.status.Error = err.Error()
if w.status.Descriptor != nil {
if w.status.Descriptor.Expiration < uint64(epoch) {
w.status.Descriptor = nil

Check warning on line 950 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L945-L950

Added lines #L945 - L950 were not covered by tests
}
}
w.Unlock()

Check warning on line 953 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L953

Added line #L953 was not covered by tests

return err

Check warning on line 955 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L955

Added line #L955 was not covered by tests
}
nodeDesc.Consensus.Addresses = addrs
}
Expand Down Expand Up @@ -946,6 +981,18 @@ func (w *Worker) registerNode(epoch beacon.EpochTime, hook RegisterNodeHook) err
w.logger.Error("failed to register node: unable to sign node descriptor",
"err", err,
)
err = fmt.Errorf("unable to sign node descriptor: %w", err)

Check warning on line 984 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L984

Added line #L984 was not covered by tests

w.Lock()
w.status.Successful = false
w.status.Error = err.Error()
if w.status.Descriptor != nil {
if w.status.Descriptor.Expiration < uint64(epoch) {
w.status.Descriptor = nil

Check warning on line 991 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L986-L991

Added lines #L986 - L991 were not covered by tests
}
}
w.Unlock()

Check warning on line 994 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L994

Added line #L994 was not covered by tests

return err
}

Expand All @@ -954,14 +1001,27 @@ func (w *Worker) registerNode(epoch beacon.EpochTime, hook RegisterNodeHook) err
w.logger.Error("failed to register node",
"err", err,
)

w.Lock()
w.status.Successful = false
w.status.Error = err.Error()
if w.status.Descriptor != nil {
if w.status.Descriptor.Expiration < uint64(epoch) {
w.status.Descriptor = nil

Check warning on line 1010 in go/worker/registration/worker.go

View check run for this annotation

Codecov / codecov/patch

go/worker/registration/worker.go#L1010

Added line #L1010 was not covered by tests
}
}
w.Unlock()

return err
}

// Update the registration status on successful registration.
w.RLock()
w.Lock()
w.status.Successful = true
w.status.Error = ""
w.status.LastRegistration = time.Now()
w.status.Descriptor = &nodeDesc
w.RUnlock()
w.Unlock()

w.logger.Info("node registered with the registry")
return nil
Expand Down

0 comments on commit d243d97

Please sign in to comment.