Class PropertySource

java.lang.Object
io.prometheus.metrics.config.PropertySource

class PropertySource extends Object
PropertySource encapsulates three separate property maps with different priorities and transformation rules.

Properties are checked in the following order:

  1. External properties (highest priority) - exact key match
  2. Environment variables (second priority) - with dot-to-underscore transformation
  3. Regular properties (lowest priority) - from system properties, files, and classpath

Property lookups remove entries from the maps. This allows detecting unused properties at the end of configuration loading.

  • Field Details

  • Constructor Details

    • PropertySource

      PropertySource(Map<Object,Object> externalProperties, Map<Object,Object> envVarProperties, Map<Object,Object> regularProperties)
      Creates a PropertySource with three separate property maps.
      Parameters:
      externalProperties - properties passed explicitly (e.g., from application code)
      envVarProperties - properties from environment variables (keys in env var format with underscores, lowercase)
      regularProperties - properties from system properties, files, and classpath (keys normalized to snake_case)
    • PropertySource

      PropertySource(Map<Object,Object> regularProperties)
      Creates a PropertySource with only regular properties (for testing).

      Creates empty maps for external and environment variable properties.

      Parameters:
      regularProperties - properties from system properties, files, and classpath (keys normalized to snake_case)
  • Method Details

    • getProperty

      String getProperty(String key)
      Gets a property value by key, checking all three sources in priority order.

      For external and regular properties, performs exact key match. For environment variables, transforms dots to underscores before lookup (e.g., "io.prometheus.metrics.exemplars_enabled" becomes "io_prometheus_metrics_exemplars_enabled").

      Removes the property from ALL source maps to prevent duplicate detection during validation.

      Parameters:
      key - the property key to look up
      Returns:
      the property value, or null if not found
    • getProperty

      String getProperty(String prefix, String propertyName)
      Gets a property value by prefix and property name.

      This is a convenience method that concatenates the prefix and property name with a dot and calls getProperty(String).

      Parameters:
      prefix - the property prefix (e.g., "io.prometheus.metrics"), or empty string for no prefix
      propertyName - the property name (e.g., "exemplars_enabled")
      Returns:
      the property value, or null if not found
    • getAllKeys

      Set<String> getAllKeys()
      Returns all keys from all three property sources.

      Keys are returned in the format they are stored in each source: external and regular properties typically use dot-separated keys, while environment variables are exposed in their underscore form (e.g., "io_prometheus_metrics_exemplars_enabled").

      This is used for pattern matching to find metric-specific configurations.

      Returns:
      a set of all property keys
    • getRemainingKeys

      Set<String> getRemainingKeys()
      Returns all remaining keys from all three property sources.

      This is used for validation to detect unused properties that might indicate configuration errors.

      Returns:
      a set of all remaining property keys