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

Modify generator to get version to generate passed #5352

Merged
merged 3 commits into from
Oct 13, 2017

Conversation

ruflin
Copy link
Contributor

@ruflin ruflin commented Oct 6, 2017

Having the version passed from external makes the generator more reusable and cleans up the internal code.

  • Modify internal dashboard version to common.Version

This is a prerequisit for #5328 and will make the change less complex.

@ruflin
Copy link
Contributor Author

ruflin commented Oct 6, 2017

@simitt I think we should merge #5329 before this one as I want to add some more things to this PR which depends on methods you introduced in your PR.

@ruflin ruflin force-pushed the kibana-versioning branch from a344306 to eef6504 Compare October 11, 2017 13:20
@ruflin ruflin changed the title Modify internal dashboard version to common.Version Modify generator to get version to generate passed Oct 11, 2017
Having the version passed from external makes the generator more reusable and cleans up the internal code.

* Modify internal dashboard version to common.Version

This is a prerequisit for elastic#5328 and will make the change less complex.
@ruflin ruflin force-pushed the kibana-versioning branch from eef6504 to a93fda1 Compare October 12, 2017 08:28
if i.version.Major == 5 {
path, err = i.generate5x(commonFields)
} else {
path, err = i.generate6x(commonFields)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the version is now passed in I think we should also rename generate5x and generate6x in something more generic, like

if i.version.Major >= 6 {
  path, err = i.generateMinVersion6(commonFields)
} else if i.version.Major >= 5 {
  path, err = i.generateMinVersion5(commonFields)
} else {
  return errors.New("version unsupported..")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

if err != nil {
return nil, err
return "", err
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you already define the path veriable upfront you could return path, err without an explicit check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, changed

@@ -65,7 +67,7 @@ func (i *IndexPatternGenerator) generate5x(fields common.Fields) (string, error)
return "", err
}

file5x := filepath.Join(i.targetDir5x, i.targetFilename)
file5x := filepath.Join(i.targetDir, i.targetFilename)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove line 64:

version, _ := common.NewVersion("5.0.0")

Rather use the given version, otherwise you don't really use the provided version from outside for fetching versionized information from the fields.

When generalizing this, the generate5x and generate6x methods have more overlap and might be a bit restructured.

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 definitively agree on this one and think the methods should probably be merge in the long run. But I suggest to do this in a follow up PR to not have too many changes in here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree on doing the method cleanup in a next version.
Not passing in the version here but hardcoding it, I consider to be a bug though, e.g. one could pass in 7.0.0 which might have differences in the fields.yml to 6.0.0 but would still get the values for 6.0.0 with this handling.

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 changed it to i.version. I agree with 7.0 it would not be the expected behaviour but this is not a "bug" that was introduced here but already in the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

The difference is that so far no version was given from the outside, but it was hardcoded inside the generator. Thus it was clear that it gets generated for those two defined versions.

This PR adds the possibility to pass in a version. The "bug" I was referring to would be to not use this version then in all places.

for _, p := range pattern {
fmt.Fprintf(os.Stdout, "-- The index pattern was created under %v\n", p)
version5, _ := common.NewVersion("5.0.0")
version6, _ := common.NewVersion("6.0.0")
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 6.0.0 already or rather be 6.0.0-rc1?
As you mentioned in the former PR that we should take the meta information of versions into account, and there are breaking changes between pre-releases, the generator now treats 6.0.0.rc1 < 6.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we don't pass the version in I would stick with 6.0.0 as I don't think this is a field we should change over time with each release. Hopefully we can get rid of it completely in the long run as index pattern could be generated on request now that we have it in Golang so we would not have to pregenerate them.

@ruflin
Copy link
Contributor Author

ruflin commented Oct 13, 2017

@simitt Thanks for the review. There are quite a few things I want further clean up in this code but I prefer to do it in multiple smaller PR's which makes spotting problems easier. This PR was mainly an extraction of some code from #5328 to make that PR smaller.

if i.version.Major >= 6 {
path, err = i.genereteMinVersion6(commonFields)
} else {
path, err = i.genereteMinVersion5(commonFields)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a typo: generate instead of generete.

@@ -65,7 +67,7 @@ func (i *IndexPatternGenerator) generate5x(fields common.Fields) (string, error)
return "", err
}

file5x := filepath.Join(i.targetDir5x, i.targetFilename)
file5x := filepath.Join(i.targetDir, i.targetFilename)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree on doing the method cleanup in a next version.
Not passing in the version here but hardcoding it, I consider to be a bug though, e.g. one could pass in 7.0.0 which might have differences in the fields.yml to 6.0.0 but would still get the values for 6.0.0 with this handling.

@ruflin ruflin force-pushed the kibana-versioning branch from 5970a46 to cae4a3f Compare October 13, 2017 08:57
Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

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

Thanks for updating, this PR is great since it allows more flexibility in the future.

@simitt simitt merged commit 01a9e43 into elastic:master Oct 13, 2017
dir = path.Join(dir, imp.version)
versionPath := "default"
if imp.version.Major == 5 {
versionPath = "5x"
Copy link
Contributor

Choose a reason for hiding this comment

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

@ruflin For when you are back from vacation, I think this should be 5.x instead of 5x. I'm going to make it 5.x in a PR, but let me know if it was 5x on purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was definitively a typo.

tsg added a commit to tsg/beats that referenced this pull request Nov 2, 2017
It was changed to '5x', I think by mistake, in elastic#5352.
kvch pushed a commit that referenced this pull request Nov 2, 2017
It was changed to '5x', I think by mistake, in #5352.
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.

3 participants