From 7c77d160c4e7459b144259470d1c5a1e37022394 Mon Sep 17 00:00:00 2001 From: Manohar HT Date: Mon, 6 Feb 2023 11:50:57 +0530 Subject: [PATCH 1/2] latency distribution for local gets with GetterFunc --- galaxycache.go | 4 ++++ observability.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/galaxycache.go b/galaxycache.go index ca89c913..19918ba0 100644 --- a/galaxycache.go +++ b/galaxycache.go @@ -613,6 +613,10 @@ func (g *Galaxy) load(ctx context.Context, key string, dest Codec) (value valWit } func (g *Galaxy) getLocally(ctx context.Context, key string, dest Codec) ([]byte, error) { + startTime := time.Now() + defer func() { + stats.RecordWithTags(ctx, nil, MGetterFuncLatencyMilliseconds.M(sinceInMilliseconds(startTime))) + }() err := g.getter.Get(ctx, key, dest) if err != nil { return nil, err diff --git a/observability.go b/observability.go index c1aa2522..467d9a18 100644 --- a/observability.go +++ b/observability.go @@ -55,6 +55,8 @@ var ( MCacheSize = stats.Int64("galaxycache/cache_bytes", "The number of bytes used for storing Keys and Values in the cache", stats.UnitBytes) MCacheEntries = stats.Int64("galaxycache/cache_entries", "The number of entries in the cache", stats.UnitDimensionless) + + MGetterFuncLatencyMilliseconds = stats.Float64("galaxycache/getterfunc_latency", "Local getter function latency in milliseconds", stats.UnitMilliseconds) ) var ( @@ -90,6 +92,8 @@ var AllViews = []*view.View{ {Measure: MRoundtripLatencyMilliseconds, TagKeys: []tag.Key{GalaxyKey}, Aggregation: defaultMillisecondsDistribution}, {Measure: MCacheSize, TagKeys: []tag.Key{GalaxyKey, CacheTypeKey}, Aggregation: view.LastValue()}, {Measure: MCacheEntries, TagKeys: []tag.Key{GalaxyKey, CacheTypeKey}, Aggregation: view.LastValue()}, + + {Measure: MGetterFuncLatencyMilliseconds, TagKeys: []tag.Key{GalaxyKey}, Aggregation: defaultMillisecondsDistribution}, } func sinceInMilliseconds(start time.Time) float64 { From edfff156f1650d7768f6b26550978015c0c08904 Mon Sep 17 00:00:00 2001 From: Manohar HT Date: Mon, 6 Feb 2023 11:55:29 +0530 Subject: [PATCH 2/2] use recordStats method. --- galaxycache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxycache.go b/galaxycache.go index 19918ba0..fdfdb646 100644 --- a/galaxycache.go +++ b/galaxycache.go @@ -615,7 +615,7 @@ func (g *Galaxy) load(ctx context.Context, key string, dest Codec) (value valWit func (g *Galaxy) getLocally(ctx context.Context, key string, dest Codec) ([]byte, error) { startTime := time.Now() defer func() { - stats.RecordWithTags(ctx, nil, MGetterFuncLatencyMilliseconds.M(sinceInMilliseconds(startTime))) + g.recordStats(ctx, nil, MGetterFuncLatencyMilliseconds.M(sinceInMilliseconds(startTime))) }() err := g.getter.Get(ctx, key, dest) if err != nil {