Repository navigation
Expand file tree
/
Copy pathlogging.go
More file actions
85 lines (72 loc) · 2.65 KB
/
Copy pathlogging.go
File metadata and controls
85 lines (72 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"time"
)
// Logger represents a consistency test logger
type Logger struct {
testName string
opts Opts
}
// Opts represents options for consistency tests
type Opts struct {
ID string
Region []string
}
// Start creates a new consistency log
func Start(testName string, opts Opts) *Logger {
fmt.Printf("\n%s%s%s\n", ColorBrightWhite, testName, ColorReset)
return &Logger{
testName: testName,
opts: opts,
}
}
// Successf logs a success message
func (c *Logger) Successf(duration time.Duration, format string, args ...interface{}) {
fmt.Printf(" %sSUCCESS%s - %s (%s%s%s)\n\n",
ColorBrightGreen, ColorReset,
fmt.Sprintf(format, args...),
ColorBrightWhite, formatDuration(duration), ColorReset)
}
// Failf logs a failure message
func (c *Logger) Failf(format string, args ...interface{}) {
fmt.Printf(" %sFAILED%s - %s\n",
ColorBrightRed, ColorReset,
fmt.Sprintf(format, args...))
}
// Infof logs an info message
func (c *Logger) Infof(format string, args ...interface{}) {
fmt.Printf(" INFO - %s\n",
fmt.Sprintf(format, args...))
}
// SuccessAfterf logs a success message after attempts
func (c *Logger) SuccessAfterf(attempts int, duration time.Duration, format string, args ...interface{}) {
fmt.Printf(" %sSUCCESS%s - %s (attempts: %s%d%s, %s%s%s)\n\n",
ColorBrightGreen, ColorReset,
fmt.Sprintf(format, args...),
ColorBrightWhite, attempts, ColorReset,
ColorBrightWhite, formatDuration(duration), ColorReset)
}
// StatsSummaryf logs aggregated statistics
func (c *Logger) StatsSummaryf(sourceRegion, targetRegion string, stats ConvergenceStats) {
immediatePercent := 0.0
eventualPercent := 0.0
timeoutPercent := 0.0
if stats.Iterations > 0 {
immediatePercent = float64(stats.ImmediateCount) * 100.0 / float64(stats.Iterations)
eventualPercent = float64(stats.EventualCount) * 100.0 / float64(stats.Iterations)
timeoutPercent = float64(stats.TimeoutCount) * 100.0 / float64(stats.Iterations)
}
fmt.Printf(" %s%s -> %s%s (%d iterations)\n",
ColorYellow, getRegionDisplayName(sourceRegion), getRegionDisplayName(targetRegion), ColorReset,
stats.Iterations)
if stats.ImmediateCount+stats.EventualCount > 0 {
fmt.Printf(" Convergence - Avg: %s%8s%s, P50: %s%8s%s, P95: %s%8s%s, P99: %s%8s%s\n",
ColorBrightWhite, formatDuration(stats.AvgTime), ColorReset,
ColorBrightWhite, formatDuration(stats.P50Time), ColorReset,
ColorBrightWhite, formatDuration(stats.P95Time), ColorReset,
ColorBrightWhite, formatDuration(stats.P99Time), ColorReset)
}
fmt.Printf(" Distribution - Immediate: %5.1f%%, Eventual: %5.1f%%, Timeout: %5.1f%%\n",
immediatePercent, eventualPercent, timeoutPercent)
}