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

Switch for disabling validation #667

Merged
merged 6 commits into from
Jan 5, 2021
Merged

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented Jan 4, 2021

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:

  • added switch to disable package validation
  • refactored Validate() methods to become idempotent

Unit tests are passing.

@mtojek mtojek requested a review from ruflin January 4, 2021 13:32
@mtojek mtojek self-assigned this Jan 4, 2021
@elasticmachine
Copy link

elasticmachine commented Jan 4, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #667 updated

  • Start Time: 2021-01-04T14:15:00.106+0000

  • Duration: 7 min 12 sec

Test stats 🧪

Test Results
Failed 0
Passed 169
Skipped 0
Total 169

Copy link
Member

@ruflin ruflin left a 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.

@mtojek mtojek changed the title Switch for enabling validation Switch for disabling validation Jan 4, 2021
@mtojek
Copy link
Contributor Author

mtojek commented Jan 4, 2021

I think we can go this way too, might be more intuitive and backwards compatible. I adjusted the PR and it's description.

@mtojek mtojek requested a review from ruflin January 4, 2021 14:16
Copy link
Member

@ruflin ruflin left a 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")
Copy link
Member

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.

Copy link
Contributor Author

@mtojek mtojek Jan 4, 2021

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 == "" {
Copy link
Member

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.

Copy link
Contributor Author

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:

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, ","))
}
? If so, then we should come back here and refactor, as the DataStream.IngestPipeline is marked as deprecated.

I suppose we can strip this part of at all, unless there is Kibana logic using it.

Copy link
Member

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.

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, 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.

Copy link
Member

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 😆

@mtojek mtojek merged commit 6d3de3a into elastic:master Jan 5, 2021
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.

3 participants