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

Implement File based configuration #351

Merged
merged 13 commits into from
Mar 18, 2024
Merged

Implement File based configuration #351

merged 13 commits into from
Mar 18, 2024

Conversation

mochi-co
Copy link
Collaborator

@mochi-co mochi-co commented Dec 25, 2023

Following our discussions and @dgduncan's work in #309, here is a PR which implements a new file-based configuration for the broker.

A runnable example can be found in examples/config.

How it works
Rather creating a layer which adds listeners and hooks as they are in the main.go files, I have opted instead to update the hooks and listeners so that they can be applied directly through the server options.

The server options, capabilities, and compatibilities transfer directly from yaml/json into their normal options struct, as though it were being provided as a value created in main.go. Refer to examples/config/config.yaml (or config.json) for all options.

The listeners are defined using a slice Listener.Config, specifying the Type, ID, and Address. TLS can also be specified although I haven't tried it, so it may need a bit of work.

Hooks are defined individually, and split by category. As above, see config.yaml for a full list of options for each hook. This was a bit tricky to implement in a respectable manner, but in the end I decided to simply give hooks their own configuration struct, and allow only one type of each hook, which allows us to provide custom parameters for each (e.g. Auth and Storage.Redis).

I have updated the Dockerfile and added a cmd/docker.main.go as per @dgduncan's original work. I have not tested it.

Caveats

  • If you use file-based configuration, you can only have one of each hook type. However, this should be fine for 99% of users.
  • You can only use built in hooks with file-based configuration, as the type needs to be known in order for it to be applied.
  • You can only use built in listeners, for the reasons above.

Contains breaking changes for the way listeners are initialized (id and address are now in Config).

If you wish to use custom hooks and listeners, you will currently need to modify the code to support these, or just use the standard system of applying them in a custom go file.

I suspect I've missed some edge-cases too, but thought I'd submit it for review :)

@mochi-co mochi-co added the enhancement New feature or request label Dec 25, 2023
@coveralls
Copy link

coveralls commented Dec 25, 2023

Pull Request Test Coverage Report for Build 8320787965

Details

  • 144 of 151 (95.36%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.06%) to 98.614%

Changes Missing Coverage Covered Lines Changed/Added Lines %
config/config.go 71 78 91.03%
Totals Coverage Status
Change from base Build 8319335138: -0.06%
Covered Lines: 5692
Relevant Lines: 5772

💛 - Coveralls

@dgduncan
Copy link
Collaborator

@mochi-co great job carrying on the work! I'll take a look at this asap.

mochi-co and others added 11 commits January 11, 2024 20:37
… to avoid data race (#360)

Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>
* Only pass a copy of system.Info to hooks

* Rename Itoa to Int64toa

---------

Co-authored-by: JB <28275108+mochi-co@users.noreply.github.com>
* Allow configurable max stored qos > 0 messages

* Only rollback Inflight if QoS > 0

* Only rollback Inflight if QoS > 0

* Minor refactor
# Conflicts:
#	hooks/storage/badger/badger.go
#	server.go
@mochi-co mochi-co merged commit 26418c6 into main Mar 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants