From 655e348870712280eac03d9e32d027e74c119ced Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 19 Jun 2025 17:00:58 +0300 Subject: Refactor: Extract magic numbers as constants and reduce client code duplication - Created internal/constants package with organized constant files: - timeouts.go: All time duration constants (timeouts, intervals, delays) - channels.go: Channel buffer size constants - limits.go: Numeric limits and configuration values - buffers.go: Buffer size constants in bytes - Replaced all magic numbers throughout codebase with named constants: - Time durations (2s, 3s, 5s, 10s, 100ms, 24h) now use descriptive constants - Buffer sizes (8KB, 64KB, 1MB) extracted to constants - Channel buffer sizes and multipliers - Configuration limits (max connections, concurrency, etc.) - Health check status codes - Percentage calculations - Reduced code duplication in client implementations: - Created CommonClient to share functionality between CatClient, GrepClient, and TailClient - All three clients now inherit from CommonClient - Eliminated duplicate makeHandler() and makeCommands() methods - Simplified client constructors This refactoring improves code maintainability by centralizing configuration values and reducing redundant code across similar client implementations. --- internal/io/fs/aggregateprocessor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'internal/io/fs/aggregateprocessor.go') diff --git a/internal/io/fs/aggregateprocessor.go b/internal/io/fs/aggregateprocessor.go index 98d0c31..809f298 100644 --- a/internal/io/fs/aggregateprocessor.go +++ b/internal/io/fs/aggregateprocessor.go @@ -5,6 +5,7 @@ import ( "context" "time" + "github.com/mimecast/dtail/internal/constants" "github.com/mimecast/dtail/internal/io/line" "github.com/mimecast/dtail/internal/lcontext" "github.com/mimecast/dtail/internal/regex" @@ -69,7 +70,7 @@ func (p *AggregateLineProcessor) Flush() []byte { if !p.isTailing { // Close the lines channel to signal end of input // Add a small delay to ensure all lines are processed before closing - time.Sleep(10 * time.Millisecond) + time.Sleep(constants.ProcessorSleepDuration) close(p.linesCh) } return nil -- cgit v1.2.3