Repository navigation
Expose optional bounded listener and forwarding diagnostics #186
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
4 commits
Select commit
Hold shift + click to select a range
a5ff054
Expose optional names-only Votifier health snapshot
BenCodez 9c7919c
Preserve forwarding entry identity in diagnostic completeness
BenCodez 0862756
Safely publish listener replacements to diagnostic callers
BenCodez 93b14a6
Mark unreadable forwarding entries as unknown diagnostic evidence
BenCodez 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| # VotifierPlus | ||
| Fork of votifier | ||
|
|
||
| ## Optional Network Doctor diagnostics | ||
|
|
||
| VotifierPlus exposes a read-only `getNetworkHealthSnapshot()` method on its | ||
| Bukkit, BungeeCord, and Velocity entry points for compatible management | ||
| software. The immutable snapshot reports whether the provider is present, the | ||
| listener is initialized, whether forwarding state is known, and the names of | ||
| enabled forwarding destinations. Destination names are bounded and | ||
| deduplicated; hosts, ports, keys, tokens, credentials, and configuration text | ||
| are never included. The API is optional and does not participate in vote | ||
| receipt, event dispatch, or forwarding, so older VotingPlugin and Control | ||
| nodes continue to work without it. |
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
54 changes: 54 additions & 0 deletions
54
VotifierPlus/src/main/java/com/vexsoftware/votifier/diagnostic/VotifierDiagnostics.java
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,54 @@ | ||
| package com.vexsoftware.votifier.diagnostic; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import com.vexsoftware.votifier.ForwardServer; | ||
| import com.vexsoftware.votifier.net.VoteReceiver; | ||
|
|
||
| /** Optional adapter used by management software without a hard dependency. */ | ||
| public final class VotifierDiagnostics { | ||
| private VotifierDiagnostics() { | ||
| } | ||
|
|
||
| /** | ||
| * Captures only state already owned by the receiver. A null receiver means | ||
| * that listener state is unavailable, rather than falsely healthy. | ||
| */ | ||
| public static VotifierDiagnosticsSnapshot snapshot(VoteReceiver receiver) { | ||
| if (receiver == null) { | ||
| return new VotifierDiagnosticsSnapshot(Boolean.TRUE, null, null, null); | ||
| } | ||
| List<String> destinations = new ArrayList<String>(); | ||
| boolean forwardingKnown = true; | ||
| try { | ||
| for (String name : receiver.getServers()) { | ||
| if (name == null || name.trim().isEmpty()) { | ||
| // An unrepresentable configured entry means the forwarding inventory is incomplete. | ||
| forwardingKnown = false; | ||
| continue; | ||
| } | ||
| ForwardServer server = receiver.getServerData(name); | ||
| if (server == null) { | ||
| // A configured entry that cannot be classified is incomplete evidence. | ||
| forwardingKnown = false; | ||
| } else if (server.isEnabled()) { | ||
| if (name.length() > VotifierDiagnosticsSnapshot.MAX_NAME_LENGTH | ||
| || destinations.size() >= VotifierDiagnosticsSnapshot.MAX_DESTINATIONS) { | ||
| // Do not claim complete evidence after the bounded snapshot omitted a risk. | ||
| forwardingKnown = false; | ||
| continue; | ||
| } | ||
| // Preserve configured identity; snapshot validation downgrades noncanonical names. | ||
| destinations.add(name); | ||
| } | ||
| } | ||
| } catch (RuntimeException unavailable) { | ||
| forwardingKnown = false; | ||
| destinations.clear(); | ||
| } | ||
| return new VotifierDiagnosticsSnapshot(Boolean.TRUE, | ||
| receiver.getServer() != null && !receiver.getServer().isClosed(), | ||
| forwardingKnown, destinations); | ||
| } | ||
| } |
88 changes: 88 additions & 0 deletions
88
...erPlus/src/main/java/com/vexsoftware/votifier/diagnostic/VotifierDiagnosticsSnapshot.java
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,88 @@ | ||
| package com.vexsoftware.votifier.diagnostic; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Bounded, read-only Votifier state for optional management-plane diagnostics. | ||
| * | ||
| * <p>This type deliberately contains destination names only. It does not expose | ||
| * forwarding endpoints, ports, keys, tokens, or configuration text.</p> | ||
| */ | ||
| public final class VotifierDiagnosticsSnapshot { | ||
| public static final int MAX_DESTINATIONS = 100; | ||
| public static final int MAX_NAME_LENGTH = 80; | ||
|
|
||
| private final Boolean providerPresent; | ||
| private final Boolean listenerInitialized; | ||
| private final Boolean forwardingKnown; | ||
| private final List<String> forwardingDestinations; | ||
|
|
||
| public VotifierDiagnosticsSnapshot(Boolean providerPresent, Boolean listenerInitialized, | ||
| Boolean forwardingKnown, Iterable<String> forwardingDestinations) { | ||
| this.providerPresent = providerPresent; | ||
| this.listenerInitialized = listenerInitialized; | ||
| BoundedNames bounded = boundedNames(forwardingDestinations); | ||
| this.forwardingKnown = forwardingKnown == null || !Boolean.TRUE.equals(forwardingKnown) | ||
| ? forwardingKnown : bounded.complete ? Boolean.TRUE : Boolean.FALSE; | ||
| this.forwardingDestinations = bounded.names; | ||
| } | ||
|
|
||
| public Boolean getProviderPresent() { | ||
| return providerPresent; | ||
| } | ||
|
|
||
| public Boolean getListenerInitialized() { | ||
| return listenerInitialized; | ||
| } | ||
|
|
||
| public Boolean getForwardingKnown() { | ||
| return forwardingKnown; | ||
| } | ||
|
|
||
| public List<String> getForwardingDestinations() { | ||
| return forwardingDestinations; | ||
| } | ||
|
|
||
| private static BoundedNames boundedNames(Iterable<String> values) { | ||
| if (values == null) { | ||
| return new BoundedNames(Collections.emptyList(), true); | ||
| } | ||
| Set<String> unique = new LinkedHashSet<String>(); | ||
| boolean complete = true; | ||
| for (String value : values) { | ||
| if (value == null) { | ||
| complete = false; | ||
| continue; | ||
| } | ||
| String name = value.trim(); | ||
| if (name.isEmpty() || name.length() > MAX_NAME_LENGTH) { | ||
| complete = false; | ||
| continue; | ||
| } | ||
| if (!name.equals(value) || name.codePoints().anyMatch(Character::isISOControl)) { | ||
| complete = false; | ||
| continue; | ||
| } | ||
| unique.add(name); | ||
| if (unique.size() > MAX_DESTINATIONS) { | ||
| complete = false; | ||
| unique.remove(name); | ||
| } | ||
| } | ||
| return new BoundedNames(Collections.unmodifiableList(new ArrayList<String>(unique)), complete); | ||
| } | ||
|
|
||
| private static final class BoundedNames { | ||
| private final List<String> names; | ||
| private final boolean complete; | ||
|
|
||
| private BoundedNames(List<String> names, boolean complete) { | ||
| this.names = names; | ||
| this.complete = complete; | ||
| } | ||
| } | ||
| } |
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.
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.
When management software calls this accessor from a thread other than the platform reload thread, the unsynchronized, non-
volatilevoteReceiverread is not guaranteed to observe the replacement written byreload(). It can therefore keep snapshotting the old closed receiver and report the listener as unavailable after the new listener is healthy; the same data race exists in the added BungeeCord and Velocity accessors. Publish each receiver field safely (for example, make itvolatile) so post-reload snapshots observe the current receiver.Useful? React with 👍 / 👎.