Cleanup
This commit is contained in:
parent
4b2007d3d9
commit
694dab9295
|
@ -17,7 +17,6 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/modules/keyvalue"
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -142,22 +141,3 @@ func GetCount(key string) (count int64, err error) {
|
||||||
func SetCount(count int64, key string) error {
|
func SetCount(count int64, key string) error {
|
||||||
return keyvalue.Put(key, count)
|
return keyvalue.Put(key, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateCount updates a count with a given amount
|
|
||||||
func UpdateCount(update int64, key string) {
|
|
||||||
if !config.ServiceEnableMetrics.GetBool() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if update > 0 {
|
|
||||||
err := keyvalue.IncrBy(key, update)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if update < 0 {
|
|
||||||
err := keyvalue.DecrBy(key, update*-1)
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/events"
|
"code.vikunja.io/api/pkg/events"
|
||||||
"code.vikunja.io/api/pkg/metrics"
|
"code.vikunja.io/api/pkg/metrics"
|
||||||
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
"github.com/ThreeDotsLabs/watermill/message"
|
"github.com/ThreeDotsLabs/watermill/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,8 +48,7 @@ func (s *IncreaseTaskCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event IncreaseTaskCounter listens on is fired
|
// Hanlde is executed when the event IncreaseTaskCounter listens on is fired
|
||||||
func (s *IncreaseTaskCounter) Handle(payload message.Payload) (err error) {
|
func (s *IncreaseTaskCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(1, metrics.TaskCountKey)
|
return keyvalue.IncrBy(metrics.TaskCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecreaseTaskCounter represents a listener
|
// DecreaseTaskCounter represents a listener
|
||||||
|
@ -62,8 +62,7 @@ func (s *DecreaseTaskCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event DecreaseTaskCounter listens on is fired
|
// Hanlde is executed when the event DecreaseTaskCounter listens on is fired
|
||||||
func (s *DecreaseTaskCounter) Handle(payload message.Payload) (err error) {
|
func (s *DecreaseTaskCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(-1, metrics.TaskCountKey)
|
return keyvalue.DecrBy(metrics.TaskCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////
|
///////
|
||||||
|
@ -77,8 +76,7 @@ func (s *IncreaseListCounter) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *IncreaseListCounter) Handle(payload message.Payload) (err error) {
|
func (s *IncreaseListCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(1, metrics.ListCountKey)
|
return keyvalue.IncrBy(metrics.ListCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DecreaseListCounter struct {
|
type DecreaseListCounter struct {
|
||||||
|
@ -89,8 +87,7 @@ func (s *DecreaseListCounter) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DecreaseListCounter) Handle(payload message.Payload) (err error) {
|
func (s *DecreaseListCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(-1, metrics.ListCountKey)
|
return keyvalue.DecrBy(metrics.ListCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
//////
|
||||||
|
@ -107,8 +104,7 @@ func (s *IncreaseNamespaceCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event IncreaseNamespaceCounter listens on is fired
|
// Hanlde is executed when the event IncreaseNamespaceCounter listens on is fired
|
||||||
func (s *IncreaseNamespaceCounter) Handle(payload message.Payload) (err error) {
|
func (s *IncreaseNamespaceCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(1, metrics.NamespaceCountKey)
|
return keyvalue.IncrBy(metrics.NamespaceCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecreaseNamespaceCounter represents a listener
|
// DecreaseNamespaceCounter represents a listener
|
||||||
|
@ -122,8 +118,7 @@ func (s *DecreaseNamespaceCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event DecreaseNamespaceCounter listens on is fired
|
// Hanlde is executed when the event DecreaseNamespaceCounter listens on is fired
|
||||||
func (s *DecreaseNamespaceCounter) Handle(payload message.Payload) (err error) {
|
func (s *DecreaseNamespaceCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(-1, metrics.NamespaceCountKey)
|
return keyvalue.DecrBy(metrics.NamespaceCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////
|
///////
|
||||||
|
@ -140,8 +135,7 @@ func (s *IncreaseTeamCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event IncreaseTeamCounter listens on is fired
|
// Hanlde is executed when the event IncreaseTeamCounter listens on is fired
|
||||||
func (s *IncreaseTeamCounter) Handle(payload message.Payload) (err error) {
|
func (s *IncreaseTeamCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(1, metrics.TeamCountKey)
|
return keyvalue.IncrBy(metrics.TeamCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecreaseTeamCounter represents a listener
|
// DecreaseTeamCounter represents a listener
|
||||||
|
@ -155,6 +149,5 @@ func (s *DecreaseTeamCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event DecreaseTeamCounter listens on is fired
|
// Hanlde is executed when the event DecreaseTeamCounter listens on is fired
|
||||||
func (s *DecreaseTeamCounter) Handle(payload message.Payload) (err error) {
|
func (s *DecreaseTeamCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(-1, metrics.TeamCountKey)
|
return keyvalue.DecrBy(metrics.TeamCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package user
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/events"
|
"code.vikunja.io/api/pkg/events"
|
||||||
"code.vikunja.io/api/pkg/metrics"
|
"code.vikunja.io/api/pkg/metrics"
|
||||||
|
"code.vikunja.io/api/pkg/modules/keyvalue"
|
||||||
"github.com/ThreeDotsLabs/watermill/message"
|
"github.com/ThreeDotsLabs/watermill/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,6 +41,5 @@ func (s *IncreaseUserCounter) Name() string {
|
||||||
|
|
||||||
// Hanlde is executed when the event IncreaseUserCounter listens on is fired
|
// Hanlde is executed when the event IncreaseUserCounter listens on is fired
|
||||||
func (s *IncreaseUserCounter) Handle(payload message.Payload) (err error) {
|
func (s *IncreaseUserCounter) Handle(payload message.Payload) (err error) {
|
||||||
metrics.UpdateCount(1, metrics.UserCountKey)
|
return keyvalue.IncrBy(metrics.UserCountKey, 1)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue