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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
const (
binaryName = "epimetheus"
mainPath = "./cmd/epimetheus"
)
// Default target to run when none is specified
var Default = Build
// Build compiles the epimetheus binary
func Build() error {
fmt.Println("Building epimetheus...")
return sh.RunV("go", "build", "-o", binaryName, mainPath)
}
// Install installs the binary to $GOPATH/bin
func Install() error {
fmt.Println("Installing epimetheus...")
return sh.RunV("go", "install", mainPath)
}
// Run executes the epimetheus binary in realtime mode
func Run() error {
mg.Deps(Build)
fmt.Println("Running epimetheus in realtime mode...")
return sh.RunV("./"+binaryName, "-mode=realtime", "-continuous")
}
// RunHistoric runs epimetheus in historic mode
func RunHistoric() error {
mg.Deps(Build)
fmt.Println("Running epimetheus in historic mode (24 hours ago)...")
return sh.RunV("./"+binaryName, "-mode=historic", "-hours-ago=24")
}
// RunAuto runs epimetheus in auto mode with a file
func RunAuto(file string) error {
mg.Deps(Build)
if file == "" {
return fmt.Errorf("file parameter required: mage RunAuto <file>")
}
fmt.Printf("Running epimetheus in auto mode with file: %s\n", file)
return sh.RunV("./"+binaryName, "-mode=auto", "-file="+file)
}
// RunWatchClickHouse runs epimetheus in watch mode with ClickHouse ingestion
func RunWatchClickHouse(file string) error {
mg.Deps(Build)
if file == "" {
file = "test-data/watch-clickhouse-test.csv"
}
fmt.Printf("Running epimetheus in watch mode with ClickHouse (file: %s)\n", file)
return sh.RunV("./"+binaryName, "-mode=watch", "-file="+file, "-metric-name=watch_test",
"-clickhouse=http://localhost:8123", "-prometheus=")
}
// Test runs all tests
func Test() error {
fmt.Println("Running tests...")
return sh.RunV("go", "test", "./...", "-v")
}
// TestCoverage runs tests with coverage report
func TestCoverage() error {
fmt.Println("Running tests with coverage...")
if err := sh.RunV("go", "test", "./...", "-cover", "-coverprofile=coverage.out"); err != nil {
return err
}
return sh.RunV("go", "tool", "cover", "-html=coverage.out", "-o", "coverage.html")
}
// TestRace runs tests with race detector
func TestRace() error {
fmt.Println("Running tests with race detector...")
return sh.RunV("go", "test", "./...", "-race", "-v")
}
// Benchmark runs all benchmarks
func Benchmark() error {
fmt.Println("Running benchmarks...")
return sh.RunV("go", "test", "./...", "-bench=.", "-benchmem")
}
// Lint runs golangci-lint
func Lint() error {
fmt.Println("Running linter...")
return sh.RunV("golangci-lint", "run", "./...")
}
// Fmt formats all Go code
func Fmt() error {
fmt.Println("Formatting code...")
return sh.RunV("go", "fmt", "./...")
}
// Vet runs go vet
func Vet() error {
fmt.Println("Running go vet...")
return sh.RunV("go", "vet", "./...")
}
// Tidy runs go mod tidy
func Tidy() error {
fmt.Println("Tidying dependencies...")
return sh.RunV("go", "mod", "tidy")
}
// Clean removes build artifacts
func Clean() error {
fmt.Println("Cleaning build artifacts...")
files := []string{
binaryName,
"coverage.out",
"coverage.html",
}
for _, f := range files {
if err := sh.Rm(f); err != nil && !os.IsNotExist(err) {
return err
}
}
return nil
}
// Generate runs go generate
func Generate() error {
fmt.Println("Running go generate...")
return sh.RunV("go", "generate", "./...")
}
// Version prints the version
func Version() error {
fmt.Println("Printing version...")
mg.Deps(Build)
return sh.RunV("./"+binaryName, "-version")
}
// All runs format, vet, test, and build
func All() {
mg.Deps(Fmt, Vet, Test, Build)
}
// CI runs the full CI pipeline (format check, vet, test, build)
func CI() error {
fmt.Println("Running CI pipeline...")
mg.Deps(Tidy, Vet, Test)
return Build()
}
// Dev starts development mode with port-forwarding
func Dev() error {
mg.Deps(Build)
fmt.Println("Starting development mode...")
fmt.Println("Setting up port-forward to Pushgateway...")
// Start port-forward in background
portForwardCmd := sh.RunCmd("kubectl", "port-forward", "-n", "monitoring", "svc/pushgateway", "9091:9091")
go func() {
if err := portForwardCmd(); err != nil {
fmt.Printf("Port-forward error: %v\n", err)
}
}()
fmt.Println("Running epimetheus in realtime mode...")
return sh.RunV("./"+binaryName, "-mode=realtime", "-continuous")
}
// GenerateTestData creates test data files
func GenerateTestData() error {
fmt.Println("Generating test data...")
return sh.RunV("./scripts/generate-test-data.sh")
}
// Backfill runs backfill for the last 48 hours
func Backfill() error {
mg.Deps(Build)
fmt.Println("Running backfill (last 48 hours)...")
return sh.RunV("./"+binaryName, "-mode=backfill", "-start-hours=48", "-end-hours=0", "-interval=1")
}
// Benchmark100MB runs the 100MB benchmark
func Benchmark100MB() error {
fmt.Println("Running 100MB benchmark...")
return sh.RunV("./scripts/benchmark-100mb.sh")
}
// Benchmark1GB runs the 1GB benchmark
func Benchmark1GB() error {
fmt.Println("Running 1GB benchmark...")
return sh.RunV("./scripts/benchmark-1gb.sh")
}
// CleanupBenchmarkData removes benchmark data from Prometheus
func CleanupBenchmarkData() error {
fmt.Println("Cleaning up benchmark data...")
return sh.RunV("./scripts/cleanup-benchmark-data.sh")
}
// CleanupBenchmarkMetrics removes benchmark metric files
func CleanupBenchmarkMetrics() error {
fmt.Println("Cleaning up benchmark metric files...")
return sh.RunV("./scripts/cleanup-benchmark-metrics.sh")
}
// DeployDashboard deploys the Grafana dashboard
func DeployDashboard() error {
fmt.Println("Deploying Grafana dashboard...")
return sh.RunV("./scripts/deploy-dashboard.sh")
}
// Help prints available targets
func Help() {
fmt.Println("Available targets:")
fmt.Println(" build - Build the epimetheus binary (default)")
fmt.Println(" install - Install the binary to $GOPATH/bin")
fmt.Println(" run - Build and run in realtime mode")
fmt.Println(" runHistoric - Build and run in historic mode")
fmt.Println(" runAuto <file> - Build and run in auto mode with file")
fmt.Println(" runWatchClickHouse [file] - Build and run watch mode with ClickHouse (default: test-data/watch-clickhouse-test.csv)")
fmt.Println(" test - Run all tests")
fmt.Println(" testCoverage - Run tests with coverage report")
fmt.Println(" testRace - Run tests with race detector")
fmt.Println(" benchmark - Run Go benchmarks")
fmt.Println(" lint - Run golangci-lint")
fmt.Println(" fmt - Format all Go code")
fmt.Println(" vet - Run go vet")
fmt.Println(" tidy - Run go mod tidy")
fmt.Println(" clean - Remove build artifacts")
fmt.Println(" generate - Run go generate")
fmt.Println(" version - Print version")
fmt.Println(" all - Run fmt, vet, test, and build")
fmt.Println(" ci - Run full CI pipeline")
fmt.Println(" dev - Start development mode with port-forwarding")
fmt.Println(" generateTestData - Generate test data files")
fmt.Println(" backfill - Run backfill for last 48 hours")
fmt.Println(" benchmark100MB - Run 100MB benchmark")
fmt.Println(" benchmark1GB - Run 1GB benchmark")
fmt.Println(" cleanupBenchmarkData - Clean up benchmark data from Prometheus")
fmt.Println(" cleanupBenchmarkMetrics - Clean up benchmark metric files")
fmt.Println(" deployDashboard - Deploy Grafana dashboard")
fmt.Println(" help - Print this help message")
}
|