-
Notifications
You must be signed in to change notification settings - Fork 7
Extract notification methods in identified object store #77
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
Extract notification methods in identified object store #77
Conversation
Codecov Report
@@ Coverage Diff @@
## main #77 +/- ##
============================================
- Coverage 85.15% 84.20% -0.96%
- Complexity 305 308 +3
============================================
Files 38 38
Lines 1495 1519 +24
Branches 45 45
============================================
+ Hits 1273 1279 +6
- Misses 191 209 +18
Partials 31 31
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
|
Also handle delete case. We should update DefaultObjectStore and ContextuallyIdentifiedObjectStore as well. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's some confusion about the flow here, so let's walk through.
Imagine I have an ObjectStore<MyInternalObject>. That means that I'm reading and writing instances of MyInternalObject. Now, imagine MyInternalObject is just a representation of MyApiObject, which is otherwise not exposed to the object store - supporting this scenario is the goal of this enhancement.
So when I call buildValueFromData, we want a Value representation of MyInternalObject - this is what goes to the server. When I call buildValueForChangeEvent, we want a Value representation of MyApiObject - that's what goes into change events (and the default implementation assumes thus that MyInternalObject is the same thing as MyApiObject).
So notice from the signatures MyApiObject doesn't show up anywhere - only a representation of it as a Value. Since that's the class name we want in the events too, we need to expose a way of configuring that.
On upsert, we have previousValue as a Value representation of MyInternalObject - luckily we already have the tools to go back and forth from Value<>MyInternalObject. We need to call something like this.buildDataFromValue(previousValue).map(this::buildValueForChangeEvent)
...store/src/main/java/org/hypertrace/config/objectstore/ContextuallyIdentifiedObjectStore.java
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
aaron-steinfeld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DefaultObjectStore should be updated, too
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Show resolved
Hide resolved
...store/src/main/java/org/hypertrace/config/objectstore/ContextuallyIdentifiedObjectStore.java
Show resolved
Hide resolved
| return this.buildValueFromData(data); | ||
| } | ||
|
|
||
| protected String buildClassNameForChangeEvent(T data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add tests for the case where this is a different class than T?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure I understand. obj.getClass().getName() work for any class right? What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably poorly phrased ask on my part. It does, but the reason we introduced buildClassNameForChangeEvent is that sometimes T is not the class we care about. I was interested in a test where we've overridden the default behavior (for example where T is MyInternalObject and we want our event to be sending MyApiObject)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Could you give an example as to how to move forward 😬.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
...store/src/main/java/org/hypertrace/config/objectstore/ContextuallyIdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
...store/src/main/java/org/hypertrace/config/objectstore/ContextuallyIdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
| log.error( | ||
| "Unable to convert previousValue back to data for change event. Falling back to raw value {}", | ||
| response.getPrevConfig()); | ||
| return response.getPrevConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have this special case. Please note consumer will not be able to handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consumer may or may not be able to, but at least we give them the option. This maps to the existing behavior (where we put in prevConfig as is, and don't check if it's transformable), but certainly open to other ideas (see #77 (comment) for various options I came up with)
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Outdated
Show resolved
Hide resolved
| log.error( | ||
| "Unable to convert previousValue back to data for change event. Falling back to raw value {}", | ||
| response.getPrevConfig()); | ||
| return response.getPrevConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consumer may or may not be able to, but at least we give them the option. This maps to the existing behavior (where we put in prevConfig as is, and don't check if it's transformable), but certainly open to other ideas (see #77 (comment) for various options I came up with)
object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
aaron-steinfeld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the tests I asked for in an earlier comment, the change lgtm. Will let @saxenakshitiz continue the discussion on how we want to handle the invalid previous case though.
This comment has been minimized.
This comment has been minimized.
|
|
||
| @lombok.Value | ||
| private static class TestObject { | ||
| private static class TestInternalObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : The test seems to suggest that object persisted in DB is completely different from object being published as part of change event. That is certainly possible. However in most of our usecases, the object being persisted will encapsulate the object being published as part of change event.

Description
Extract notification methods from IdentifiedObjectStore to be able to override sending notifications.