Last active
February 25, 2020 10:33
-
-
Save narqo/d232def0c707e745e8f2c67de71e4ddd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pkg/svc | |
type SettingsService struct { | |
db DB // DB is an interface | |
} | |
func (svc *SettingsService) IsProCustomer(token Token) bool { | |
v := svc.db.GetProCustomer(makeProPKFromToken(token)) | |
return v == "1" | |
} | |
// pkg/db/kv | |
type KV struct { | |
remoteDB RemoteDBaaSClient | |
cache Cache | |
pubsub PubSub // pubsub invalidates local cache on set operations | |
} | |
// KV implements DB interface | |
var _ DB = (*KV)(nil) | |
func (db *KV) GetProCustomer(pk) string { | |
if v, ok := db.cache.Get(···); ok { | |
return v | |
} | |
db.remoteDB.Get(···) | |
/* get foo via DBaaS client, put value into cache, return value */ | |
} | |
// pkg/pubsub | |
type PubSub struct {···} | |
// vendor/cache | |
type Cache struct { | |
getOpDuration prometheus.Histogram // cache_get_duration_seconds | |
} | |
func (cache *Cache) Get(k string) (string, bool) { | |
defer func(t time.Time) { | |
getOpDuration.WithLabelValues(···).Observe(time.Since(t)) | |
}(time.Now()) | |
/* ··· */ | |
} | |
// How to re-implement it so we could filter cache's metrics by "svc" or by "db implementation". | |
// I.e. to have the "<host>.<application>.settings-svc.kv.cache.get.duration-seconds" metrics. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment