Skip to content

Conversation

@servak
Copy link
Owner

@servak servak commented Jul 7, 2025

Summary

  • Implemented comprehensive probe history tracking with detailed information storage
  • Added support for all probe types (ICMP, HTTP, DNS, NTP, TCP) with type-specific details
  • Enhanced TUI with real-time detail view and history management
  • Added color-coded status display and filtering capabilities

Key Features

  • History Management: Efficient history storage using ring buffer (default 100 entries)
  • Detailed Information: Type-specific probe details (sequence, status codes, response sizes, etc.)
  • TUI Enhancements: Detail view with 'd' key, color-coded status display
  • Filtering: Dynamic filtering with 'f' key
  • Interface: MetricsReader interface for read-only access

Technical Changes

  • New files: internal/stats/history.go, internal/stats/interface.go, internal/prober/details.go
  • Enhanced all probers (ICMP, HTTP, DNS, NTP, TCP) with detail collection
  • Added history size configuration and management to MetricsManager
  • Integrated detail view and filtering into TUI

Test Coverage

  • Unit tests for history functionality (internal/stats/history_test.go)
  • Ring buffer behavior verification
  • Success rate calculation and consecutive failure/success counting tests

Breaking Changes

  • Changed default sort key from Success to Fail (shows failures first)
  • Added SortByWithReader method to support MetricsReader interface

servak added 7 commits July 7, 2025 22:51
…rchitecture

- Implement ring buffer-based history management for each target
- Add detailed probe information collection for all probe types (ICMP, HTTP, DNS, NTP)
- Refactor stats module to use interface-based design for better abstraction
- Enhance probe details with protocol-specific information:
  * ICMP: sequence, TTL, data size
  * HTTP: status code, response size, headers, redirects
  * DNS: response code, answer count, server details
  * NTP: stratum, time offset, precision
  * TCP: connection-only verification (no additional details)
- Add MetricsReader interface to decouple UI from internal implementation
- Extend history functionality with consecutive failure/success tracking
- Add success rate calculation within specified time periods
- Update TUI components to use interface-based metrics access
- Maintain backward compatibility for existing functionality

This enhancement enables advanced monitoring capabilities including trend analysis,
detailed probe diagnostics, and improved failure pattern detection.
- Add 'v' key toggle for showing/hiding detailed host information panel
- Implement 2-pane layout: host list (left) + detail panel (right)
- Display probe history (last 10 entries) with timestamps and probe-specific details
- Show basic statistics: RTT metrics, success/failure counts, packet loss
- Support all probe types: ICMP (seq/ttl/size), HTTP (status/size), DNS (code/answers), NTP (stratum/offset), TCP (connection)
- Fix TCP detail display issue by passing metrics objects directly instead of hostname strings
- Default to single-pane view for simplicity, toggle detail view on demand
- Remove redundant host name from detail view content (already shown in title bar)
- Display error messages in history Details column for failed probes
- Fix ICMP details to show only implemented fields (seq, size) instead of unimplemented TTL
- Add fallback probe type labels when detailed information is unavailable
- Simplify DNS details display by removing server information for cleaner layout
- Enhance history readability with context-aware Details column (errors vs probe specifics)
- Fix infinite loop when applying filters by removing immediate Update() call
- Add selection change detection to prevent redundant callback executions
- Simplify DNS details format by removing redundant domain/server information
- Add first DNS answer value display with configurable truncation (35 chars)
- Improve protocol indication (TCP only when used, UDP implied by absence)
- Extract DNS answer parsing logic into dedicated function for reusability
- Color-code basic statistics with status-aware colors:
  * Success count: green (with data) / red (zero)
  * Failed count: red (with failures) / white (zero)
  * Loss rate: green (<10%) / yellow (10-50%) / red (>50%)
  * Labels: consistent cyan coloring
- Enhance history section with visual hierarchy:
  * Section titles in yellow for prominence
  * Headers in cyan for structure
  * Timestamps in gray for subtlety
  * Status indicators: green (OK) / red (FAIL)
  * Error messages highlighted in red
- Improve overall readability and instant problem identification
- Updated metrics sorting logic to use `stats.Fail` instead of `stats.Success`
  to highlight failing endpoints by default.
- Updated UI state default `sortKey` to `stats.Fail` and changed `ascending`
  to `false` to show most problematic rows at the top.
- Adjusted `ToGoPrettyTable` to handle wide character rendering correctly by
  disabling East Asian width override with `text.OverrideRuneWidthEastAsianWidth(false)`.
- Minor formatting improvements in `ToTviewTable()` for consistent code style.
- Fix type conversion issues in test files to use MetricsReader interface
- Update test expectations to match color-coded formatter output
- Fix default sort key test to use Fail instead of Success
- Ensure all tests pass with new interface implementation
@servak servak force-pushed the feature/stats-history-enhancement branch from ff0920e to 04346f5 Compare July 7, 2025 22:29
servak added 6 commits July 8, 2025 08:49
- Replace all Japanese comments with clear English equivalents
- Update comments in prober package (details.go, dns.go, http.go, icmp.go, ntp.go, tcp.go)
- Update comments in stats package (history.go, interface.go, manager.go, metric.go, history_test.go)
- Maintain original meaning and context in all translations
- Fix minor ICMP variable naming issues discovered during translation
- All functionality remains unchanged, only comment language updated
- Remove unnecessary fields from ICMPDetails (TTL, ID, DataSize, SourceIP, PayloadMatch)
- Add actual payload content display with formatted output (max 32 chars)
- Remove ICMP Packet Details section from Host Details view
- Simplify Recent History display with essential packet information
- Update tests to reflect simplified structure

This change focuses on showing only the most relevant ICMP information
while maintaining detailed packet analysis in the Recent History section.
- Fix v key showing "Select a host to view details" by adding GetSelectedMetrics() method
- Add selection synchronization in showDetailView() to display current host details
- Add border containers to both Host List and Host Details panels
- Update panel architecture to use Flex containers with borders
- Fix test expectations for container-based panel architecture
… dependencies

- Split MetricsManagerInterface into focused interfaces:
  - BasicMetrics: Basic statistics for display/sorting
  - DetailedMetrics: Extended metrics with history
  - MetricsProvider: External API for metrics access
  - MetricsSystemManager: System-level operations
  - MetricsEventRecorder: Internal event recording

- Replace concrete *stats.MetricsManager with appropriate interfaces:
  - UI components now use MetricsProvider interface
  - Command layer uses MetricsManagerInterface
  - Each component only depends on methods it actually uses

- Update MetricsManager implementation:
  - Separate internal getMetrics() from external GetMetrics()
  - Update method signatures to match interface contracts
  - Maintain backward compatibility with MetricsManagerInterface

This change improves code maintainability by enforcing interface segregation
principle and reducing coupling between components.
Phase 3-6 final optimization:
- Remove unused interface methods (GetHistorySince, GetAllTargets, etc.)
- Consolidate MetricsReader and DetailedMetrics interfaces
- Eliminate unused dependencies in HostDetailPanel
- Optimize interface usage in setupPanels to use MetricsProvider
- Simplify method name: SortByWithReader → SortBy

Interface cleanup results:
- BasicMetrics: 12 methods (core statistics)
- MetricsReader: 16 methods (BasicMetrics + history/analysis)
- MetricsProvider: 2 methods (SortBy, GetMetrics)
- MetricsSystemManager: 1 method (ResetAllMetrics)
- MetricsEventRecorder: 3 methods (Success, Failed, Sent)
- MetricsManagerInterface: Clean composition of above interfaces

This completes the interface segregation principle implementation,
removes dead code, and provides cleaner, more intuitive method names
while maintaining full backward compatibility.
- Update metric_test.go to use Getter methods instead of direct field access
- Replace stats.MetricsReader with stats.Metrics interface in test files
- Fix type assertions and method calls to work with new interface structure
- All tests now pass after interface refactoring
@servak servak merged commit 0f4a9d4 into main Jul 11, 2025
4 checks passed
@servak servak deleted the feature/stats-history-enhancement branch July 11, 2025 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant