-
Notifications
You must be signed in to change notification settings - Fork 0
v3.1.0 implementation #12
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5bbff36
Clarify README wording about codecs
lupodevelop a6c2066
Add cluster monitoring and tests
lupodevelop 64c3145
Add telemetry & variant codec, integrate hooks
lupodevelop 55641e8
Add variant & integration tests, update version
lupodevelop 8296557
Add ADT variant codec docs and telemetry dep
lupodevelop 2a0fe2e
Add master branch and bump OTP in CI
lupodevelop 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ | |
| erl_crash.dump | ||
| **/build | ||
| *.log | ||
| /notes | ||
|
|
||
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
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
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,81 @@ | ||
| import distribute/internal/telemetry | ||
| import gleam/dynamic.{type Dynamic} | ||
| import gleam/erlang/process.{type Subject} | ||
| import gleam/otp/actor | ||
| import gleam/result | ||
|
|
||
| pub type ClusterEvent { | ||
| NodeUp(node: String) | ||
| NodeDown(node: String) | ||
| } | ||
|
|
||
| @external(erlang, "cluster_ffi", "nodeup_atom") | ||
| fn nodeup_atom() -> Dynamic | ||
|
|
||
| @external(erlang, "cluster_ffi", "nodedown_atom") | ||
| fn nodedown_atom() -> Dynamic | ||
|
|
||
| @external(erlang, "cluster_ffi", "monitor_nodes") | ||
| fn monitor_nodes_ffi(flag: Bool) -> Dynamic | ||
|
|
||
| @external(erlang, "cluster_ffi", "atom_to_string") | ||
| fn atom_to_string_ffi(atom: Dynamic) -> String | ||
|
|
||
| @external(erlang, "cluster_ffi", "get_node_from_tuple") | ||
| fn get_node_from_tuple_ffi(msg: Dynamic) -> Dynamic | ||
|
|
||
| pub type ControlMessage { | ||
| Stop | ||
| InternalEvent(ClusterEvent) | ||
| } | ||
|
|
||
| /// Subscribe to cluster topology events. | ||
| /// Events are forwarded to the provided user_subject. | ||
| /// Returns a control subject to stop the subscription. | ||
| pub fn subscribe( | ||
| user_subject: Subject(ClusterEvent), | ||
| ) -> Result(Subject(ControlMessage), actor.StartError) { | ||
| actor.new_with_initialiser(5000, fn(self_subject) { | ||
| // Start node monitoring in the actor's context | ||
| monitor_nodes_ffi(True) | ||
|
|
||
| // Select standard nodeup/nodedown Erlang messages | ||
| let selector = | ||
| process.new_selector() | ||
| |> process.select(self_subject) | ||
| |> process.select_record(nodeup_atom(), 1, fn(msg) { | ||
| let node_atom = get_node_from_tuple_ffi(msg) | ||
| InternalEvent(NodeUp(atom_to_string_ffi(node_atom))) | ||
| }) | ||
| |> process.select_record(nodedown_atom(), 1, fn(msg) { | ||
| let node_atom = get_node_from_tuple_ffi(msg) | ||
| InternalEvent(NodeDown(atom_to_string_ffi(node_atom))) | ||
| }) | ||
|
|
||
| Ok( | ||
| actor.initialised(user_subject) | ||
| |> actor.selecting(selector) | ||
| |> actor.returning(self_subject), | ||
| ) | ||
| }) | ||
| |> actor.on_message(fn(state, msg) { | ||
| case msg { | ||
| InternalEvent(event) -> { | ||
| case event { | ||
| NodeUp(node) -> telemetry.emit_node_event(node, "up") | ||
| NodeDown(node) -> telemetry.emit_node_event(node, "down") | ||
| } | ||
| process.send(state, event) | ||
| actor.continue(state) | ||
| } | ||
| Stop -> actor.stop() | ||
| } | ||
| }) | ||
| |> actor.start() | ||
| |> result.map(fn(started) { started.data }) | ||
| } | ||
|
|
||
| /// Stop the monitoring for a specific subscription. | ||
| pub fn unsubscribe(monitor_subject: Subject(ControlMessage)) -> Nil { | ||
| process.send(monitor_subject, Stop) | ||
| } |
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.
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.
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.
simulate_node_event/3usesbinary_to_atom/2on caller-provided data and is exported from the library module. This allows creating arbitrary new atoms at runtime (atom table exhaustion). Consider removing it from-export, moving it to test-only code, or usingbinary_to_existing_atom/2/validated allowlists so it can’t create unbounded atoms.