Skip to content

Commit 1ec06ad

Browse files
author
Beykan Şen
committed
Add slim docker image.
1 parent f0f779b commit 1ec06ad

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

main.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ func main() {
6464
}
6565

6666
func collectMetrics() {
67-
for {
68-
rand.Seed(time.Now().UnixNano())
67+
iteration := func() {
6968
if result, err := runSpeedTest(); err != nil {
7069
atomic.AddUint64(&errorCount, 1)
7170
if errorCount > fatalErrorCountThreshold {
@@ -78,12 +77,14 @@ func collectMetrics() {
7877
jitter.WithLabelValues(hostname).Set(result.Jitter)
7978
latency.WithLabelValues(hostname).Set(result.Latency)
8079

81-
if len(strings.TrimSpace(args.CallbackUrl)) > 0 {
82-
if err := pkg.Callback(args.CallbackUrl, result); err != nil {
83-
log.Printf("Got error while callback %s\n", err.Error())
84-
}
80+
if err := pkg.Callback(args.CallbackUrl, result); err != nil {
81+
log.Printf("Got error while callback %s\n", err.Error())
8582
}
8683
}
84+
}
85+
for {
86+
iteration()
87+
rand.Seed(time.Now().UnixNano())
8788
time.Sleep(time.Duration(args.Interval)*time.Minute + time.Duration(rand.Intn(120))*time.Second)
8889
}
8990
}

pkg/callback_service.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package pkg
22

33
import (
44
"encoding/json"
5+
"strings"
56
"time"
67

78
"github.com/valyala/fasthttp"
89
)
910

1011
func Callback(url string, result *Result) error {
12+
if len(strings.TrimSpace(url)) == 0 {
13+
return nil
14+
}
1115
req := fasthttp.AcquireRequest()
1216
defer fasthttp.ReleaseRequest(req)
1317
resp := fasthttp.AcquireResponse()

0 commit comments

Comments
 (0)