Skip to content

Conversation

@RIT3shSapata
Copy link
Contributor

CBG-4928

Describe your PR here...

  • Currently SGW logs the changes feed cancellation messages at warn level with "error" in the message
  • These are not necessarily errors, therefore the message level and messages have been updated appropriately
  • The other part of this ticket is implemented in CBG-4928 do not log warning for closed blip sender #7878

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

Copilot AI review requested due to automatic review settings November 14, 2025 09:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the logging approach for changes feed cancellation scenarios. Currently, these cancellations are logged as warnings with "error" in the messages, but they are not necessarily errors. The changes downgrade the log level from WarnfCtx to InfofCtx, add the base.KeyChanges log key for better filtering, and update the error messages to be more descriptive and accurate.

Key Changes

  • Downgraded log level from warning to info for changes feed cancellation messages
  • Added base.KeyChanges log key to enable targeted log filtering
  • Updated error messages to be more descriptive (e.g., "Error retrieving changes" → "Could not retrieve changes")

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
db/channel_cache_single.go Simplified error message when changes feed is cancelled while waiting for view lock
db/changes.go Downgraded two log statements from warning to info level and updated messages to be more descriptive
base/error.go Updated ErrChannelFeed message from "Error while building channel feed" to "Failed to build channel feed"

changes, err := singleChannelCache.GetChanges(ctx, paginationOptions)
if err != nil {
base.WarnfCtx(ctx, "Error retrieving changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
base.InfofCtx(ctx, base.KeyChanges, "Could not retrieve changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

The error message 'Could not retrieve changes' is vague and doesn't clearly indicate that the changes feed was cancelled. Consider using a more specific message like 'Changes feed cancelled for channel %q: %v' to better reflect the actual cause.

Suggested change
base.InfofCtx(ctx, base.KeyChanges, "Could not retrieve changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
base.InfofCtx(ctx, base.KeyChanges, "Changes feed cancelled for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
} else {
base.InfofCtx(ctx, base.KeyChanges, "Could not retrieve changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
}

Copilot uses AI. Check for mistakes.
// On feed error, send the error and exit changes processing
if current[i].Err == base.ErrChannelFeed {
base.WarnfCtx(ctx, "MultiChangesFeed got error reading changes feed: %v", current[i].Err)
base.InfofCtx(ctx, base.KeyChanges, "Could not read changes feed: %v", current[i].Err)
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

The error message 'Could not read changes feed' is ambiguous and doesn't clearly indicate a cancellation scenario. Consider using 'Changes feed cancelled: %v' or 'Changes feed operation cancelled: %v' for clarity.

Suggested change
base.InfofCtx(ctx, base.KeyChanges, "Could not read changes feed: %v", current[i].Err)
base.InfofCtx(ctx, base.KeyChanges, "Changes feed cancelled: %v", current[i].Err)

Copilot uses AI. Check for mistakes.
ErrUpdateCancel = &sgError{"Cancel update"}
ErrImportCancelledPurged = HTTPErrorf(http.StatusNotFound, "Import Cancelled Due to Purge")
ErrChannelFeed = &sgError{"Error while building channel feed"}
ErrChannelFeed = &sgError{"Failed to build channel feed"}
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

The error message 'Failed to build channel feed' still implies a failure rather than a cancellation, which contradicts the PR's goal of treating these as non-error scenarios. Consider renaming to 'Channel feed cancelled' or similar to better reflect the intended semantics.

Suggested change
ErrChannelFeed = &sgError{"Failed to build channel feed"}
ErrChannelFeed = &sgError{"Channel feed cancelled"}

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can drop this, because I think this error wouldn't show up if we avoid logging it at all.

// overhead in that case (and prevent feedback loop on query backlog)
if options.ChangesCtx.Err() != nil {
return nil, fmt.Errorf("Changes feed cancelled while waiting for view lock")
return nil, fmt.Errorf("Changes feed cancelled")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("Changes feed cancelled")
return nil, fmt.Errorf("Changes feed cancelled %w", options.ChangesCtx.Err())

This would tell us in downstream while it was canceled, particularly if we are able to determine a cause, this will make the above easier to reason about I think.

changes, err := singleChannelCache.GetChanges(ctx, paginationOptions)
if err != nil {
base.WarnfCtx(ctx, "Error retrieving changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
base.InfofCtx(ctx, base.KeyChanges, "Could not retrieve changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Assuming the context cancellation is passed back in the error message:

								if !errors.Is(err, context.Canceled) && errors.Is(err, context.DeadlineExceeded) {
									base.WarnfCtx(ctx, "Error retrieving changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
								}

However, I think to match the behavior of below if we don't always wrap the context error message:

Suggested change
base.InfofCtx(ctx, base.KeyChanges, "Could not retrieve changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
if options.ChangesCtx.Err() != nil {
base.WarnfCtx(ctx, "Error retrieving changes for channel %q: %v", base.UD(singleChannelCache.ChannelID().Name), err)
}

Comment on lines 998 to -999
if current[i].Err == base.ErrChannelFeed {
base.WarnfCtx(ctx, "MultiChangesFeed got error reading changes feed: %v", current[i].Err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if current[i].Err == base.ErrChannelFeed {
base.WarnfCtx(ctx, "MultiChangesFeed got error reading changes feed: %v", current[i].Err)
if !options.ChangesCtx.Err() {
base.WarnfCtx(ctx, "MultiChangesFeed got error reading changes feed: %v", current[i].Err)
}

In this case, it's not clear whether that err from current[i].Err is better than the error returned.

ErrUpdateCancel = &sgError{"Cancel update"}
ErrImportCancelledPurged = HTTPErrorf(http.StatusNotFound, "Import Cancelled Due to Purge")
ErrChannelFeed = &sgError{"Error while building channel feed"}
ErrChannelFeed = &sgError{"Failed to build channel feed"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can drop this, because I think this error wouldn't show up if we avoid logging it at all.

Comment on lines 413 to 414
// Check whether the changes process has been terminated while we waited for the view lock, to avoid the view
// overhead in that case (and prevent feedback loop on query backlog)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Check whether the changes process has been terminated while we waited for the view lock, to avoid the view
// overhead in that case (and prevent feedback loop on query backlog)
// Check whether the changes process has been terminated before running a query

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.

3 participants