Skip to content

Commit

Permalink
Registry prometheus grpc unary server interceptor; set prometheus nam…
Browse files Browse the repository at this point in the history
…espace for flipt metrics
  • Loading branch information
markphelps committed Jul 7, 2019
1 parent c12f80b commit 9a1efed
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func execute() error {
grpcOpts = append(grpcOpts, grpc_middleware.WithUnaryServerChain(
grpc_ctxtags.UnaryServerInterceptor(),
grpc_logrus.UnaryServerInterceptor(logger),
grpc_prometheus.UnaryServerInterceptor,
srv.ErrorUnaryInterceptor,
grpc_recovery.UnaryServerInterceptor(),
))
Expand Down
2 changes: 1 addition & 1 deletion config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ log:

# server:
# host: 0.0.0.0
# http_port: 8000
# http_port: 8080
# grpc_port: 9000

db:
Expand Down
2 changes: 1 addition & 1 deletion config/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ log:

# server:
# host: 0.0.0.0
# http_port: 8000
# http_port: 8080
# grpc_port: 9000

db:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.9.3

github.com/hashicorp/golang-lru v0.5.1
github.com/hashicorp/golang-lru v0.5.1
github.com/lib/pq v1.1.1
github.com/markphelps/flipt-grpc-go v0.0.0-20190303144529-3ebb133e62c0
github.com/mattn/go-colorable v0.0.9 // indirect
Expand Down
14 changes: 8 additions & 6 deletions storage/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ var ErrCacheCorrupt = errors.New("cache corrupted")

// Prometheus variables used throughout the cache package
var (
CacheHitTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cache_hit_total",
Help: "The total number of cache hits",
cacheHitTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "flipt",
Name: "cache_hit_total",
Help: "The total number of cache hits",
}, []string{"type", "cache"})

CacheMissTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cache_miss_total",
Help: "The total number of cache misses",
cacheMissTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "flipt",
Name: "cache_miss_total",
Help: "The total number of cache misses",
}, []string{"type", "cache"})
)

Expand Down
4 changes: 2 additions & 2 deletions storage/cache/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (f *FlagCache) GetFlag(ctx context.Context, r *flipt.GetFlagRequest) (*flip
// check if flag exists in cache
if data, ok := f.cache.Get(key); ok {
f.logger.Debugf("cache hit: %q", key)
CacheHitTotal.WithLabelValues("flag", "memory").Inc()
cacheHitTotal.WithLabelValues("flag", "memory").Inc()
bytes, bok := data.([]byte)
if !bok {
// not bytes, bad cache
Expand Down Expand Up @@ -67,7 +67,7 @@ func (f *FlagCache) GetFlag(ctx context.Context, r *flipt.GetFlagRequest) (*flip

_ = f.cache.Add(flagCacheKey(r.Key), data)
f.logger.Debugf("cache miss; added: %q", key)
CacheMissTotal.WithLabelValues("flag", "memory").Inc()
cacheMissTotal.WithLabelValues("flag", "memory").Inc()
return flag, nil
}

Expand Down

0 comments on commit 9a1efed

Please sign in to comment.