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

Allow local override of operational configs #5314

Conversation

mjungsbluth
Copy link
Contributor

@mjungsbluth mjungsbluth commented Oct 27, 2022

A draft PR to address #5070

It makes specific attributes on the OPA configuration overridable if discovery is used

  • It allows all decision_logs.runtime.* attributes
  • It allows the caching configuration to be overridden

It also introduces an interface for plugin factories to make their config partially overridable.

This PR is still a draft because at least one negative test and a test for the plugin factories is missing

@mjungsbluth mjungsbluth marked this pull request as draft October 27, 2022 06:51
@mjungsbluth mjungsbluth changed the title [DRAFT] Allow local override of operational configs Allow local override of operational configs Oct 27, 2022
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Some WIP comments, hope you don't mind.

err := d.Decode(&configStruct)

if err != nil {
return fmt.Errorf("discovery only allows manual configuration of the decision_logs plugin for the reporting.* configuration items")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit odd. The code makes me think that there might be many ways to fail d.Decode() and yet we pretend that it's always due to extra config items.

I suppose one alternative would be something along the lines of

m := map[string]interface{}{}
if err := json.NewDecoder(...).Decode(&m); err != nil {
     return err
}
_, ok := m["reporting"]
if ok && len(m) == 1 {
    return nil
}
return fmt.Errorf("discovery only allows manual configuration of the decision_logs plugin for the reporting.* configuration items")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this definitely needs some work. I originally wanted to only allow a subset of reporting, i.e. the buffer sizes and client rates. And agreed that there are other error scenarios, I was about to decode plainly and with disallowing unknown fields and then comparing if plain decoding works without error to narrow the root cause.

If we agree to make the entire runtime tree overridable, your suggestion is of course much simpler. I am not sure about the Trigger config inside runtime, wdyt?

plugins/discovery/discovery_test.go Outdated Show resolved Hide resolved
"plugins": {
"test_plugin": {"a": "b"}
},
"decision_logs": {"partition_name": "bar"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth testing that in the case that discovery also sets the value, the local override wins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, also we have to agree on order of the override, which is why I posted this as draft. The current version lets the local version win in case both discovery and local for example contain decision_logs.runtime.* configs. We can also reverse this. This still allows to generally configure operational attributes locally if they are not forced centrally.

plugins/discovery/discovery.go Outdated Show resolved Hide resolved
plugins/discovery/discovery.go Outdated Show resolved Hide resolved
factory := result.factories[name]
var pluginConfig json.RawMessage
if name == "decision_logs" {
if err := logs.AllowConfigOverride(manager.Config.DecisionLogs); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 so decision logs doesn't live in manager.Config.Plugins["decision_logs"]? Unfortunate 😳

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that is actually how I started 😄 . All the "initial" plugins also do not implement the Factory interface so I guess this is all structures from the early days. It also leads to quite a bit of boilerplate further down...

plugins/plugins.go Outdated Show resolved Hide resolved
Co-authored-by: Stephan Renatus <stephan@styra.com>
@netlify
Copy link

netlify bot commented Oct 27, 2022

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 625e75c
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/635a722c6225bb0008f76613
😎 Deploy Preview https://deploy-preview-5314--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@stale
Copy link

stale bot commented Nov 26, 2022

This pull request has been automatically marked as stale because it has not had any activity in the last 30 days.

@stale stale bot added the inactive label Nov 26, 2022
@srenatus
Copy link
Contributor

srenatus commented Dec 7, 2022

🟢 Let's circle back on this if your objective still isn't met in any ways. Cleaning up the PR for now. 🧹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants