feat(parser): add UptimeRobot IP range parser#15
Merged
Conversation
- Add parser_uptimerobot.go to handle UptimeRobot API JSON format - Update uptimerobot.yaml to use correct API endpoint and parser - UptimeRobot uses ip_prefix/ipv6_prefix fields (snake_case) PiperOrigin-RevId: 028161d Change-Id: I028161dcde3769a4b5d6546649af9d18
Contributor
Reviewer's GuideAdds a custom parser for UptimeRobot's JSON IP range API and updates the UptimeRobot monitor configuration to use the new parser and endpoint. Sequence diagram for UptimeRobot JSON IP range parsing flowsequenceDiagram
participant MonitorConfig_uptimerobot as MonitorConfig_uptimerobot
participant Fetcher
participant UptimeRobotAPI
participant UptimeRobotParser
participant netip
MonitorConfig_uptimerobot->>Fetcher: configure parser uptimerobot and URL https_api_uptimerobot_com_meta_ips
Fetcher->>UptimeRobotAPI: HTTP GET https_api_uptimerobot_com_meta_ips
UptimeRobotAPI-->>Fetcher: JSON body prefixes_ip_prefix_ipv6_prefix
Fetcher->>UptimeRobotParser: Parse(reader)
UptimeRobotParser->>UptimeRobotParser: io_ReadAll
UptimeRobotParser->>UptimeRobotParser: json_Unmarshal_to_uptimeRobotResponse
loop over resp_Prefixes
UptimeRobotParser->>netip: ParsePrefix(IPPrefix_or_IPv6Prefix)
netip-->>UptimeRobotParser: netip_Prefix_or_error
UptimeRobotParser->>UptimeRobotParser: append_valid_prefixes
end
UptimeRobotParser-->>Fetcher: []netip_Prefix
Fetcher-->>MonitorConfig_uptimerobot: normalized_IP_prefix_list
Class diagram for UptimeRobotParser and related typesclassDiagram
class Parser {
<<interface>>
Name() string
Parse(r io_Reader) []netip_Prefix
}
class UptimeRobotParser {
Name() string
Parse(r io_Reader) []netip_Prefix
}
Parser <|.. UptimeRobotParser
class uptimeRobotResponse {
Prefixes []uptimeRobotPrefix
}
class uptimeRobotPrefix {
IPPrefix string
IPv6Prefix string
}
uptimeRobotResponse "1" *-- "many" uptimeRobotPrefix
class ParserRegistry {
RegisterParser(name string, parser Parser)
}
ParserRegistry o--> UptimeRobotParser
UptimeRobotParser ..> uptimeRobotResponse
UptimeRobotParser ..> uptimeRobotPrefix
UptimeRobotParser ..> netip_Prefix
UptimeRobotParser ..> io_Reader
UptimeRobotParser ..> json_Unmarshal
UptimeRobotParser ..> io_ReadAll
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
Parse, prefix parsing errors are silently ignored; consider either returning an error with context or logging which prefixes failed to parse so malformed data from the upstream API is visible rather than being quietly dropped. - You can avoid the intermediate allocation with
io.ReadAllby usingjson.NewDecoder(r).Decode(&resp), which simplifies the parsing path and streams directly from the reader.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Parse`, prefix parsing errors are silently ignored; consider either returning an error with context or logging which prefixes failed to parse so malformed data from the upstream API is visible rather than being quietly dropped.
- You can avoid the intermediate allocation with `io.ReadAll` by using `json.NewDecoder(r).Decode(&resp)`, which simplifies the parsing path and streams directly from the reader.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #15 +/- ##
===========================================
- Coverage 72.76% 61.80% -10.97%
===========================================
Files 15 24 +9
Lines 661 1000 +339
===========================================
+ Hits 481 618 +137
- Misses 136 324 +188
- Partials 44 58 +14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replace io.ReadAll + json.Unmarshal with json.NewDecoder(r).Decode() for zero-allocation streaming JSON parsing. PiperOrigin-RevId: 83e1682 Change-Id: I83e168289585ebac84bed837eb92f6a0
Benchmark Results |
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 by Sourcery
Add a dedicated parser and configuration to consume UptimeRobot IP ranges from their JSON metadata API instead of the legacy text endpoint.
New Features:
Enhancements: