-
Notifications
You must be signed in to change notification settings - Fork 23
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
Rest api rework #124
Rest api rework #124
Conversation
rpc:multicall() doesn't guarantee the sequence of returned Results so running lists:zip with Nodes list and Results is not safe.
….yaml file. this is done only to simplify 'git rebase', no functional changes.
…e '/upload' method
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 for the PR, it's good to see another approach to providing correct and up to date API spec. It looks like you put much effort to make this work.
Being honest, I'm currently not convinced that's a convenient way to go. I may not have the full understanding yet or don't see the real value. Below there are my concerns:
-
I can see that we have multiple static files describing the API
open_api/amoc-openapi.yml
open_api/amoc-swagger.json
open_api/amoc_rest/priv/openapi.json
Can we have only one?
-
As far as I understand the approach taken in this PR generates the erlang code from the API spec. I find the other way around (the spec generated from the code) more convenient.
-
The auto-generated code doesn't fit our (any?) formatting rules
abe50d8
to
79a9b27
Compare
79a9b27
to
7f73d73
Compare
|
4b35f19
to
4bbe8b6
Compare
4bbe8b6
to
f967538
Compare
cef87d8
to
50cc0e5
Compare
9e416ac
to
1a76792
Compare
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 for extracting the generated code to an external repository. It's much cleaner and easier to understand it now. I had some questions and comments on the code.
exometer_core, | ||
exometer_report_graphite, | ||
exometer_report_statsd, | ||
ssl, |
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'd like to understand why amoc
doesn't need the the ssl
application now.
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.
amoc is a framework and it doesn't establish any connections. ssl must be mentioned as a dependency for the apps that really use it.
Users = maps:get(<<"users">>, Body), | ||
SettingsMap = maps:get(<<"settings">>, Body, #{}), | ||
Settings = [begin | ||
Key = binary_to_atom(K, latin1), |
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 is probably a copy-paste. I think it'd be good to change latin1
to utf8
as we have in other projects (MongooseIM for instance). It'd be even better to use binart_to_existing_atom
. The perfect solution would be to parse the binary and return atom only when the binary is acceptable.
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, I tried to introduce changes step by step. so the whole implementation of the rest api handlers is extracted from the previous cowboy-swagger based implementation. the risk is quite low, taking into account that this API should be called just once during the whole amoc app lifecycle. And the goal of this PR is to have equivalent API after migration, while binart_to_existing_atom usage requires introduction of some new error code. Also, amoc_config_env:parse_value(V)
can still introduce new atoms, but we definitely don't want to change that functionality.
{200, #{}, [{<<"nodes">>, ResponseList}]}; | ||
handle_request('ScenariosGet', _Req, _Context) -> | ||
Scenarios = amoc_scenario:list_scenario_modules(), | ||
BinaryScenarios = [atom_to_binary(S, latin1) || S <- Scenarios], |
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.
Is there a reason behind the latin1
encoding in amoc
? Maybe utf8
could be used here?
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.
latin1 should be good enough for the module name, but I can change it to utf8 if you want.
{200, #{}, [{<<"compile">>, Error}]} | ||
end; | ||
handle_request(OperationID, Req, Context) -> | ||
error_logger:error_msg( |
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 amoc we are using the built-in Erlang logger. I think it'd be better to be consistent with that and use it here as well.
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.
sure, that is a copy-past from the default handler. thanks for catching that.
@@ -59,17 +57,6 @@ end_per_testcase( | |||
end_per_testcase(_, _Config) -> | |||
destroy_env(). | |||
|
|||
get_scenario_status_returns_200_when_scenario_exists(_Config) -> |
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 this test case was 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.
it's a very old one. given_test_status_mocked(true)
- this is completely invalid, the mocked function should never return true
value (even before the migration), loaded
is used instead.
@@ -43,15 +31,6 @@ returns_up_when_amoc_up_online(_Config) -> | |||
?assertEqual(200, CodeHttp), | |||
?assertMatch({[{<<"node_status">>, <<"up">>}]}, Body). | |||
|
|||
|
|||
returns_down_when_api_up_and_amoc_down_offline(_Config) -> |
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 this test case was 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.
it doesn't introduce any value. it tests absolutely the same thing asreturns_down_when_api_up_and_amoc_down_online
, but restricts internal implementation.
cfc6f63
to
e1d839d
Compare
e1d839d
to
3e9fb1d
Compare
83cfe36
to
b27596b
Compare
This PR replaces an old cowboy-swagger based REST API with the new openapi-generator implementation.
The generated server code is in the separate repo https://github.com/esl/amoc_rest
The whole migration process is described here in details
NB: it is important to merge this PR using "create a merge commit" option!!!