Skip to content

Discover additional flag definitions via ServiceLoader SPI#36603

Closed
esolitos wants to merge 1 commit intomasterfrom
flag-definitions-spi
Closed

Discover additional flag definitions via ServiceLoader SPI#36603
esolitos wants to merge 1 commit intomasterfrom
flag-definitions-spi

Conversation

@esolitos
Copy link
Copy Markdown
Contributor

@esolitos esolitos commented Apr 29, 2026

What

Add a FlagDefinitions service-provider interface (single register()
method). Flags.<clinit> and PermanentFlags.<clinit> discover
implementations via java.util.ServiceLoader and invoke register()
once per JVM, after the static flag map is initialized. Existing flag
definitions are untouched.

Why

  • Lets other bundles on the classpath contribute flag definitions without
    modifying this one.
  • Keeps consumer-specific metadata (owners, expiry dates, rollout notes)
    out of this generic bundle.
  • Purely additive: no new compile-time or runtime edge from this bundle
    to any other artifact, and no behavior change for flags currently
    defined here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a ServiceLoader-based extension point so external artifacts on the classpath can contribute additional flag definitions to the central Flags registry, with tests verifying discovery and interaction with Flags.Replacer.

Changes:

  • Introduce FlagDefinitions SPI (single register() method) for out-of-bundle flag registration.
  • Load and invoke FlagDefinitions providers during Flags class initialization (and trigger from PermanentFlags).
  • Add test-only SPI implementation + ServiceLoader registration and regression tests for visibility and Flags.Replacer behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
flags/src/main/java/com/yahoo/vespa/flags/FlagDefinitions.java Adds the SPI contract for registering external flag definitions.
flags/src/main/java/com/yahoo/vespa/flags/Flags.java Loads FlagDefinitions via ServiceLoader once and runs providers during static init.
flags/src/main/java/com/yahoo/vespa/flags/PermanentFlags.java Calls into Flags to ensure SPI loading when PermanentFlags is initialized.
flags/src/test/resources/META-INF/services/com.yahoo.vespa.flags.FlagDefinitions Registers the test SPI implementation on the test classpath.
flags/src/test/java/com/yahoo/vespa/flags/TestFlagDefinitions.java Test-only FlagDefinitions provider that registers sample flags.
flags/src/test/java/com/yahoo/vespa/flags/FlagDefinitionsSpiTest.java Verifies ServiceLoader discovery and SPI-registered flags are visible; checks no double-registration.
flags/src/test/java/com/yahoo/vespa/flags/FlagsReplacerSpiRegressionTest.java Regression tests ensuring Flags.Replacer saves/restores SPI-registered flags correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread flags/src/main/java/com/yahoo/vespa/flags/Flags.java Outdated
Comment thread flags/src/main/java/com/yahoo/vespa/flags/FlagDefinitions.java Outdated
Comment thread flags/src/main/java/com/yahoo/vespa/flags/PermanentFlags.java Outdated
Comment thread flags/src/test/java/com/yahoo/vespa/flags/TestFlagDefinitions.java
Add a FlagDefinitions service-provider interface so downstream artifacts
can register flags into Flags/PermanentFlags without depending on this
bundle at compile time. Flags.<clinit> (and, defensively, PermanentFlags.
<clinit>) load implementations via java.util.ServiceLoader and invoke
register() at most once per JVM, after the static flag map and all
in-bundle flag fields are initialized.
@esolitos esolitos force-pushed the flag-definitions-spi branch from f563d64 to a077281 Compare April 30, 2026 05:59
@esolitos
Copy link
Copy Markdown
Contributor Author

As discussed, let's find another way.

@esolitos esolitos closed this Apr 30, 2026
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