Interface MeterConfigurations
- All Known Implementing Classes:
MeterConfigurationsImpl
This interface allows adding configurations for specific meter key prefixes and evaluating configurations for given meter keys. The configurations can be applied to meters based on their key prefixes.
Seecreate(Consumer) for creating a new instance of MeterConfigurations.- Since:
- 5.0.0
-
Method Summary
Modifier and TypeMethodDescriptionaddMeterConfig(String prefixMatcher, Consumer<MeterConfigBuilder> meterConfig) Adds a configuration for a specific meter key prefix.static MeterConfigurationscreate(Consumer<ProductMeterConfigBuilder> defaultConfig) Creates a new instance of MeterConfigurations with the provided default configuration.voidevaluateConfig(MeterKey meterKey, ProductMeterConfigBuilder configBuilder) Evaluates the configuration for the given MeterKey and applies it to the provided ProductMeterConfigBuilder.
-
Method Details
-
addMeterConfig
Adds a configuration for a specific meter key prefix. The key prefix must be made of full meter segments it wants to match. Matching prefix as `String.startsWith()` is not supported.For example, a meter "issue.created" will apply configurations with prefix "issue" and "issue.created". However, it won't apply configuration with prefix "iss". Such configuration would apply to meters like "iss" and "iss.created".
The configuration is applied to all meters whose key starts with the provided prefix. The configuration is applied after the default configuration.
Configuration added with prefix "" (empty string) will apply to all meters.
Important Note: The configuration is applied only on meter creation. Changing the configuration after the meter is created will not affect the meter. It is recommended to declare all configurations before creating any meters, otherwise meters may not have the expected configuration.- Parameters:
prefixMatcher- the prefix of the meter key to matchmeterConfig- the configuration that will be applied to meters with keys matching the prefix- Returns:
- this MeterConfigurations instance
-
evaluateConfig
Evaluates the configuration for the given MeterKey and applies it to the provided ProductMeterConfigBuilder. The default configuration is applied first, followed by any specific configurations that match the MeterKey.This method applies configurations for each segment of the meter key, starting from the most generic to the most specific. For example, if the meter key is "issue.created" and there are configurations for "issue" and "issue.created", the configuration for "issue" will be applied first, followed by the configuration for "issue.created".
- Parameters:
meterKey- the key of the meter to evaluate the configuration forconfigBuilder- the builder to apply the configuration to
-
create
Creates a new instance of MeterConfigurations with the provided default configuration.- Parameters:
defaultConfig- the default configuration to apply to all meter configurations. The defaultConfig is always applied first, followed by any specific configurations that match the MeterKey.- Returns:
- a new instance of MeterConfigurations
-