-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Value Conversions #172
Conversation
037f809
to
9500f3c
Compare
This feels like a happy middle ground for issues with strings/nulls. Fingers crossed it looks good! 😄 |
Can a maintainer approve this pull request? We have a deadline here. It would be best if we can get an approval by Wednesday? |
@yaohongkok I am not sure if we should hurry a change in case there's an unseen breakage (but I don't have any say other than being an end-user). All that said, @SuperQ what is the likelihood of this PR being merged? |
@liam-hogan Thanks for the reply. I understand the concern of introducing breaking changes. We would still appreciate it if we can get a code review soon. If it is not possible, then we will just wait like everyone else. We have tested it internally and things seems to work fine. I think the tests are passing too. |
Hey @rustycl0ck @SuperQ What is the likelihood for this PR as well as #167 getting merged into master? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks like there are some naming convention issue. I will go update the forked repo next week to conform to the linter. |
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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
…ommunity#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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
6314b9f
to
52a4267
Compare
I have fixed the linting issue. Hopefully, the reviewers can take a look at it. Also, the merge conflict basically involves merging both code together. Some manually typing would be involved. Unfortunately, I have no write access so I cannot perform the merge. |
You will need to perform the merge locally on your fork and force-push your branch. I recommend syncing your master branch and doing |
Oh, I see, @ngrebels needs to fix up the branch. |
Oh, you are right. Let me give this a try to see if it will work. |
…_exporter into prometheus-community-master
Signed-off-by: Yao Hong Kok <yaokok@mathworks.com>
1121928
to
428f101
Compare
I have made all the fix. Hopefully @rustycl0ck and @sysadmind can perform the code review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@rustycl0ck Can you review it when you are free? |
Hi @rustycl0ck were you able to review this change? |
@yaohongkok and @sysadmind : Not sure if there's anything wrong with the waiting approval? What can be done to get this moved forward? |
@liam-hogan I think my understanding is @rustycl0ck need to approve this before it can be merged. Maybe I am wrong? I have check with ngrebls but it seems like he cannot finish of the pull request too. Can @sysadmind force pull this pull request? |
I believe that @SuperQ is the one to merge. I don't have access on this repo. Ping. :) |
I will try to ping @SuperQ. |
@SuperQ please hold on, don't release this yet. Sorry for being late but I have some questions regarding this PR. Also, it seems to be buggy if the sample config uses |
Sorry, I overlooked this PR. I will set up a periodic schedule for me to go through issues and PRs for this repo in future. However, for the people involved with the use case for this PR (@ngrebels, @liam-hogan, @yaohongkok): ExampleExample config: modules:
default:
metrics:
- name: example_state
type: object
help: Example of counting different states
path: '{.values[*]}'
labels:
id: '{.id}'
state: '{.state}'
values:
activity: 18 # static value
- name: example_convert_original
type: object
help: Example of assigning a static value to INACTIVE state
path: '{.values[?(@.state == "INACTIVE")]}'
labels:
id: '{.id}'
state: '{.state}'
values:
state: 17 # static value
- name: example_convert_original
type: object
help: Example of assigning a static value to INACTIVE state
path: '{.values[?(@.state == "ACTIVE")]}'
labels:
id: '{.id}'
state: '{.state}'
values:
state: 19 # static value
- name: example_convert
type: object
path: '{.values[0,1]}'
labels:
state: '{.state}'
values:
state: '{.state}'
valueconverter:
'{.state}': #convert value 'state' in JSON into a number
active: 29
inactive: 23 Example data: {
"counter": 1234,
"timestamp": 1657568506,
"values": [
{
"id": "id-A",
"count": 1,
"some_boolean": true,
"state": "ACTIVE"
},
{
"id": "id-B",
"count": 2,
"some_boolean": true,
"state": "INACTIVE"
},
{
"id": "id-C",
"count": 3,
"some_boolean": false,
"state": "ACTIVE"
}
],
"location": "mars"
} Response: $ curl "http://localhost:7979/probe?module=default&target=http://localhost:8000/examples/data.json"
# HELP example_convert_original_state Example of assigning a static value to INACTIVE state
# TYPE example_convert_original_state untyped
example_convert_original_state{id="id-A",state="ACTIVE"} 19
example_convert_original_state{id="id-B",state="INACTIVE"} 17
example_convert_original_state{id="id-C",state="ACTIVE"} 19
# HELP example_convert_state example_convert
# TYPE example_convert_state untyped
example_convert_state{state="ACTIVE"} 29
example_convert_state{state="INACTIVE"} 23
# HELP example_state_activity Example of counting different states
# TYPE example_state_activity untyped
example_state_activity{id="id-A",state="ACTIVE"} 18
example_state_activity{id="id-B",state="INACTIVE"} 18
example_state_activity{id="id-C",state="ACTIVE"} 18 Reproducing your use case without this PR: An alternative to your use case: Minor problem with the implementation of this PR:
This means that the example config added in this PR, is equivalent to adding following two static metrics in each scrape (irrespective of any conditions, the following two metrics will always be scraped or else there will be an error): example_convert_state{state="ACTIVE"} 1
example_convert_state{state="INACTIVE"} 2 This makes these metrics useless in my opinion because they are "always" present and with the exact same values. So they contain no information at all. But still if you want this behavior, it can be achieved by adding static metric values in the config file already before this PR was merged. Again, sorry for the delay in reviewing. I hope I will be able to better manage my schedule in future. |
@rustycl0ck Ok. I think the problem here was the documentation was not completely clear. Until you showed me the example, I thought that this was not possible at all. I will give your examples a try. |
@rustycl0ck To explain my use case, it has been discussed at #76 .Specifically, I have values that are returning as My json format is described in #168
Really what I am targeting is the values in Additionally, I have tried your method where I have also tried just ignoring null values and letting Grafana deal with it, but I run into the same issue. |
@rustycl0ck so, I was able to resolve this. Long story short, yes: each individual metric requires a separate So, I was able to make sure there were no errors by filtering out the null values on individual metrics this way. This means each name section basically looks like so:
|
After looking more closely at @rustycl0ck suggestion and comparing it with our previous pull request, I do see more benefits of adopting our approach to map values. The key benefit is that the value mapping process is more succinct and less code duplication. Let's say I have a field call 'status' and it has 4 possible values. These means that I need 4 entries in the config.yml file. Notices that 'labels' field is being duplicated 4 times. Some apps may need different labels but I feel that there should be an option to avoid repeating labels frequently. If no one objects, can I create an issue for this? |
* 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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> * 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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> * Added a value converter for dynamic values and associated tests Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> * Refactored into functions and created a type Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> * value converter: added example Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> * Remove underscore from variable name Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> * Fix formatting error from merging Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> Signed-off-by: ngrebels <ngrebels@mathworks.com> Signed-off-by: Yao Hong Kok <yaokok@mathworks.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yao Hong Kok <yaokok@mathworks.com>
* [FEATURE] Allow timestamps from metrics prometheus-community#167 * [FEATURE] Support Value Conversions prometheus-community#172 Signed-off-by: SuperQ <superq@gmail.com> Signed-off-by: raed altuwaijri <altuwaijriraed@gmail.com>
These changes allow users to define value mappings within the config file. By defining these mappings, values that are strings can be converted into a number.
Included: