This commit is contained in:
@@ -112,6 +112,7 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) ([]byte, erro
|
|||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
message.TimeStamp = &now
|
message.TimeStamp = &now
|
||||||
}
|
}
|
||||||
|
grainMutations.Inc()
|
||||||
var err error
|
var err error
|
||||||
switch message.Type {
|
switch message.Type {
|
||||||
case AddRequestType:
|
case AddRequestType:
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ func (p *GrainLocalPool) GetGrains() map[CartId]*CartGrain {
|
|||||||
func (p *GrainLocalPool) GetGrain(id CartId) (*CartGrain, error) {
|
func (p *GrainLocalPool) GetGrain(id CartId) (*CartGrain, error) {
|
||||||
var err error
|
var err error
|
||||||
grain, ok := p.grains[id]
|
grain, ok := p.grains[id]
|
||||||
|
grainLookups.Inc()
|
||||||
if grain == nil || !ok {
|
if grain == nil || !ok {
|
||||||
if len(p.grains) >= p.PoolSize {
|
if len(p.grains) >= p.PoolSize {
|
||||||
if p.expiry[0].Expires.Before(time.Now()) {
|
if p.expiry[0].Expires.Before(time.Now()) {
|
||||||
|
|||||||
12
main.go
12
main.go
@@ -14,14 +14,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
|
grainSpawns = promauto.NewCounter(prometheus.CounterOpts{
|
||||||
Name: "cart_grain_spawned_total",
|
Name: "cart_grain_spawned_total",
|
||||||
Help: "The total number of spawned grains",
|
Help: "The total number of spawned grains",
|
||||||
})
|
})
|
||||||
|
grainMutations = promauto.NewCounter(prometheus.CounterOpts{
|
||||||
|
Name: "cart_grain_mutations_total",
|
||||||
|
Help: "The total number of mutations",
|
||||||
|
})
|
||||||
|
grainLookups = promauto.NewCounter(prometheus.CounterOpts{
|
||||||
|
Name: "cart_grain_lookups_total",
|
||||||
|
Help: "The total number of lookups",
|
||||||
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
func spawn(id CartId) (*CartGrain, error) {
|
func spawn(id CartId) (*CartGrain, error) {
|
||||||
opsProcessed.Inc()
|
grainSpawns.Inc()
|
||||||
ret := &CartGrain{
|
ret := &CartGrain{
|
||||||
Id: id,
|
Id: id,
|
||||||
Items: []CartItem{},
|
Items: []CartItem{},
|
||||||
|
|||||||
Reference in New Issue
Block a user