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

Validate ingest pipelines while packaging #426

Merged
merged 4 commits into from
May 4, 2020

Conversation

mtojek
Copy link
Contributor

@mtojek mtojek commented May 4, 2020

Changes:

  • validate ingest pipelines while packaging

Issue: #404

@mtojek mtojek requested a review from ruflin May 4, 2020 11:58
@mtojek mtojek self-assigned this May 4, 2020
Copy link
Contributor

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

Could you add a line to the changelog?

_, errYAML := os.Stat(yamlPipelinePath)

var validFound bool
if !os.IsNotExist(errJSON) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Why not put the checks for each error directly after where the error happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

util/dataset.go Outdated
if err != nil {
return errors.Wrapf(err, "reading ingest pipeline file failed")
}
ext := pipelinePath[strings.LastIndex(pipelinePath, ".")+1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

filepath.Ext?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed

util/dataset.go Outdated
func validateIngestPipelineFile(pipelinePath string) error {
f, err := ioutil.ReadFile(pipelinePath)
if err != nil {
return errors.Wrapf(err, "reading ingest pipeline file failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have the path reported as part of the error which makes it much easier to find which file did not parse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@mtojek mtojek requested a review from ruflin May 4, 2020 12:16
Copy link
Contributor

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

Approving as code is correct. Changelog still missing ;-)

util/dataset.go Outdated
_, errJSON := os.Stat(jsonPipelinePath)
if errJSON != nil && !os.IsNotExist(errJSON) {
return errors.Wrapf(errJSON, "stat ingest pipeline JSON file failed (path: %s)", jsonPipelinePath)
} else if !os.IsNotExist(errJSON) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need an else here as if it matches before, it will return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

util/dataset.go Outdated
err = validateIngestPipelineFile(jsonPipelinePath)
if err != nil {
return errors.Wrapf(err, "validating ingest pipeline JSON file failed (path: %s)", jsonPipelinePath)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

no else needed as it returns on 167

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

is it? :-D Perhaps I'm commenting too early ;-)

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 was looking on the other if-else struct. Now, it's truly fixed :D

@mtojek
Copy link
Contributor Author

mtojek commented May 4, 2020

Changelog still missing ;-)

My bad, forgot about it. Sorry!

@mtojek mtojek merged commit 3fc5198 into elastic:master May 4, 2020
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.

2 participants