Skip to content

Conversation

@jakelandis
Copy link
Contributor

@jakelandis jakelandis commented Sep 28, 2020

This commit introduces a plugin to run REST compatibility tests.
The plugin is not currently applied to any projects with this commit,
but it establishes the foundation for testing REST compatibility.

This plugin will be applied to all core, plugin, and module projects
that currently have YAML based REST tests. This plugin, when applied
will do the following:

  • Create a new sourceset that extends from the yamlRestTest sourceset
  • Ensure the default distribution is used to execute the tests
  • Checkout bwc:minor version of the source code
  • Copy the rest api and rest tests from bwc:minor to the new sourceset
  • Create the test task, but manipulate the classpath so it uses the
    "normal" YAML test runner, but the "compat" set of tests
  • wire up dependencies, ide, and check

The implementation here depends on :distribution:bwc:minor:checkoutBwcBranch
which is a convenient way to git checkout the most recent prior branch.
This approach works but is a bit fragile and long term would like a more
robust way to checkout arbitrary prior branches. This would be a fairly large
effort and is not included in this commit.

Also not included in this commit is the code necessary to inject the
compatible header, any customization to running the compatibility tests,
or any of the logic to override specific tests. Future commits will address
those concerns.

@jakelandis jakelandis marked this pull request as ready for review September 29, 2020 13:42
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Build)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Sep 29, 2020
final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);
String sourceSetName;
boolean skipHasRestTestCheck;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed so that you can run compat tests for a project that may no longer have YAML REST tests in master. Also, there may be cases where a module is completely deleted in master, but we will still want to use this plugin to only test compatibility.

This basically ensures that the execution of "compat" YAML tests is not directly coupled to the existence of "normal" YAML rest tests.

boolean skipHasRestTestCheck;
Configuration coreConfig;
Configuration xpackConfig;
Configuration additionalConfig;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed as a way to copy the 7.x module/plugin tests to the source set. For "normal" YAML tests they are already in the source set (since they are part of the current source code).

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

We seem to be only testing against the previous minor, but shouldn't we create bwc test tasks for comparing against all compatible versions?

.getBuildDir()
.toPath()
.resolve("bwc")
.resolve("checkout-" + priorMajorVersion + ".x");
Copy link
Member

Choose a reason for hiding this comment

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

Why are we peeking at the source? Instead can we produce the files as an artifact? This would allow us to test against already released versions in the same way, just grab the zip of the spec/test files of that released version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The artifacts we produce only contain the OSS core api and tests. I need the x-pack core api/tests as well as all of the OSS/X-pack module/plugin API/tests. Back filling those I think is a reasonable approach as a long term solution, but I think sourcing like this is decent temporary approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @rjernst that peeking into other source folders is kind of an anti pattern. Instead sharing it declaratively as described here: https://docs.gradle.org/current/userguide/cross_project_publications.html is what we should aim for.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally I think the bwc project would just share the checkoutDir as an artifact. Can you put a TODO in there to look into this after #62473 I will then pick that up at one. point. This PR does quite some rework on the bwc setup

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, exposing the checkoutDir as an artifact, I think will clean this up. I added a TODO in the code to come back to this.

@jakelandis
Copy link
Contributor Author

We seem to be only testing against the previous minor, but shouldn't we create bwc test tasks for comparing against all compatible versions?

Yes, testing against all prior minor versions is the long term goal. This PR is satisfies the short term goal that will allow the bare min. needed to start testing compatibility. I am presuming that testing compatibility against the latest minor should be part of the project's check task, and testing against all branches would be a new lifecycle task (similar to bwc).

To satisfy the long term goal (and introduce a new lifecycle task to test all prior minors) we will need a way to checkout an arbitrary branch/tag or publish artifacts for ALL of the rest tests for each minor version (the existing artifacts only contain the OSS api/tests). This will need further discussion, but hoping that this approach is sufficient as a starting point.

Copy link
Contributor

@breskeby breskeby left a comment

Choose a reason for hiding this comment

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

