summaryrefslogtreecommitdiff
path: root/internal/io/fs/tailprocessor.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-19 17:00:58 +0300
committerPaul Buetow <paul@buetow.org>2025-06-19 17:00:58 +0300
commit655e348870712280eac03d9e32d027e74c119ced (patch)
treefe9546bf96e0d8d7a30d87d7d4936dc4bea31ca8 /internal/io/fs/tailprocessor.go
parent0234fbac3490ccf2b9dca36292ad6459e990e0f5 (diff)
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.
Diffstat (limited to 'internal/io/fs/tailprocessor.go')
-rw-r--r--internal/io/fs/tailprocessor.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/io/fs/tailprocessor.go b/internal/io/fs/tailprocessor.go
index 3bc9029..55934ce 100644
--- a/internal/io/fs/tailprocessor.go
+++ b/internal/io/fs/tailprocessor.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/constants"
"github.com/mimecast/dtail/internal/lcontext"
"github.com/mimecast/dtail/internal/regex"
)
@@ -163,7 +164,7 @@ func (ftp *FollowingTailProcessor) followFile(ctx context.Context, filePath stri
func (ftp *FollowingTailProcessor) followReader(ctx context.Context, file *os.File, filePath string) error {
// Set buffer size respecting MaxLineLength configuration
maxLineLength := config.Server.MaxLineLength
- initialBufSize := 64 * 1024
+ initialBufSize := constants.InitialBufferSize
if maxLineLength < initialBufSize {
initialBufSize = maxLineLength
}
@@ -259,7 +260,7 @@ func (ftp *FollowingTailProcessor) followReader(ctx context.Context, file *os.Fi
select {
case <-ctx.Done():
return ctx.Err()
- case <-time.After(100 * time.Millisecond):
+ case <-time.After(constants.ProcessorTimeoutDuration):
// Continue the loop to check for new content
}
}