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

CBG-3835 catch error in case there is a valid json but not a JSON object #6756

Merged
merged 3 commits into from
Apr 17, 2024

Conversation

torcolvin
Copy link
Collaborator

@torcolvin torcolvin commented Apr 5, 2024

The code has now been reverted to the state before 2bde1ea with two changes:

log debug for event.DataType == base.MemcachedDataTypeRaw, Info logging in 3.1.3/3.1.4 but no logging before
increment ImportErrorCount in the case of valid _sync xattr and valid json but not a json object
Wrote tests for the expected behavior, which is to silently ignore documents with invalid _sync metadata, where it is valid JSON but not a valid JSON object.

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

Integration Tests

Copy link
Collaborator

@adamcfraser adamcfraser left a comment

Choose a reason for hiding this comment

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

I have concerns about the overhead of the json.Valid call. It also feels like these changes are too heavyweight when considering the original enhancement we're trying to make here (CBG-3332), particularly considering this would be a backport candidate.

@adamcfraser adamcfraser assigned torcolvin and unassigned adamcfraser Apr 5, 2024
@torcolvin torcolvin changed the base branch from main to master April 9, 2024 15:00
@torcolvin torcolvin changed the base branch from master to main April 9, 2024 15:09
@torcolvin torcolvin assigned adamcfraser and unassigned torcolvin Apr 9, 2024
log in the case where there is _sync xattr but the body has become non
json
@torcolvin
Copy link
Collaborator Author

The code has now been reverted to the state before 2bde1ea with two changes:

  1. log debug for event.DataType == base.MemcachedDataTypeRaw, Info logging in 3.1.3/3.1.4 but no logging before
  2. increment ImportErrorCount in the case of valid _sync xattr and valid json but not a json object

Wrote tests for the expected behavior, which is to silently ignore documents with invalid _sync metadata, where it is valid JSON but not a valid JSON object.

require.Equal(t, int64(0), db.DbStats.SharedBucketImport().ImportErrorCount.Value())
}

func TestImportFeedNonJSONNewDoc(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is logging:

Found sync metadata, but unable to unmarshal for feed document "<ud>bookstand</ud>". Will not be imported. Error: readObjectStart: expect { or n, but found 1, error found in #1 byte of ...|1|..., bigger context ...|1|...

which is incorrect, because it didn't find sync metadata. I think we've decided we can't differentiate between this case and the ones above without additional overhead, so I think we need to change the error message to be more generic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the error messages and wrote them inline with the tests.

@torcolvin torcolvin requested a review from adamcfraser April 15, 2024 15:38
Copy link
Collaborator

@adamcfraser adamcfraser left a comment

Choose a reason for hiding this comment

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

One minor tweak for the debug logging, otherwise looks good.

@adamcfraser adamcfraser assigned torcolvin and unassigned adamcfraser Apr 15, 2024
Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>
@torcolvin torcolvin assigned adamcfraser and unassigned torcolvin Apr 15, 2024
@adamcfraser adamcfraser merged commit 64bad65 into main Apr 17, 2024
30 checks passed
@adamcfraser adamcfraser deleted the CBG-3835 branch April 17, 2024 23:19
torcolvin added a commit that referenced this pull request Apr 30, 2024
backport of CBG-3835 catch error in case there is a valid json but not a JSON object (#6756)

* Remove logging for invalid JSON in sync attribute

log in the case where there is _sync xattr but the body has become non
json

* Update log messages

* Update db/import_listener.go

Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>

---------

Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>
bbrks pushed a commit that referenced this pull request May 2, 2024
* [CBG-3876] suppress warning for non json objects

backport of CBG-3835 catch error in case there is a valid json but not a JSON object (#6756)

* Remove logging for invalid JSON in sync attribute

log in the case where there is _sync xattr but the body has become non
json

* Update log messages

* Update db/import_listener.go

Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>

---------

Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>

* Change test to work without multi-xattr write APIs

---------

Co-authored-by: Adam Fraser <adam.fraser@couchbase.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