-
Notifications
You must be signed in to change notification settings - Fork 15
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
Log domain events #2817
Log domain events #2817
Conversation
4f9501b
to
13690ff
Compare
13690ff
to
b3e1bed
Compare
alias Trento.ActivityLog.ActivityLog | ||
alias Trento.Infrastructure.Commanded.EventHandlers.ActivityLogEventHandler | ||
|
||
test "should log a domain event" do |
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.
Pretty useless test 🙈, as we don't have anything really interesting happening here, except from calling the ActivityLogger. I can get rid of this.
metadata: metadata | ||
}) | ||
|
||
:ok |
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.
A doubt I have here is: if for any reason logging a specific interesting domain event fails, we'd be continuing silently.
If we want to be more reliable and have the event handler retry, we might want to not always return :ok
.
That means having ActivityLogger.log_activity
possibly return an :ok/:error tuple.
I guess we can have this improvement as a followup.
|> Enum.filter(fn | ||
["Trento", resource_type, "Events", _] | ||
when resource_type in [ | ||
"Hosts", | ||
"Clusters", | ||
"SapSystems", | ||
"Databases" | ||
] -> |
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 expectation on the name structure of modules that contain events can be turned into a Credo check, for better enforcing consistency.
f50947e
to
a17a387
Compare
387465d
to
4814ab6
Compare
Hey @gagandeepb @balanza the whole macros stuff have been revisited and eventually removed. |
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.
Thanks, looks good! Just one minor comment.
for {event, expected_activity_type} <- events do | ||
metadata = | ||
event | ||
|> Jason.encode!() | ||
|> Jason.decode!() |
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.
Why do you encode and decode again?
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.
because what gets stored is an arrow map, while the event itself is an atom map
%{
"foo" => "bar"
}
# vs
%{
foo: "bar"
}
Any suggestion on different approaches?
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.
Maybe something this should work/help:
Map.new(map_with_string_keys, fn {k, v} -> {String.to_exisiting_atom(k), v} end)
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.
tried, not working tho 😅
protocol Enumerable not implemented for %Trento.Hosts.Events.HostRegistered (and any other event struct I guess)
Description
This PR extends Activity Logging capabilities so that all domain events can be tracked as activity log entries.
How was this tested?
Automated tests.