-
-
Notifications
You must be signed in to change notification settings - Fork 466
feat: server conn statistics #888
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
Reviewer's GuideImplements server connection statistics by introducing freezed data models and Hive adapters, logging connection outcomes in the server provider, persisting and cleaning records via a new ConnectionStatsStore, and adding a settings entry with a dedicated UI for viewing and managing connection history. File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes - here's some feedback:
- The exception-based failure result detection is brittle—consider catching specific exception types (e.g. TimeoutException, AuthException) or encoding error metadata instead of string‐matching on exception messages.
- Relying on string‐splitting of the Hive keys for serverId and timestamp may break if your IDs contain underscores—consider using a structured key or separate indexing fields in the store for safer lookup.
- Scanning all keys every time you fetch stats (especially in getAllServerStats) could become slow at scale—consider grouping records by server or caching aggregated stats to avoid full key iteration on each refresh.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The exception-based failure result detection is brittle—consider catching specific exception types (e.g. TimeoutException, AuthException) or encoding error metadata instead of string‐matching on exception messages.
- Relying on string‐splitting of the Hive keys for serverId and timestamp may break if your IDs contain underscores—consider using a structured key or separate indexing fields in the store for safer lookup.
- Scanning all keys every time you fetch stats (especially in getAllServerStats) could become slow at scale—consider grouping records by server or caching aggregated stats to avoid full key iteration on each refresh.
## Individual Comments
### Comment 1
<location> `lib/data/store/connection_stats.dart:11` </location>
<code_context>
+
+ // Record a connection attempt
+ void recordConnection(ConnectionStat stat) {
+ final key = '${stat.serverId}_${stat.timestamp.millisecondsSinceEpoch}';
+ set(key, stat);
+ _cleanOldRecords(stat.serverId);
+ }
</code_context>
<issue_to_address>
Key generation may lead to collisions for rapid consecutive connections.
Appending only millisecondsSinceEpoch to the key may not ensure uniqueness for rapid consecutive connections. Add a random or incrementing component to the key to prevent collisions.
</issue_to_address>
### Comment 2
<location> `lib/data/store/connection_stats.dart:86` </location>
<code_context>
+ }
+
+ // Get recent connections (last 20)
+ final recentConnections = allStats.take(20).toList();
+
+ return ServerConnectionStats(
</code_context>
<issue_to_address>
Recent connections may not be the most recent if allStats is not sorted.
Sort 'allStats' by timestamp in descending order before selecting the first 20 items to ensure accuracy. Note that this relies on getConnectionHistory's current behavior; future changes to that method could introduce bugs if sorting is not guaranteed.
</issue_to_address>
### Comment 3
<location> `lib/view/page/server/connection_stats.dart:77` </location>
<code_context>
+ }
+
+ Widget _buildServerStatsCard(ServerConnectionStats stats) {
+ final successRate = (stats.successRate * 100).toStringAsFixed(1);
+ final lastSuccessTime = stats.lastSuccessTime;
+ final lastFailureTime = stats.lastFailureTime;
</code_context>
<issue_to_address>
Success rate calculation may display misleading percentages for zero attempts.
Consider displaying 'N/A' or a placeholder instead of '0.0%' when totalAttempts is zero to prevent misinterpretation.
Suggested implementation:
```
Widget _buildServerStatsCard(ServerConnectionStats stats) {
final successRate = stats.totalAttempts == 0
? 'N/A'
: '${(stats.successRate * 100).toStringAsFixed(1)}%';
final lastSuccessTime = stats.lastSuccessTime;
final lastFailureTime = stats.lastFailureTime;
```
If you are displaying `successRate` elsewhere in the card (e.g., in a `Text` widget), ensure you remove any hardcoded '%' sign, as the replacement above already includes it when appropriate.
</issue_to_address>
### Comment 4
<location> `CLAUDE.md:95` </location>
<code_context>
+ - `libL10n` is from `fl_lib` package, and `l10n` is from this project.
+ - Before adding new strings, check if it already exists in `libL10n`.
+ - Prioritize using strings from `libL10n` to avoid duplication, even if the meaning is not 100% exact, just use the substitution of `libL10n`.
+- Split UI into Widget build, Actions, Utils. use `extension on` to archive this
</code_context>
<issue_to_address>
Typo: 'archive' should be 'achieve'.
Change 'archive this' to 'achieve this' to correct the wording.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
lib/data/store/connection_stats.dart
Outdated
| final key = '${stat.serverId}_${stat.timestamp.millisecondsSinceEpoch}'; | ||
| set(key, stat); |
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.
issue (bug_risk): Key generation may lead to collisions for rapid consecutive connections.
Appending only millisecondsSinceEpoch to the key may not ensure uniqueness for rapid consecutive connections. Add a random or incrementing component to the key to prevent collisions.
| } | ||
|
|
||
| // Get recent connections (last 20) | ||
| final recentConnections = allStats.take(20).toList(); |
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.
nitpick (bug_risk): Recent connections may not be the most recent if allStats is not sorted.
Sort 'allStats' by timestamp in descending order before selecting the first 20 items to ensure accuracy. Note that this relies on getConnectionHistory's current behavior; future changes to that method could introduce bugs if sorting is not guaranteed.
| } | ||
|
|
||
| Widget _buildServerStatsCard(ServerConnectionStats stats) { | ||
| final successRate = (stats.successRate * 100).toStringAsFixed(1); |
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.
suggestion: Success rate calculation may display misleading percentages for zero attempts.
Consider displaying 'N/A' or a placeholder instead of '0.0%' when totalAttempts is zero to prevent misinterpretation.
Suggested implementation:
Widget _buildServerStatsCard(ServerConnectionStats stats) {
final successRate = stats.totalAttempts == 0
? 'N/A'
: '${(stats.successRate * 100).toStringAsFixed(1)}%';
final lastSuccessTime = stats.lastSuccessTime;
final lastFailureTime = stats.lastFailureTime;
If you are displaying successRate elsewhere in the card (e.g., in a Text widget), ensure you remove any hardcoded '%' sign, as the replacement above already includes it when appropriate.
CLAUDE.md
Outdated
| - `libL10n` is from `fl_lib` package, and `l10n` is from this project. | ||
| - Before adding new strings, check if it already exists in `libL10n`. | ||
| - Prioritize using strings from `libL10n` to avoid duplication, even if the meaning is not 100% exact, just use the substitution of `libL10n`. | ||
| - Split UI into Widget build, Actions, Utils. use `extension on` to archive this |
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.
issue (typo): Typo: 'archive' should be 'achieve'.
Change 'archive this' to 'achieve this' to correct the wording.
Fixes #748
Summary by Sourcery
Introduce comprehensive server connection statistics by modeling and persisting per-connection data, instrumenting SSH flows to record attempts, and adding a UI page for viewing and managing stats.
New Features:
Enhancements:
Documentation: