support environment variables in properties#1828
Open
zeitlinger wants to merge 14 commits intomainfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an environment-variable configuration layer and standardizes property naming to snake_case while preserving backward compatibility via key normalization.
Changes:
- Introduces
PropertySourceto unify external, environment, and “regular” (system/file/classpath) properties with defined precedence. - Adds environment-variable loading (
IO_PROMETHEUS_*) and camelCase→snake_case normalization for file/system/external keys. - Updates config docs, test resources, and tests to use the new snake_case property names and new loader APIs.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PropertySource.java | New abstraction for multi-source property lookup with precedence and key transformations. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusPropertiesLoader.java | Loads properties from file/classpath/system, adds env var layer, normalizes keys, validates leftovers. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/Util.java | Refactors property lookup helpers to read from PropertySource and improve key formatting in errors. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/MetricsProperties.java | Migrates internal property-name constants to snake_case and updates loading/validation paths. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterProperties.java | Switches exporter property keys to snake_case and loads via PropertySource. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterHttpServerProperties.java | Updates prefix/key naming to snake_case and loads via PropertySource. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterFilterProperties.java | Renames filter keys to snake_case and updates loader wiring. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterOpenTelemetryProperties.java | Renames OTel keys to snake_case and updates loader wiring. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterPushgatewayProperties.java | Renames pushgateway keys to snake_case and updates loader wiring. |
| prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExemplarsProperties.java | Renames exemplars keys to snake_case and loads via PropertySource. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/UtilTest.java | Updates tests to use PropertySource-based APIs. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/PrometheusPropertiesTest.java | Updates loading tests to use PropertySource and asserts properties are consumed. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/PrometheusPropertiesLoaderTest.java | Updates loader tests to snake_case keys. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/MetricsPropertiesTest.java | Updates expected exception messages and property keys to snake_case. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPropertiesTest.java | Updates keys and loader helper to use PropertySource. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterHttpServerPropertiesTest.java | Updates keys and loader helper to use PropertySource. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterFilterPropertiesTest.java | Updates keys and loader helper to use PropertySource. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterOpenTelemetryPropertiesTest.java | Updates keys and loader helper to use PropertySource. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java | Updates loader helper to use PropertySource. |
| prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExemplarsPropertiesTest.java | Updates keys and loader helper to use PropertySource. |
| prometheus-metrics-config/src/test/resources/prometheus.properties | Updates test properties file to snake_case keys. |
| prometheus-metrics-config/src/test/resources/emptyUpperBounds.properties | Updates test properties key to snake_case. |
| docs/content/config/config.md | Documents env var support, precedence, and snake_case naming; updates examples/tables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PropertySource.java
Outdated
Show resolved
Hide resolved
...us-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusPropertiesLoader.java
Show resolved
Hide resolved
...us-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusPropertiesLoader.java
Show resolved
Hide resolved
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1d05224 to
8ee2b21
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 24 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusProperties.java
Outdated
Show resolved
Hide resolved
prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusProperties.java
Show resolved
Hide resolved
...-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterHttpServerProperties.java
Show resolved
Hide resolved
prometheus-metrics-config/src/test/resources/prometheus.properties
Outdated
Show resolved
Hide resolved
...heus-metrics-config/src/test/java/io/prometheus/metrics/config/PrometheusPropertiesTest.java
Outdated
Show resolved
Hide resolved
...etrics-config/src/test/java/io/prometheus/metrics/config/PrometheusPropertiesLoaderTest.java
Outdated
Show resolved
Hide resolved
prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusProperties.java
Show resolved
Hide resolved
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
No Breaking Changes. This is fully backward compatible:
Migration Guide
No migration required. However, to adopt the new features:
To use environment variables: Convert property names to uppercase with underscores
io.prometheus.exporter.httpServer.port→IO_PROMETHEUS_EXPORTER_HTTP_SERVER_PORTTo use snake_case (recommended): Update properties files
io.prometheus.metrics.exemplarsEnabled→io.prometheus.metrics.exemplars_enabledNotes