Skip to content

Conversation

breskeby
Copy link
Contributor

@breskeby breskeby commented Aug 22, 2025

  • We want to avoid project.allprojects as sooner or later this will start breaking
  • Implementing Verification task in the transport validation tasks
    • Allows better filtering for verification vs. other build failures.
      e.g. in Develocity Failures Overview
  • Use project.layout.settingsDirectory instead of project.rootProject.projectDir
    • Avoiding accessing other projects properties

@breskeby breskeby requested a review from a team as a code owner August 22, 2025 20:41
@breskeby breskeby added >non-issue :Delivery/Build Build or test infrastructure Team:Delivery Meta label for Delivery team auto-backport Automatically create backport pull requests when merged v9.2.0 v8.17.11 v8.18.6 v8.19.3 v9.1.4 v9.0.7 labels Aug 22, 2025
@breskeby breskeby self-assigned this Aug 22, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

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.

A couple questions about the subscriber setup


public abstract class ProjectSubscribeBuildService implements BuildService<BuildServiceParameters.None> {

public static final String TRANSPORT_REFERENCES_TOPIC = "transportReferences";
Copy link
Member

Choose a reason for hiding this comment

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

nit: since this class should be generic, could this topic string be moved into the transport version classes, perhaps in TransportVersionResourcesPlugin?

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

private Map<String, Collection<String>> versionsByTopic = new HashMap<>();

public Collection<String> getProjectsByTopic(String topic) {
return versionsByTopic.get(topic);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a javadoc explaining the expectation of the returned collection? It appears it's supposed to be live, right?

Separately, I think this also needs to be a computeIfAbsent. Otherwise if getProjectsByTopic is called before any register, it will return null rather than an empty list that will be updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, "live" isn't really the write term here. We are just returning a mutable collection, which seems wrong. To me I think it would make sense to return a Provider which wraps and immutable collection representing that registered projects at the time whenever you call get().

I also think we should standardize on using Provider-based APIs pretty much anytime we have "lazy" stuff like this, or when we want to make it obvious that eagerly resolving this might (a) have performance impacts or (b) might give you incomplete results.

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

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

c.setCanBeConsumed(false);
c.setCanBeResolved(true);
c.attributes(TransportVersionReference::addArtifactAttribute);
c.defaultDependencies(t -> {
Copy link
Member

Choose a reason for hiding this comment

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

When will this be called relative to other projects? Can there not be projects added later?

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 will be called when the configuration is resolved. usually thats part of the taskgraph calculation when using configuration cache or even later when evaluating inputs of the task required.
At this point all projects should be evaluated.

At one point we want to support only partial gradle configuration so we don't need to reevaluate the world when just triggering subprojects. then we probably need an approach to handle those scenario. but we and gradle is not there yet

Copy link
Contributor

@mark-vieira mark-vieira Aug 26, 2025

Choose a reason for hiding this comment

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

As I mentioned above, I think if we make ProjectSubscribeBuildService a Provider-based API this becomes a lot less confusing. You can then just use DependencyHandler.addProvider and use .map() to have it be providers all the way down. IMO calling get() anywhere in configuration logic is a smell. It means we're relying on some kind of implicit deferral to happen or we're forced to awkwardly integrate with another non-Provider API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory thats nice and the way to go. unfortunately (again) the provider based interfaces in Gradle often break that by themself. In this case we have a Provider<Collection> but DependencyHandler.addProvider only takes a Provider<String> representing a dependencyNotation. To have that working nicely we would need DependencyHandler.addProvider(String, Collection<Object>). Alternatively we return a Collection<Provider<String>> :/

We still can be good citizens but we're limited by the reality that the provider api in Gradle is lacking proper coverage in certain places.

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 found a different api by now that is closer to idomatic provider usage

var tvReferencesConfig = project.getConfigurations().create("globalTvReferences", c -> {
            c.setCanBeConsumed(false);
            c.setCanBeResolved(true);
            c.attributes(TransportVersionReference::addArtifactAttribute);
            c.getDependencies()
                .addAllLater(
                    psService.flatMap(t -> t.getProjectsByTopic(TRANSPORT_REFERENCES_TOPIC))
                        .map(projectPaths -> projectPaths.stream().map(path -> depsHandler.project(Map.of("path", path))).toList())
                );
        });

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

*/
@CacheableTask
public abstract class ValidateTransportVersionResourcesTask extends DefaultTask {
public abstract class ValidateTransportVersionResourcesTask extends DefaultTask implements VerificationTask {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we throwing error messages that align with this expecation? My understanding was that Develocity also requires the failure message to match a certain pattern. See https://docs.gradle.com/develocity/failure-classification/

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 catch! I was too naive here thinking using the task interface is enough. I'll have a quick look 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.

I fixed the throwing exceptions here

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties
@breskeby breskeby force-pushed the gradle-transport-polishing branch from 54b1a8c to 86fc83b Compare August 27, 2025 08:21
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.

LGTM

* The values are LinkedHashSet to preserve the order of registration mostly to provide a predicatable order
* when running consecutive builds.
* */
private Map<String, Collection<String>> versionsByTopic = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

nit: this can be final

@breskeby breskeby removed the v8.17.11 label Aug 28, 2025
@breskeby breskeby merged commit fa531c9 into elastic:main Aug 28, 2025
33 of 34 checks passed
breskeby added a commit to breskeby/elasticsearch that referenced this pull request Aug 28, 2025
* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
breskeby added a commit to breskeby/elasticsearch that referenced this pull request Aug 28, 2025
* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
breskeby added a commit to breskeby/elasticsearch that referenced this pull request Aug 28, 2025
* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
breskeby added a commit to breskeby/elasticsearch that referenced this pull request Aug 28, 2025
* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.1
9.0
8.18
8.19

elasticsearchmachine pushed a commit that referenced this pull request Aug 28, 2025
)

* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
elasticsearchmachine pushed a commit that referenced this pull request Aug 28, 2025
)

* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
elasticsearchmachine pushed a commit that referenced this pull request Aug 28, 2025
)

* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
elasticsearchmachine pushed a commit that referenced this pull request Aug 29, 2025
)

* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
sarog pushed a commit to portsbuild/elasticsearch that referenced this pull request Sep 11, 2025
elastic#133695)

* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
sarog pushed a commit to portsbuild/elasticsearch that referenced this pull request Sep 19, 2025
elastic#133695)

* [Gradle] Some tweaks to transport related build logic

- We want to avoid project.allprojects
- Implementing Verification task in the transport validation tasks
  - Allows better filtering for verification vs. other build failures.
    e.g. in Develocity Failures Overview
- Use project.layout.settingsDirectory instead of project.rootProject.projectDir
  - Avoiding accessing other projects properties

* Address some review feedback

* Rework mapping project path list to dependencies

* Some more review feedback

* Minor tweak after review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Delivery/Build Build or test infrastructure >non-issue Team:Delivery Meta label for Delivery team v8.18.7 v8.19.4 v9.0.7 v9.1.4 v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants