fix: missing events in the event store #4335
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About the changes
We are losing some events because of not having "created by" which is required by a constraint in the DB. One scenario where this can happen is with the default user admin, because it doesn't have a username or an email (unless configured by the administrator).
Our code makes assumptions on the existence of one of these 2 attributes (e.g.
unleash/src/lib/services/user-service.ts
Lines 220 to 222 in 248118a
Event lost metrics:
Discussion points
The solution proposed here is falling back to a default value. I've chosen
"admin"
because it covers one of the use cases, but it can also be"system"
mimickingunleash/src/lib/services/user-service.ts
Line 32 in 248118a
"unknown"
which is sometimes used as a default:unleash/src/lib/services/project-service.ts
Line 57 in 248118a
Anyway, I believe it's better not to lose the event rather than be accurate with the "created by" that can be fixed later