forked from prometheus-community/json_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Value Conversions (prometheus-community#172)
* Bump k8s.io/client-go from 0.24.2 to 0.24.3 (prometheus-community#171) Bumps [k8s.io/client-go](https://github.com/kubernetes/client-go) from 0.24.2 to 0.24.3. - [Release notes](https://github.com/kubernetes/client-go/releases) - [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md) - [Commits](kubernetes/client-go@v0.24.2...v0.24.3) --- updated-dependencies: - dependency-name: k8s.io/client-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: ngrebels <[email protected]> Signed-off-by: Yao Hong Kok <[email protected]> * Bump github.com/prometheus/common from 0.35.0 to 0.37.0 (prometheus-community#170) Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.35.0 to 0.37.0. - [Release notes](https://github.com/prometheus/common/releases) - [Commits](prometheus/common@v0.35.0...v0.37.0) --- updated-dependencies: - dependency-name: github.com/prometheus/common dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: ngrebels <[email protected]> Signed-off-by: Yao Hong Kok <[email protected]> * Added a value converter for dynamic values and associated tests Signed-off-by: ngrebels <[email protected]> Signed-off-by: Yao Hong Kok <[email protected]> * Refactored into functions and created a type Signed-off-by: ngrebels <[email protected]> Signed-off-by: Yao Hong Kok <[email protected]> * value converter: added example Signed-off-by: ngrebels <[email protected]> Signed-off-by: Yao Hong Kok <[email protected]> * Remove underscore from variable name Signed-off-by: Yao Hong Kok <[email protected]> * Fix formatting error from merging Signed-off-by: Yao Hong Kok <[email protected]> Signed-off-by: ngrebels <[email protected]> Signed-off-by: Yao Hong Kok <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yao Hong Kok <[email protected]>
- Loading branch information
1 parent
cb16d24
commit cedb5a5
Showing
8 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
#the following tests use ./valueconverter.json | ||
|
||
modules: | ||
default: | ||
metrics: | ||
#State should be converted to 1 for the metric value | ||
#Test uppercase key | ||
- name: test1 | ||
path: "{$}" | ||
help: Testing Single Value Converter on Type Object | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
state: '{.state}' | ||
valueconverter: | ||
'{.state}': | ||
ACTIVE: 1 | ||
|
||
#State should be converted to 1 for the metric value | ||
#Test lowercase key | ||
- name: test2 | ||
path: "{$}" | ||
help: Testing Single Value Converter on Type Object | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
state: '{.state}' | ||
valueconverter: | ||
'{.state}': | ||
active: 1 | ||
|
||
#There should be two JSONs returned: a metric for 'state' with value 1, and a metric with value 12 | ||
- name: test3 | ||
path: "{$}" | ||
help: Testing Multi Diff Value Converter on Type Object | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
state: '{.state}' | ||
active: 12 | ||
valueconverter: | ||
'{.state}': | ||
ACTIVE: 1 | ||
|
||
#Nothing should be returned. This should be an error since 'state' can't be converted to an int | ||
- name: test4 | ||
path: "{$}" | ||
help: Testing Value with missing conversion | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
state: '{.state}' | ||
|
||
#Test nested JSON. It should return with both values but with 12 as the metric value | ||
- name: test5 | ||
path: '{.values[*]}' | ||
help: Testing Conversion with Missing value | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
active: 12 | ||
valueconverter: | ||
'{.state}': | ||
ACTIVE: 1 | ||
|
||
#Test nested JSON. | ||
#It should return with both values but 'state' should be converted | ||
- name: test6 | ||
path: '{.values[*]}' | ||
help: Testing Value with Multiple Conversions | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
state: '{.state}' | ||
valueconverter: | ||
'{.state}': | ||
ACTIVE: 1 | ||
inactive: 2 | ||
|
||
#Test nested JSON. | ||
#However, it should only return with state value | ||
#There is a missing key: 'down' in valueconverter | ||
- name: test7 | ||
path: '{.values[*]}' | ||
help: Testing Value with Multiple Conversions and Missing Key, Value | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
state: '{.state}' | ||
valueconverter: | ||
'{.state}': | ||
ACTIVE: 1 | ||
|
||
#Two metrics should be returned | ||
#State should be mapped to 1. | ||
#ResponseCode should be 2 because it already has a value in the JSON. | ||
- name: test8 | ||
path: "{$}" | ||
help: Testing Multi Diff Value Converter on Type Object | ||
type: object | ||
labels: | ||
name: '{.name}' | ||
values: | ||
stat: '{.state}' | ||
active: '{.responseCode}' | ||
valueconverter: | ||
'{.state}': | ||
ACTIVE: 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# HELP test1_state Testing Single Value Converter on Type Object | ||
# TYPE test1_state untyped | ||
test1_state{name="Test Converter"} 1 | ||
# HELP test2_state Testing Single Value Converter on Type Object | ||
# TYPE test2_state untyped | ||
test2_state{name="Test Converter"} 1 | ||
# HELP test3_active Testing Multi Diff Value Converter on Type Object | ||
# TYPE test3_active untyped | ||
test3_active{name="Test Converter"} 12 | ||
# HELP test3_state Testing Multi Diff Value Converter on Type Object | ||
# TYPE test3_state untyped | ||
test3_state{name="Test Converter"} 1 | ||
# HELP test5_active Testing Conversion with Missing value | ||
# TYPE test5_active untyped | ||
test5_active{name="id-A"} 12 | ||
test5_active{name="id-B"} 12 | ||
# HELP test6_state Testing Value with Multiple Conversions | ||
# TYPE test6_state untyped | ||
test6_state{name="id-A"} 1 | ||
test6_state{name="id-B"} 2 | ||
# HELP test7_state Testing Value with Multiple Conversions and Missing Key, Value | ||
# TYPE test7_state untyped | ||
test7_state{name="id-A"} 1 | ||
# HELP test8_active Testing Multi Diff Value Converter on Type Object | ||
# TYPE test8_active untyped | ||
test8_active{name="Test Converter"} 2 | ||
# HELP test8_stat Testing Multi Diff Value Converter on Type Object | ||
# TYPE test8_stat untyped | ||
test8_stat{name="Test Converter"} 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Test Converter", | ||
"state": "ACTIVE", | ||
"responseCode": 2, | ||
"values": [ | ||
{ | ||
"name": "id-A", | ||
"state": "ACTIVE" | ||
}, | ||
{ | ||
"name": "id-B", | ||
"state": "INACTIVE" | ||
} | ||
] | ||
} | ||
|