-
Notifications
You must be signed in to change notification settings - Fork 86
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
Operator refactor - validation and import cleanup #1356
Operator refactor - validation and import cleanup #1356
Conversation
…ion, remove validation sections from operator runtime methods where possible.
/assign @timflannagan1 |
pkg/operator/operator.go
Outdated
log "github.com/sirupsen/logrus" | ||
"github.com/taozle/go-hive-driver" | ||
"github.com/kube-reporting/metering-operator/pkg/db" | ||
cbClientset "github.com/kube-reporting/metering-operator/pkg/generated/clientset/versioned" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're tackling this kind of work now, I would expect to also rename this import and all of its occurrences too, to something like meteringClientset
or anything that doesn't involve the old "chargeback" name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're tackling this kind of work now
We don't have to merge this now, I think it should be no-op so it shouldn't be too risky but bugs first and we can merge these when master opens if that't the right thing to do.
I would expect to also rename this import and all of its occurrences too, to something like
meteringClientset
or anything that doesn't involve the old "chargeback" name.
Easy enough, I'll add a new commit for this refactor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can take a better look tomorrow when my brain is probably fresher, but I think this is awesome so far. A lot of this part of the codebase has been somewhat neglected for a while now and could use some general maintenance work.
Something else that I would like to tackle, but is probably out of the scope of this kind of work, is improving (or adding) comments to types/methods/functions to the various reporting-operator components, like what does |
errs := IsValidConfig(&cfg) | ||
if errs != nil { | ||
return nil, errs | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Building off my comment from above, I wonder if we should be doing all of the reporting configuration validation in the cmd/reporting-operator driver function that provides the entry point for this operator, rather than in the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be called from the cmd
package but it should not be done there. Commands in Kube/OpenShift follow a pattern of Complete
, Validate
, Run
. We should refactor ours to match and call the IsValidConfig
method in the command's Validate
method. However we should keep it in new as well to protect against programmatic access to the operator no matter how it's started in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example of the recommended pattern: https://github.com/openshift/oc/blob/a695d74ef1aee9a3f605d38dd8b6fae2062b63fc/pkg/cli/tag/tag.go#L93-L116
this is 100% a goal here. Anything we touch in a refactor should get comments IMO, hence the API comments. |
Some other observations for the discussion (perhaps this PR, perhaps future)
|
|
|
/retest |
2 similar comments
/retest |
/retest |
Removing WIP from this - it's probably big enough that we shouldn't add anything else too it yet if we want to merge. I am going to call out a few pieces (in review comments) that I think we need to be aware of though before we merge. |
/retest |
// TODO this requires a port to be specified, is that one of our requirements? | ||
func isValidHostPort(hp string, name string) error { | ||
if len(hp) > 0 { | ||
if _, _, err := net.SplitHostPort(hp); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will fail if a port is not given - can someone confirm that that is a correct behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets called on api, metrics, pprof, presto, hive
I think it's valid to make the admin config the port for our API.
Metrics = Prom, has a default, might be ok to not spec.
pprof seems like it has a default port as well, so maybe okay to not spec.
Presto has a default port, might be ok to not spec.
Hive has a default thrift service port as well, so maybe that might not need being requeired to specify either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will remove the calls/tests for apis that have default ports.
// PrometheusDataSourceMaxBackfillImportDuration overrides PrometheusDataSourceGlobalImportFromTime | ||
// don't set both. | ||
if cfg.PrometheusDataSourceGlobalImportFromTime != nil && cfg.PrometheusDataSourceMaxBackfillImportDuration > 0 { | ||
errs = append(errs, fmt.Errorf("prometheusDataSourceGlobalImportFromTime and prometheusDataSourceMaxBackfillImportDuration cannot both be set")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously we stated that one overrides the other. Introducing this will cause explicit failure. Acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure where I land on this validation check. I think it sounds reasonable looking at the codebase and making sure we reject configurations that won't be respected. @bentito any opinion on this validation check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bentito - thoughts on this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading the usage in start.go
, it seems like this validates the stated usage. If it's Prom import question, they're both just ways of getting at how far back to try to grab Prom data when metering somehow gets out of sync. I think PrometheusDataSourceGlobalImportFromTime
has more potential to be pretty awful for cluster workload, but I don't think that's being asked here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just validation of input. Sounds like I can leave it. Thanks
|
||
errs = append(errs, isValidHostPort(cfg.HiveHost, "hiveHost")) | ||
|
||
if !cfg.HiveUseTLS { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously we allowed config to be set even if this was set to false. Should we continue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as my comment below. I think this is fine UX, reject any configurations like this if you're disabling TLS on the reporting-operator side for that component.
|
||
errs = append(errs, isValidHostPort(cfg.PrestoHost, "prestoHost")) | ||
|
||
if !cfg.PrestoUseTLS { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously we allowed config to be set even if this was set to false. Should we continue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would imagine that makes sense, i.e. rejecting a configuration where you explicitly set TLS-related flags yet disable TLS entirely for the reporting-operator -> presto communications.
/retest |
@bentito @timflannagan1 updates from the review in the last commit. Thanks. |
/retest |
5 similar comments
/retest |
/retest |
/retest |
/retest |
/retest |
@timflannagan1 all review comments from @bentito have been addressed (left the Unless there is anything else I think this can merge. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pweil-, timflannagan1 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
🎉 |
Round 1 - go!
Let's see what clean up we can do here @timflannagan1.
This has the following commits that can be reviewed independently
New
,newOperator
, andRun
methods and consolidate on a single validation call to ensure the config is good duringNew
. No good config == no operator to run. Bonus: Add tests for all validationsThere are a couple questions sprinkled in where things weren't obvious.