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

Introduce feature flags to control experiments #658

Merged
merged 3 commits into from
May 11, 2022

Conversation

pivotaljohn
Copy link
Contributor

No description provided.

@pivotaljohn pivotaljohn linked an issue Apr 29, 2022 that may be closed by this pull request
@pivotaljohn pivotaljohn force-pushed the add-experiments-flag branch 3 times, most recently from 8c121ed to 88a9713 Compare May 3, 2022 22:38
cmd/ytt/ytt.go Outdated
"time"

uierrs "github.com/cppforlife/go-cli-ui/errors"
"github.com/vmware-tanzu/carvel-ytt/pkg/cmd"
"github.com/vmware-tanzu/carvel-ytt/pkg/feature"
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be local to the command (aka not global)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you share more of what you're thinking?

Copy link
Contributor

Choose a reason for hiding this comment

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

typically i try to go with least scope as possible. as soon as you go global scope, there is never certainty of what previous/current code could be influencing things -- e.g. in tests you have to be careful how things get cleaned, in prod code if i configure one instance of ytt library execution would it somehow we affected by some other external code (that might decide to tweak some feature flags possibly for another parallel execution).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, that absolutely makes sense for me for a "first class" feature flag.

This is meant to govern experiments. I'm thinking of it as a runtime-checked build flag: that it selects which flavor of executable should be used.

I was really wanting to avoid plumbing through this kind of thing through as it could potentially litter a bunch of unrelated abstractions.

Would this be a job for a Context?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking of it as a runtime-checked build flag: that it selects which flavor of executable should be used.

with you about the plumbing 👍

may be then the middle ground is:

  • only expose read only getter functions from that package so it's not an invitation for flip them during runtime
  • have a single function that acts as a setter SetFromEnv() (so that may be ytt when imported as library never interacts with it).
  • [nit] rename features to experiments to make terminology more consistent with env var

for example:

experiments.go

var (
  schemaValidationEnabled = false
)
func LoadFromEnv() {
  // do stuff with os.Getenv("YTTEXPERIMENTS")
  // ... schemaValidationEnabled = true
}
func IsSchemaValidationEnabled() bool { return schemaValidationEnabled }

code uses experiments.IsSchemaValidationEnabled()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[nit] rename features to experiments to make terminology more consistent with env var

Totally agree. AND to not risk confusion with actual feature flags (e.g. --data-values-validation.

...

(so that may be ytt when imported as library never interacts with it).

I was aiming to include those who are programmatically integrating — which motivated exporting Flagset.Enable().
I guess technically, they could also call experiements.EnableFromEnv() if they wanted to... which would just be a more complicated form of the same thing?

... ah, no, I see... since the environment variable would be essentially constant, it approximates what we're going for: a stable value.

Oh, I'm liking this. Because in tests, we can change that value, as desired. ... but in a typical execution environment, it's almost likely static.

Gonna try this out and see.

@pivotaljohn pivotaljohn force-pushed the add-experiments-flag branch from 88a9713 to 2e928a0 Compare May 9, 2022 21:12
@pivotaljohn pivotaljohn force-pushed the add-experiments-flag branch from 2e928a0 to d739fcc Compare May 9, 2022 22:16
- rename package from "feature" to "experiments"
- report enabled experiments in "version" command output
@cppforlife cppforlife merged commit ded5312 into develop May 11, 2022
@pivotaljohn pivotaljohn deleted the add-experiments-flag branch May 11, 2022 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants