-
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
Add :ignore
behavior for discovery events
#3069
Conversation
@@ -26,6 +26,11 @@ defmodule Trento.Infrastructure.Commanded.Middleware.Enrich do | |||
pipeline | |||
|> respond({:error, reason}) | |||
|> halt | |||
|
|||
{:ignore, reason} -> |
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.
question(naming): I'm open to alternative names for this: halt, skip, noop...
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.
Hey @balanza ,
What do you think of the next option?
Simply return {:error, :database_not_registered}
in the enrichment code, as before. The same goes for the discovery. And in the FallbackController
, instead of returning 404, simply return 202. I mean, move the logic to the FallbackController in this scenario. I think, internally, for the enrichment protocol and discovery, this can continue being an error, and you decide how to handle this error somewhere else.
Otherwise, I see this new aggregate_dispatch_results
really confusing an error prone. For example, ignored messages coming with error ones, are kind of ignored, and only the error message is logged.
@@ -36,7 +36,7 @@ defimpl Trento.Infrastructure.Commanded.Middleware.Enrichable, | |||
}} | |||
|
|||
nil -> | |||
{:error, :database_not_registered} | |||
{:ignore, :database_not_registered} |
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.
Let's add here, before returning, a concise message of what's happening, to give real undoubetable hint about what's their issue.
Something like:
Logger.error("database instance associated to application instance #{sid} not registered in Trento. Please make sure that Trento agent is running on database instances associated to this SAP system")
You can get the sid
in the RegisterApplicationInstance
command I guess
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.
Should be an error or a warning?
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.
Yes, maybe an warning is more appropriate
defp aggregate_dispatch_results({:ignore, reasons}, {:error, reason}), | ||
do: {:error, [reason | reasons]} | ||
|
||
defp aggregate_dispatch_results({:error, reasons}, :ok), do: {:errors, reasons} |
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 return {:error, reasons}
in any case
@arbulu89 I'm trying to avoid the I see the implementation I'm proposing is maybe too convoluted. As an alternative, I'm keen to just return |
What I propose doesn't even require to do almost any single change in the enrichment or discovery code.
It simply defines what type of return to use in the controller in case of we don't have the happy path |
I don't mind the ignore semantics. However it is true that returning a different error, perhaps a more specific one, allowing us to catch it in the outer layer and act accordingly (the fallback controller in this case returning a 202) is simpler and requires less changes. |
@nelsonkopliku @arbulu89 Thanks for the review, I buy your point and I'll go for a simpler solution. I open a new PR. |
A received discovery event is discarded even if valid and correctly mapped to a command. This can happen if it does not make sense for the state of the
SapSystem
aggregate at that moment.Namely, this happens with the
RegisterApplicationInstance
command. When the relative database instance has not been registered yet, the command cannot be processed.This scenario is not considered an error anymore; instead, the command is just ignored and the publishing client receives a
202 Accepted
response.Despite being applied to discovery events, the behavior is available to any other command that's been enriched (example)