question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programmatically configure `Flags` via SPI

See original GitHub issue

The default value of some Flags could be changed by only JVM -Dcom.linecorp.armeria.XXX option such as -Dcom.linecorp.armeria.verboseSocketExceptions=true. New options are constantly added to Flags according to various requirements and environments. Consequently, users find it difficult to override many options only via JVM options. They may not want to frequently fix the options in their CI/CD tools.

If we provide an SPI interface and let users programmatically override the default value by implementing a configuration interface. Users can take advantage of the benefits of reviewing the properties in the PR and managing it in the source set.

The following priority could be applied to the new configuration mechanism.

  1. Give JVM options the highest priority.
  2. If a JVM option is not specified, checks the value in the configuration provided via SPI
  3. Neither is set, the sensible default defined in Flags will be used.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ikhooncommented, Mar 8, 2022

I want to use @ClearSystemProperty and @SetSystemProperty to set and clear system properties

System properties are loaded once when Flags is initialized. So @ClearSystemProperty and @SetSystemProperty do not effectively change the default values of Flags. We can use a custom class loader to re-evaluate the system properties. https://github.com/line/armeria/blob/4edffc8c11bd74665d652a1fd108d6a0307b6733/core/src/test/java/com/linecorp/armeria/common/FlagsTest.java#L92

There are 2 options in Flags that marked as deprecated( annotatedServiceExceptionVerbosity() and useEpoll() ). Should I still add them as part of the ArmeriaOptions SPI interface, or ignore them?

It is OK to exclude the deprecated flags from ArmeriaOptions.

1reaction
ikhooncommented, Mar 3, 2022

I was thinking of the first approach in order to easily override the default options. For example:

public interface ArmeriaOptions {
    default int numCommonBlockingTaskThreads() {
        return 0; //return default value
    }

    default long defaultMaxRequestLength() {
        return 2; //return default value
    }
    ...
}

//Users implementation
class CustomArmeriaOptions extends ArmeriaOptions {
    @Override
    public long defaultMaxRequestLength() {
        return 3;
    }
}

class Flag {
    // Dynamically load AmeriaOptions
    static final ArmeriaOptions ARMERIA_OPTIONS = ServiceLoader.load(...);
   
    private static final long DEFAULT_MAX_REQUEST_LENGTH =
            getLong("defaultMaxRequestLength",
                    armeriaOptions.defaultMaxRequestLength(),
                    value -> value >= 0);

    public static long defaultMaxRequestLength() {
        return DEFAULT_MAX_REQUEST_LENGTH;
    }
}

The API consistency between Flag and ArmeriaOptions can be ensured with a test using reflection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4.2. Programmatically Configure the Persistence SPI Red Hat Data ...
Configure the Single File Store via the Persistence SPI ... Programmatic configurations can only be used with Red Hat JBoss Data Grid's Library...
Read more >
SPI userspace API - The Linux Kernel documentation
SPI devices have a limited userspace API, supporting basic half-duplex read() and write() access to SPI slave devices. Using ioctl() requests, full duplex ......
Read more >
Class ConnectionFactories - R2DBC
This utility provides runtime discovery of R2DBC implementations that are available through the class path. A ConnectionFactory can be obtained in two ways:...
Read more >
STM32H7-Peripheral-Serial Peripheral interface (SPI)
peripheral's configuration. There are four I/O signals associated with the SPI peripheral. If required, the peripheral can keep control over the associated ...
Read more >
Creating Extensible Applications (The Java™ Tutorials > The ...
The SPI defines the classes and methods available to your application. Service Provider: Implements the SPI. An application with extensible services enable ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found