-
Notifications
You must be signed in to change notification settings - Fork 25
Add x-medkit-graph provider and function cyclic subscriptions #270
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
Merged
bburda
merged 13 commits into
selfpatch:main
from
eclipse0922:feat/248-x-medkit-graph-provider
Mar 15, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a21f8d7
Add x-medkit-graph provider
eclipse0922 78e280a
Add function cyclic subscription support
eclipse0922 5f6a99b
Fix graph provider schema semantics
eclipse0922 a5392b0
Add graph provider regression coverage
eclipse0922 3c3eae9
Fix graph provider diagnostics semantics
eclipse0922 db32e2d
Remove cyclic subscription design note
eclipse0922 b865b36
Remove cyclic subscription plan note
eclipse0922 410a8bc
Fix graph provider route rebuild semantics
eclipse0922 024c6e1
Fix CI lint and legacy discovery race
eclipse0922 694aab1
Stabilize graph provider introspection test
eclipse0922 09ac63c
test(gateway): restore graph provider introspection cleanup
eclipse0922 ddf8500
Address Copilot review feedback
eclipse0922 d3d09e3
fix(gateway): address bburda graph provider review
eclipse0922 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
112 changes: 112 additions & 0 deletions
112
src/ros2_medkit_gateway/include/ros2_medkit_gateway/plugins/graph_provider_plugin.hpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright 2026 eclipse0922 | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ros2_medkit_gateway/plugins/gateway_plugin.hpp" | ||
| #include "ros2_medkit_gateway/providers/introspection_provider.hpp" | ||
|
|
||
| #include <diagnostic_msgs/msg/diagnostic_array.hpp> | ||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| #include <deque> | ||
| #include <mutex> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
|
|
||
| namespace ros2_medkit_gateway { | ||
|
|
||
| class PluginContext; | ||
| class GatewayNode; | ||
|
|
||
| class GraphProviderPlugin : public GatewayPlugin, public IntrospectionProvider { | ||
| public: | ||
| struct TopicMetrics { | ||
| std::optional<double> frequency_hz; | ||
| std::optional<double> latency_ms; | ||
| double drop_rate_percent{0.0}; | ||
| std::optional<double> expected_frequency_hz; | ||
| }; | ||
|
|
||
| struct GraphBuildState { | ||
| std::unordered_map<std::string, TopicMetrics> topic_metrics; | ||
| std::unordered_set<std::string> stale_topics; | ||
| std::unordered_map<std::string, std::string> last_seen_by_app; | ||
| bool diagnostics_seen{false}; | ||
| }; | ||
|
|
||
| struct GraphBuildConfig { | ||
| double expected_frequency_hz_default{30.0}; | ||
| double degraded_frequency_ratio{0.5}; | ||
| double drop_rate_percent_threshold{5.0}; | ||
| }; | ||
|
|
||
| GraphProviderPlugin() = default; | ||
| ~GraphProviderPlugin() override = default; | ||
|
|
||
| std::string name() const override; | ||
| void configure(const nlohmann::json & config) override; | ||
| void set_context(PluginContext & context) override; | ||
| void register_routes(httplib::Server & server, const std::string & api_prefix) override; | ||
| IntrospectionResult introspect(const IntrospectionInput & input) override; | ||
|
|
||
| static nlohmann::json build_graph_document(const std::string & function_id, const IntrospectionInput & input, | ||
| const GraphBuildState & state, const GraphBuildConfig & config, | ||
| const std::string & timestamp); | ||
|
|
||
| private: | ||
| struct ConfigOverrides { | ||
| std::unordered_map<std::string, GraphBuildConfig> by_function; | ||
| GraphBuildConfig defaults; | ||
| }; | ||
|
|
||
| void subscribe_to_diagnostics(); | ||
| void diagnostics_callback(const diagnostic_msgs::msg::DiagnosticArray::ConstSharedPtr & msg); | ||
| static std::optional<TopicMetrics> parse_topic_metrics(const diagnostic_msgs::msg::DiagnosticStatus & status); | ||
| static std::optional<double> parse_double(const std::string & value); | ||
| static std::string generate_fault_code(const std::string & diagnostic_name); | ||
| static std::string current_timestamp(); | ||
| GraphBuildConfig resolve_config(const std::string & function_id) const; | ||
| std::optional<nlohmann::json> get_cached_or_built_graph(const std::string & function_id); | ||
| std::optional<nlohmann::json> build_graph_from_entity_cache(const std::string & function_id); | ||
| std::unordered_set<std::string> collect_stale_topics(const std::string & function_id, | ||
| const IntrospectionInput & input) const; | ||
| GraphBuildState build_state_snapshot(const std::string & function_id, const IntrospectionInput & input, | ||
| const std::string & timestamp, bool include_stale_topics = true); | ||
| void load_parameters(); | ||
|
|
||
| PluginContext * ctx_{nullptr}; | ||
| GatewayNode * gateway_node_{nullptr}; | ||
|
|
||
| // Each mutex protects an independent cache/state bucket; no code path acquires more than one. | ||
| mutable std::mutex cache_mutex_; | ||
| std::unordered_map<std::string, nlohmann::json> graph_cache_; | ||
|
|
||
| mutable std::mutex metrics_mutex_; | ||
| std::unordered_map<std::string, TopicMetrics> topic_metrics_; | ||
| std::deque<std::string> topic_metrics_order_; | ||
| bool diagnostics_seen_{false}; // Guarded by metrics_mutex_. | ||
|
|
||
| mutable std::mutex status_mutex_; | ||
| std::unordered_map<std::string, std::string> last_seen_by_app_; | ||
|
|
||
| mutable std::mutex config_mutex_; | ||
| ConfigOverrides config_; | ||
|
|
||
| rclcpp::Subscription<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr diagnostics_sub_; | ||
| }; | ||
|
|
||
| } // namespace ros2_medkit_gateway |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.