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

Events based cache: Address missed code review comments #5249

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

faisal-memon
Copy link
Contributor

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality

Events based cache

Description of change
Addressing some comments missed in review of #5071. It was merged before i could address them.

Which issue this PR fixes

Signed-off-by: Faisal Memon <fymemon@yahoo.com>
Comment on lines +160 to +168
// If there is a gap in the event stream, log the missed events for later processing.
// For example if the current event ID is 6 and the previous one was 3, events 4 and 5
// were skipped over and need to be queued in case they show up later.
// This can happen when a long running transaction allocates an event ID but a shorter transaction
// comes in after, allocates and commits the ID first. If a read comes in at this moment, the event id for
// the longer running transaction will be skipped over
if a.receivedFirstRegistrationEntryEvent && event.EventID != a.lastRegistrationEntryEventID+1 {
for i := a.lastRegistrationEntryEventID + 1; i < event.EventID; i++ {
a.log.WithField(telemetry.EventID, i).Info("Detected skipped registration entry event")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addresses this comment: #5071 (comment)

Comment on lines -249 to +268
// If there is a gap in the event stream, log the missed events for later processing
// If there is a gap in the event stream, log the missed events for later processing.
// For example if the current event ID is 6 and the previous one was 3, events 4 and 5
// were skipped over and need to be queued in case they show up later.
// This can happen when a long running transaction allocates an event ID but a shorter transaction
// comes in after, allocates and commits the ID first. If a read comes in at this moment, the event id for
// the longer running transaction will be skipped over
if a.receivedFirstAttestedNodeEvent && event.EventID != a.lastRegistrationEntryEventID+1 {
for i := a.lastAttestedNodeEventID + 1; i < event.EventID; i++ {
a.log.WithField(telemetry.EventID, i).Info("Detected skipped attested node event")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addresses this comment: #5071 (comment)

Comment on lines 229 to 237
if commonEntry == nil {
a.cache.RemoveEntry(entryID)
return nil
}

entry, err := api.RegistrationEntryToProto(commonEntry)
if err != nil {
a.cache.RemoveEntry(entryID)
return nil
return fmt.Errorf("removing malformed entry %s from cache: %w", entryID, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addresses this comment: #5071 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Won't returning an error here result in the event being processed again (and again and again), presumably with the same outcome each time (assuming the entry is malformed)?

IMO, this condition should be logged but otherwise the event should be considered handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed.

Signed-off-by: Faisal Memon <fymemon@yahoo.com>
entry, err := api.RegistrationEntryToProto(commonEntry)
if err != nil {
a.cache.RemoveEntry(entryID)
a.log.WithField(telemetry.RegistrationID, entryID).Info("Removed malformed registration entry from cache")
Copy link
Member

Choose a reason for hiding this comment

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

This is problematic enough we should log it at Warn level

Signed-off-by: Faisal Memon <fymemon@yahoo.com>
@azdagron azdagron merged commit 27f8c36 into spiffe:main Jun 25, 2024
33 checks passed
@faisal-memon faisal-memon deleted the events-cleanup branch June 25, 2024 23:45
edwbuck pushed a commit to edwbuck/spire that referenced this pull request Aug 20, 2024
Signed-off-by: Faisal Memon <fymemon@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants