-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[feat] Http collect supports jsonpath parsing of numeric type #3612
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
Conversation
Duansg
left a comment
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.
The configuration is as follows:
- name: system_cpu_usage
i18n:
zh-CN: CPU Usage
en-US: CPU Usage
priority: 5
fields:
- field: usage
i18n:
zh-CN: usage
en-US: usage
type: 0
unit: '%'
calculates:
- usage=usage*100
protocol: http
http:
host: ^_^host^_^
port: ^_^port^_^
url: ^_^base_path^_^/metrics/system.cpu.usage
method: GET
ssl: ^_^ssl^_^
authorization:
type: Basic Auth
basicAuthUsername: ^_^username^_^
basicAuthPassword: ^_^password^_^
parseType: jsonPath
parseScript: '$.measurements[?(@.statistic == "VALUE")].value'
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.
Pull Request Overview
This PR adds support for parsing numeric types in JSONPath expressions for HTTP collection in HertzBeat. Previously, the JSONPath parser only handled string values; now it can also extract and process numeric values from JSON responses.
- Added numeric type handling in the
parseResponseByJsonPathmethod - Added comprehensive test coverage for both string and numeric JSONPath parsing scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| HttpCollectImpl.java | Adds numeric type support to JSONPath parsing with proper handling of Number instances |
| HttpCollectImplTest.java | Adds new test case covering both string array and numeric value extraction scenarios |
| parseMethod = HttpCollectImpl.class.getDeclaredMethod( | ||
| "parseResponseByJsonPath", | ||
| String.class, | ||
| List.class, | ||
| HttpProtocol.class, | ||
| CollectRep.MetricsData.Builder.class, | ||
| Long.class); | ||
| parseMethod.setAccessible(true); |
Copilot
AI
Jul 31, 2025
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.
The reflection setup for parseMethod is duplicated code. Consider extracting this into a helper method or reusing the parseMethod variable from the earlier declaration.
| parseMethod = HttpCollectImpl.class.getDeclaredMethod( | |
| "parseResponseByJsonPath", | |
| String.class, | |
| List.class, | |
| HttpProtocol.class, | |
| CollectRep.MetricsData.Builder.class, | |
| Long.class); | |
| parseMethod.setAccessible(true); | |
| parseMethod = getParseMethod(); |
| } | ||
| } | ||
| builder.addValueRow(valueRowBuilder.build()); | ||
| } else if (objectValue instanceof Number numberValue) { |
Copilot
AI
Jul 31, 2025
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.
The logic for handling Number values duplicates the alias field processing from the string array case above. Consider extracting the alias field processing into a helper method to reduce code duplication.
MasamiYui
left a comment
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.
…#3612) Co-authored-by: tomsun28 <[email protected]> Co-authored-by: Sherlock Yin <[email protected]>
What's changed?
Please refer to: #3609
For details:
org.apache.hertzbeat.collector.collect.http.HttpCollectImpl#parseResponseByJsonPathmethod.Checklist
Add or update API