From cdce03ca1cc026610c8ab5e80172324b4b684ba9 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 8 Nov 2021 11:24:01 +0100 Subject: [PATCH] feat: Add more log --- Makefile | 6 +++++- cmd/aggregator/main.go | 2 +- telemetry/aggregator.go | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6968f7b..584467f 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,8 @@ lint: @golangci-lint --exclude=SA1019 run ./... --deadline=5m test: - go test -v -failfast ./... \ No newline at end of file + go test -v -failfast ./... + +build: + go build -o ./build/server ./cmd/server/main.go + go build -o ./build/aggregator ./cmd/aggregator/main.go \ No newline at end of file diff --git a/cmd/aggregator/main.go b/cmd/aggregator/main.go index d2f2e2e..eaa48c9 100644 --- a/cmd/aggregator/main.go +++ b/cmd/aggregator/main.go @@ -17,5 +17,5 @@ func main() { defer db.Close() aggregator := telemetry.NewAggregator(db) - aggregator.Run(time.Duration(*seconds)) + aggregator.Run(time.Duration(*seconds) * time.Second) } diff --git a/telemetry/aggregator.go b/telemetry/aggregator.go index 5932722..875aaf4 100644 --- a/telemetry/aggregator.go +++ b/telemetry/aggregator.go @@ -17,6 +17,7 @@ func NewAggregator(db *sql.DB) *Aggregator { } func (a *Aggregator) Run(d time.Duration) { + log.Printf("started aggregator for %s\n", d) // Define the duration starts and end. // Allow a buffer of the duration to define the start and end. // This is to ensure we wait for people not being connected or if they received messages with delay @@ -63,6 +64,7 @@ func (a *Aggregator) Run(d time.Duration) { } if len(groupedMessages) == 0 { + log.Println("no record found, finishing early") return } @@ -103,6 +105,7 @@ func (a *Aggregator) Run(d time.Duration) { log.Fatalf("could not store received message aggregated: %s", err) } } + log.Printf("stored %d chat id records", len(rChatID)) // Calculate the global reliability R = (R(0) + R(1)+ .... + R(n)) / len(Rch) rChatIDTotal := 0.0 @@ -121,4 +124,5 @@ func (a *Aggregator) Run(d time.Duration) { if err != nil { log.Fatalf("could not store received message aggregated: %s", err) } + log.Printf("finished aggregator for %s\n", d) }