-
Notifications
You must be signed in to change notification settings - Fork 66
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
Switch for disabling validation #667
Conversation
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.
Should it be enabled or disabled by default? I wonder if we have less reported issues if we enable it by default. If disabled by default, the registry might have issues because packages are not valid.
Everyone just getting started with the registry and running it for some of the packages should have validation enabled. The only place we need to disable it is for the production environment because we know there, we already have validation in place.
That is why I would switch the defaults.
I think we can go this way too, might be more intuitive and backwards compatible. I adjusted the PR and it's description. |
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.
LGTM. This also cleans up the code around the validation which is great.
@@ -46,6 +46,7 @@ func init() { | |||
flag.StringVar(&address, "address", "localhost:8080", "Address of the package-registry service.") | |||
// This flag is experimental and might be removed in the future or renamed | |||
flag.BoolVar(&dryRun, "dry-run", false, "Runs a dry-run of the registry without starting the web service (experimental)") | |||
flag.BoolVar(&util.PackageValidationDisabled, "disable-package-validation", false, "Disable package content validation") |
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.
Quite a long name for a flag but no better suggestion.
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's one of these feature flags that you should be discouraged to use :)
|
||
if !d.validType() { | ||
return fmt.Errorf("type is not valid: %s", d.Type) | ||
return nil, err | ||
} | ||
|
||
if d.Elasticsearch != nil && d.Elasticsearch.IngestPipelineName == "" { |
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 is kind of a mix between validation and building the data model. I wonder if we should clean it up later or keep it as is. It would probably mean doing parts of it twice.
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 if I understand your concerns. Any code that modifies a package or a datastream is placed in constructors (e.g. NewDataStream
). Are you referring to this part of code:
package-registry/util/data_stream.go
Lines 161 to 183 in b20850d
if d.Elasticsearch != nil && d.Elasticsearch.IngestPipelineName == "" { | |
// Check that no ingest pipeline exists in the directory except default | |
for _, path := range paths { | |
if filepath.Base(path) == DefaultPipelineNameJSON || filepath.Base(path) == DefaultPipelineNameYAML { | |
d.Elasticsearch.IngestPipelineName = DefaultPipelineName | |
// TODO: remove because of legacy | |
d.IngestPipeline = DefaultPipelineName | |
break | |
} | |
} | |
// TODO: Remove, only here for legacy | |
} else if d.IngestPipeline == "" { | |
// Check that no ingest pipeline exists in the directory except default | |
for _, path := range paths { | |
if filepath.Base(path) == DefaultPipelineNameJSON || filepath.Base(path) == DefaultPipelineNameYAML { | |
d.IngestPipeline = DefaultPipelineName | |
break | |
} | |
} | |
} | |
if d.IngestPipeline == "" && len(paths) > 0 { | |
return nil, fmt.Errorf("unused pipelines in the package (dataset: %s): %s", d.Dataset, strings.Join(paths, ",")) | |
} |
DataStream.IngestPipeline
is marked as deprecated.
I suppose we can strip this part of at all, unless there is Kibana logic using it.
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.
What I initially assume could be an issue does not seem to be one after quickly checking the code. I was worried that for example the pipeline checks do not happen if only Validate
is run. But this is not the case as before validate is run, the constructor is used which runs all these additional checks always to build the actual package object. So all good.
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.
Yeah, I know the design is not really clear as we have to sneak the condition into the Validate
function, but I didn't see any Option
to disable validation at Unpack
.
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 think I know the person who built this initially and is to blame for the design 😆
Issue: #653
This PR introduces a switch for disabling package validation. In public image builds of package-storage the validation will be shifted from runtime to build time.
Changes:
Validate()
methods to become idempotentUnit tests are passing.