From 3081338a371c0786c88a86849312c0514104aee7 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 19 Jan 2020 17:26:26 +0000 Subject: [PATCH] Use redis INCRBY and DECRBY when updating metrics values (#121) Move test coverage processing to a seperate command Use redis INCRBY and DECRBY when updating metrics values Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/api/pulls/121 --- Makefile | 3 +++ go.mod | 1 + pkg/metrics/metrics.go | 17 ++++++++++------- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7728f76c261..f3ba1865cdb 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,9 @@ clean: .PHONY: test test: VIKUNJA_SERVICE_ROOTPATH=$(shell pwd) go test $(GOFLAGS) -cover -coverprofile cover.out $(PACKAGES) + +.PHONY: test-coverage +test-coverage: test go tool cover -html=cover.out -o cover.html .PHONY: integration-test diff --git a/go.mod b/go.mod index b1a8ffc57f0..2b304391909 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( github.com/onsi/gomega v1.4.3 // indirect github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/pelletier/go-toml v1.4.0 // indirect + github.com/pkg/errors v0.8.1 // indirect github.com/prometheus/client_golang v0.9.2 github.com/samedi/caldav-go v3.0.0+incompatible github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index efd33fec98e..5287ed4b7cc 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -115,13 +115,16 @@ func UpdateCount(update int64, key string) { if !config.ServiceEnableMetrics.GetBool() { return } - oldtotal, err := GetCount(key) - if err != nil { - log.Error(err.Error()) + if update > 0 { + err := r.IncrBy(key, update).Err() + if err != nil { + log.Error(err.Error()) + } } - - err = SetCount(oldtotal+update, key) - if err != nil { - log.Error(err.Error()) + if update < 0 { + err := r.DecrBy(key, update).Err() + if err != nil { + log.Error(err.Error()) + } } }