Skip to content

Commit

Permalink
Merge pull request #40 from manu844/getter-func-latency
Browse files Browse the repository at this point in the history
latency distribution for local gets per galaxy using GetterFunc
  • Loading branch information
dfinkel committed Feb 7, 2023
2 parents 6de18ea + edfff15 commit f7799df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions galaxycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
g.recordStats(ctx, nil, MGetterFuncLatencyMilliseconds.M(sinceInMilliseconds(startTime)))
}()
err := g.getter.Get(ctx, key, dest)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f7799df

Please sign in to comment.