Skip to content

Unify config parsing - #675

Merged
refs merged 17 commits into
masterfrom
config-housekeeping-proxy
Nov 5, 2020
Merged

refs merged 17 commits into
masterfrom
config-housekeeping-proxy

Conversation

@refs

@refs refs commented Oct 9, 2020 •

Copy link
Copy Markdown
Contributor

fixing #671

- responsibility for config parsing should be on the subcommand
- if there is a config file in the environment location, env var should take precedence
- general rule of thumb: the more explicit the config file is that would be picked up. Order from less to more explicit:
    - config location (/etc/ocis)
    - environment variable
    - cli flag

It should work both in the standalone proxy command and embedded in the ocis command (as a subcommand). Here are some examples and expected behaviors:

As a standalone proxy command (cd proxy):

precondition: create a proxy.json file on /etc/ocis. The easiest way is to move the one on /proxy: mv config/proxy-example-migration.json /etc/ocis/proxy.json

path env cli loaded
go run cmd/proxy/main.go --log-level=debug server ✅ path
PROXY_CONFIG_FILE=config/proxy-example-migration.json go run cmd/proxy/main.go --log-level=debug server ✅ ✅ env
PROXY_CONFIG_FILE=config/proxy-example-migration.json go run cmd/proxy/main.go --log-level=debug server --config-file config/proxy-example-migration.json-this-file-doesnt-exist-but-will-be-picked-up-as-it-is-the-more-explicit ✅ ✅ ✅ cli

As an embedded subcommand on ocis proxy command (cd proxy):

path env cli parsed
go run cmd/ocis/main.go --log-level=debug proxy ✅ path
PROXY_CONFIG_FILE=../proxy/config/proxy-example-migration.json go run cmd/ocis/main.go --log-level=debug proxy ✅ ✅ env
PROXY_CONFIG_FILE=../proxy/config/proxy-example-migration.json go run cmd/ocis/main.go --log-level=debug proxy --config-file config/proxy-example-migration.json-this-file-doesnt-exist-but-will-be-picked-up-as-it-is-the-more-explicit ✅ ✅ ✅ cli

Other things this PR address

The ocis root command was never parsing any config whatsoever. This PR allows for configuring high level settings for the root command in the same fashion as its extensions, with the only difference being these global options cascade down to ocis extensions it embeds.

A clear example of this is the following scenario:

  1. create a config file for ocis on /etc/ocis/ocis.json with the following contents:

ocis-11d6a46146

  1. run ocis server

By this point, you should see a log wall similar to this:

grafik
(please note that this is but a portion of the entire logs...)

The point being all extensions configuring the same logging configuration. Now, while cascading works as expected, extensions can still override them using their own config files / environment variables. Let's see an example of it.

  1. with the existing ocis json config file in the correct location
  2. create a proxy.json config file, also on /etc/ocis with the following contents:

proxy-3134355ba2

  1. run ocis server

Now the log wall should look familiar to the previous step, with the only difference being the proxy service loading its log values from its own configuration file on /etc/ocis/proxy.json:

carbon(2)

Please note that the premise of this PR on keeping parsing order stays present. In fact with both config files existing from previous steps, running the following command

PROXY_LOG_LEVEL=info go run cmd/ocis/main.go server

will effectively override the value on /etc/ocis/proxy.json regarding the log level, the ones that are not overridden remain as parsed from the config file.

@refs refs self-assigned this Oct 9, 2020
@refs
refs requested a review from felixboehm October 9, 2020 09:25
@update-docs

update-docs Bot commented Oct 9, 2020

Copy link
Copy Markdown

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@kulmann

kulmann commented Oct 9, 2020

Copy link
Copy Markdown
Contributor
  • responsibility for config parsing should be on the subcommand

  • if there is a config file in the environment location, env var should take precedence

  • general rule of thumb: the more explicit the config file is that would be picked up. Order from less to more explicit:

    • config location (/etc/ocis)
    • environment variable
    • cli flag

full ack

@felixboehm felixboehm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, explains it!

@phil-davis

Copy link
Copy Markdown
Contributor

Should this have a changelog, or not?

@refs

refs commented Oct 9, 2020

Copy link
Copy Markdown
Contributor Author

Should this have a changelog, or not?

@phil-davis yes absolutely. And before merging it I would like to update all the other extensions aligned to these changes. Please do not merge yet :)

@phil-davis

Copy link
Copy Markdown
Contributor

@refs good to know - I saw the green approval tick from @felixboehm and I'm glad I asked.

@IljaN
IljaN self-requested a review October 9, 2020 14:14
@kulmann
kulmann marked this pull request as draft October 9, 2020 15:27
@refs
refs marked this pull request as ready for review November 4, 2020 14:47
@refs
refs force-pushed the config-housekeeping-proxy branch from 3b3ead1 to fa7f137 Compare November 5, 2020 10:29
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2020

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@refs
refs merged commit 2d1d2d0 into master Nov 5, 2020
@refs
refs deleted the config-housekeeping-proxy branch November 5, 2020 13:13
ownclouders pushed a commit that referenced this pull request Nov 5, 2020
Merge: 6b05e92 d9962ee
Author: Alex Unger <[email protected]>
Date:   Thu Nov 5 14:13:28 2020 +0100

    Merge pull request #675 from owncloud/config-housekeeping-proxy
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.

5 participants