Configuring global flags

What flags in Armeria are

Flags are global variables that control the behavior of Armeria. These variables mostly serve one of the following two purposes:

  1. Overriding the default system values.
  2. Enhanced debugging or monitoring.

You can also override these properties by setting JVM system properties. For example:

  • -Dcom.linecorp.armeria.defaultRequestTimeoutMillis=<long>
  • -Dcom.linecorp.armeria.defaultMaxServerNumRequestsPerConnection=<integer>
  • -Dcom.linecorp.armeria.reportBlockedEventLoop=<boolean>
  • -Dcom.linecorp.armeria.verboseSocketExceptions=<boolean>

Implementing your own FlagsProvider

Create your own FlagsProvider and load it via Java SPI. If there are multiple implementations of FlagsProvider, the implementation with the highest priority will take precedence over the others.

MyFlagsProvider.java
package com.example.providers;

public class MyFlagsProvider implements FlagsProvider {

  @Override
  public int priority() {
    // The provider with higher value will be evaluated first.
    return 100;
  }

  @Override
  public Long defaultRequestTimeoutMillis() {
      return 5000L;
  }

  @Override
  public TransportType transportType() {
      return TransportType.EPOLL;
  }

  @Override
  public Boolean reportBlockedEventLoop() {
      return true;
  }

  @Override
  public Sampler<? super RequestContext> requestContextLeakDetectionSampler() {
      // Samples all request contexts.
      return Sampler.always();
  }

  @Override
  public MeterRegistry meterRegistry() {
      return PrometheusMeterRegistries.newRegistry();
  }

}

Add the following text file to your classpath or JAR file.

META-INF/services/com.linecorp.armeria.common.FlagsProvider
com.example.providers.MyFlagsProvider