I left some remarks regarding resolving and sharing artefacts among projects similar to what @rjernst commented and added a remark about avoiding project.copy{} at execution time. We probably want to tackle this sharing resources as artifacts in a separate story and not as part of this PR. If not we should at least create a ticket for this problem

.getBuildDir()
.toPath()
.resolve("bwc")
.resolve("checkout-" + priorMajorVersion + ".x");
Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @rjernst that peeking into other source folders is kind of an anti pattern. Instead sharing it declaratively as described here: https://docs.gradle.org/current/userguide/cross_project_publications.html is what we should aim for.

// always copy the core specs if the task executes
if (BuildParams.isInternal()) {
getLogger().debug("Rest specs for project [{}] will be copied to the test resources.", project.getPath());
project.copy(c -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd like to get away from using the project property within task actions. I'm currently working on #62968 Instead using project.copy{} we should inject a FileSystemOperations service and use that one for these kind of operations. See for example the LoggedExec task how this service is injected: https://github.com/elastic/elasticsearch/pull/62968/files#diff-babd4b74d83a9cea8bf0823cf6b71b66

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 added some TODO's for the new project.copy's to ensure it uses the newer style once that PR lands. I didn't make the change now to avoid avoid copy/paste code from your PR (which could merge clash). If this PR beats yours then feel free to add it to your, else I will circle back to this.

}
// copy any additional config
if (additionalConfig != null) {
project.copy(c -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

.getBuildDir()
.toPath()
.resolve("bwc")
.resolve("checkout-" + priorMajorVersion + ".x");
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally I think the bwc project would just share the checkoutDir as an artifact. Can you put a TODO in there to look into this after #62473 I will then pick that up at one. point. This PR does quite some rework on the bwc setup

project.getDependencies()
.add(
task.coreConfig.getName(),
project.files(checkoutDir.resolve("rest-api-spec/src/main/resources").resolve(RELATIVE_API_PATH))
Copy link
Contributor

Choose a reason for hiding this comment

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

same here. We should not rely on file dependencies and provide these dependencies as artifacts of the bwc project.

@jakelandis
Copy link
Contributor Author

Add some more TODO's to revisit after Rene's PRs land as well as to test multiple versions using published artifacts as discussed.

@jakelandis jakelandis merged commit f56bf94 into elastic:master Sep 30, 2020
@jakelandis jakelandis deleted the rest_compat_test branch September 30, 2020 22:09
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Sep 30, 2020
This commit introduces a plugin to run REST compatibility tests.
The plugin is not currently applied to any projects with this commit, 
but it establishes the foundation for testing REST compatibility. 

This plugin will be applied to all core, plugin, and module projects 
that currently have YAML based REST tests. This plugin, when applied
will do the following:

* Create a new sourceset that extends from the yamlRestTest sourceset
* Ensure the default distribution is used to execute the tests
* Checkout bwc:minor version of the source code
* Copy the rest api and rest tests from bwc:minor to the new sourceset
* Create the test task, but manipulate the classpath so it uses the 
  "normal" YAML test runner, but the "compat" set of tests
* wire up dependencies, ide, and check

The implementation here depends on :distribution:bwc:minor:checkoutBwcBranch
which is a convenient way to git checkout the most recent prior branch. 
This approach works but is a bit fragile and long term would like a more 
robust way to checkout arbitrary prior branches. This would be a fairly large
effort and is not included in this commit. 

Also not included in this commit is the code necessary to inject the
compatible header, any customization to running the compatibility tests, 
or any of the logic to override specific tests. Future commits will address
those concerns.
jakelandis added a commit that referenced this pull request Oct 1, 2020
Backport for #62985 that includes the related changes, but 
not the actual plugin for yamlRestCompatTest. The plugin 
is not necessary in 7.x, and back porting relevant changes to
help keep 7.x code inline with master.
@mark-vieira mark-vieira added Team:Delivery Meta label for Delivery team and removed Team:Core/Infra Meta label for core/infra team labels Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Delivery/Build Build or test infrastructure >non-issue Team:Delivery Meta label for Delivery team v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants