Add support for dynamic object key extraction in JSON Exporter#397
Open
silveraignacio wants to merge 1 commit intoprometheus-community:masterfrom
Open
Add support for dynamic object key extraction in JSON Exporter#397silveraignacio wants to merge 1 commit intoprometheus-community:masterfrom
silveraignacio wants to merge 1 commit intoprometheus-community:masterfrom
Conversation
984259c to
03862fb
Compare
This enhancement allows extracting dynamic JSON object keys as Prometheus labels using the special JSONPath syntax `{__name__}`.
## Key Features:
- Extract dynamic object keys as label values using `{__name__}` syntax
- Maintain full backward compatibility with existing configurations
- Support for mixed label types (dynamic keys + static values + regular JSONPath)
- Enhanced object scraping with dynamic label extraction
## Use Cases:
- Cloud provider monitoring with dynamic instance/account names
- Service discovery endpoints with generated names
- Infrastructure monitoring with environment-specific identifiers
- API gateway monitoring with dynamic endpoint names
## Implementation:
- Added `extractDynamicLabels()` function for enhanced label extraction
- Added `extractDynamicValue()` function for dynamic object value extraction
- Extended object scraping logic to support dynamic key extraction
- Added comprehensive test coverage for new functionality
- Included test data and configuration files for validation
## Files Added/Modified:
- exporter/collector.go: Core implementation
- exporter/util_test.go: Unit tests
- README.md: Updated documentation
- test/local-test-*.* and test/multi-provider-test-*.*: Test configurations and data
Signed-off-by: Ignacio Silvera <silveraignacio@gmail.com>
03862fb to
ecc0df9
Compare
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.
This enhancement allows extracting dynamic JSON object keys as Prometheus labels using the special JSONPath syntax
{__name__}.Key Features:
{__name__}syntaxUse Cases:
Implementation:
extractDynamicLabels()function for enhanced label extractionextractDynamicValue()function for dynamic object value extractionFiles Added/Modified:
Example
{"providers": [{"aws-prod-123": {"ok": true}}, {"gcp-dev-456": {"ok": false}}]}Config
Generates: