-
Notifications
You must be signed in to change notification settings - Fork 1
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
Rework internal API #12
Conversation
achouippe
commented
Jul 22, 2024
•
edited
Loading
edited
- Add an OpenAPI descriptor for the internal API,
- Support one or multiple topics in one HTTP call,
- Support one or multiple published message in one HTTP cal,
- Validation of the JSON input,
- Split existing unit tests + comprehensive unit tests on the validation logic,
- Possibility to pass message timestamps in the publish request.
|
||
Logger.debug("Message published on topic: #{topic}") | ||
Stats.inc_msg_received() | ||
Stats.inc_msg_received() |
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.
Not sure what we really want to monitor with the new API.
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 we incr with nb_publish?
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.
Do we want to count the number of call on the internal interface per issuer ?
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.
In that case, it should be outside of the loop :)
|> put_resp_header("content-type", "text/html") | ||
|> send_resp(200, "Published #{message} to #{topic}\n") | ||
|> put_resp_header("content-type", "application/json") | ||
|> send_resp(200, "{\"nb_published\": #{nb_publish}}") |
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.
Jason.encode?
} | ||
end | ||
|
||
def validate(message) 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.
You can probably write this with a list of guard. May be it's cleaner.
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 tried first, but the combinatory effect make it much difficult to read.
end | ||
end | ||
|
||
def validate_topics(request) 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.
Same here, with guards?
end | ||
end | ||
|
||
def validate_messages(request) 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.
Ditto
Neurow.InternalApi.Message.from_json(payload["message"]) | ||
|
||
_ -> | ||
nil |
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.
nil -> nil, but _ -> error?
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.
The validation is performed later, so I prefer not to return an error at this step.
|
||
Logger.debug("Message published on topic: #{topic}") | ||
Stats.inc_msg_received() | ||
Stats.inc_msg_received() |
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.
In that case, it should be outside of the loop :)