Skip to content
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

feat: add conf load api #11180

Merged
merged 1 commit into from
Jul 4, 2023
Merged

Conversation

zhongwencool
Copy link
Contributor

@zhongwencool zhongwencool commented Jul 3, 2023

Fixes https://emqx.atlassian.net/browse/EMQX-9180

Summary

🤖 Generated by Copilot at c07db9d

This pull request improves the configuration management features of emqx by enhancing the emqx_conf_cli module and its related modules, adding a new configuration API that supports binary input and output, and updating the i18n file and the swagger documentation accordingly. It also removes some unused code and fixes some error handling cases.

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Changed lines covered in coverage report
  • Change log has been added to changes/{ce,ee}/(feat|perf|fix)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • If there should be document changes, a PR to emqx-docs.git is sent, or a jira ticket is created to follow up
  • Schema changes are backward compatible

Checklist for CI (.github/workflows) changes

  • If changed package build workflow, pass this action (manual trigger)
  • Change log has been added to changes/ dir for user-facing artifacts update

@zhongwencool zhongwencool force-pushed the conf-load-api branch 2 times, most recently from 2985e14 to f04aa2b Compare July 3, 2023 08:13
@zhongwencool zhongwencool marked this pull request as ready for review July 3, 2023 08:13
@zhongwencool zhongwencool requested review from a team, lafirest and sstrigler as code owners July 3, 2023 08:13
@@ -208,15 +207,6 @@ schema_module() ->
Value -> list_to_existing_atom(Value)
end.

check_config(Mod, Raw) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this function to emqx_conf_cli

{error, Reason} ->
emqx_ctl:warning("load ~ts failed~n~p~n", [Path, Reason]),
{error, bad_hocon_file}
end;
load_config(Bin, ReplaceOrMerge) when is_binary(Bin) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load from binary is for HTTP API.

@@ -186,37 +191,47 @@ get_config(Key) ->
end.

-define(OPTIONS, #{rawconf_with_defaults => true, override_to => cluster}).
load_config(Path, ReplaceOrMerge) ->
load_config(Path, ReplaceOrMerge) when is_list(Path) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load from file is for CLI

parameters => [
{node,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

origin GET /configs is unused, So I think incompatibility here is accepted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that it should be kept, even if no one is using it?

Then, we can add a check on the HTTP Header of the request. If the Accept header is set to application/json or is not specified, we will return the response according to the original logic. If the Accept header is set to text/plain, we will return the response in hocon file format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll change it back right away, although personally I really dislike doing so.

@zhongwencool zhongwencool force-pushed the conf-load-api branch 2 times, most recently from 5461160 to 0b68782 Compare July 4, 2023 06:17
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 5451451624

  • 36 of 43 (83.72%) changed or added relevant lines in 3 files are covered.
  • 14 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.05%) to 82.016%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/emqx/src/emqx_config_handler.erl 1 2 50.0%
apps/emqx_management/src/emqx_mgmt_api_configs.erl 11 13 84.62%
apps/emqx_conf/src/emqx_conf_cli.erl 24 28 85.71%
Files with Coverage Reduction New Missed Lines %
apps/emqx_conf/src/emqx_conf_cli.erl 1 54.32%
apps/emqx_dashboard/src/emqx_dashboard_swagger.erl 1 97.38%
apps/emqx_management/src/emqx_mgmt_util.erl 1 13.79%
apps/emqx_resource/src/emqx_resource_buffer_worker.erl 1 93.4%
apps/emqx_utils/src/emqx_utils.erl 1 82.3%
apps/emqx/src/emqx_banned.erl 2 89.55%
apps/emqx/src/emqx_reason_codes.erl 7 94.12%
Totals Coverage Status
Change from base Build 5451123929: 0.05%
Covered Lines: 30766
Relevant Lines: 37512

💛 - Coveralls

Copy link
Member

@HJianBo HJianBo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhongwencool zhongwencool merged commit a45a163 into emqx:master Jul 4, 2023
@zhongwencool zhongwencool deleted the conf-load-api branch July 4, 2023 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants