Cleanup metrics
Consolidated error metrics into a vector counter with a label, removed other uneeded counters.
This commit is contained in:
parent
a27b6e730d
commit
45e9817ced
3 changed files with 13 additions and 52 deletions
|
@ -1,7 +1,6 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lbryio/hub/meta"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
@ -13,46 +12,11 @@ var (
|
||||||
Name: "requests_count",
|
Name: "requests_count",
|
||||||
Help: "Total number of searches",
|
Help: "Total number of searches",
|
||||||
}, []string{"method"})
|
}, []string{"method"})
|
||||||
SessionCount = promauto.NewGauge(prometheus.GaugeOpts{
|
|
||||||
Name: "session_count",
|
|
||||||
Help: "Number of client sessions",
|
|
||||||
ConstLabels: map[string]string{
|
|
||||||
"version": meta.Version,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
// These are unique to the go code
|
// These are unique to the go code
|
||||||
PingsCounter = promauto.NewCounter(prometheus.CounterOpts{
|
ErrorsCounter = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Name: "pings",
|
Name: "errors",
|
||||||
Help: "Number of pings",
|
Help: "Number of errors by type",
|
||||||
})
|
}, []string{"error_type"})
|
||||||
ZeroChannelsCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "zero_channels_counter",
|
|
||||||
Help: "Number of times zero channels were returned in getUniqueChannels",
|
|
||||||
})
|
|
||||||
NoRepostedCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "no_reposted_counter",
|
|
||||||
Help: "Number of times zero reposted were returned in getClaimsForRepost",
|
|
||||||
})
|
|
||||||
GetUniqueChannelsErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "get_unique_channels_error_counter",
|
|
||||||
Help: "Number of errors",
|
|
||||||
})
|
|
||||||
JsonErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "json_error_counter",
|
|
||||||
Help: "JSON parsing errors",
|
|
||||||
})
|
|
||||||
MgetErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "mget_error_counter",
|
|
||||||
Help: "Mget errors",
|
|
||||||
})
|
|
||||||
SearchErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "search_error_counter",
|
|
||||||
Help: "Number of errors",
|
|
||||||
})
|
|
||||||
FatalErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
|
|
||||||
Name: "fatal_error_counter",
|
|
||||||
Help: "Number of errors",
|
|
||||||
})
|
|
||||||
QueryTime = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
QueryTime = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
Name: "query_time",
|
Name: "query_time",
|
||||||
Help: "Histogram of query times",
|
Help: "Histogram of query times",
|
||||||
|
|
|
@ -129,8 +129,7 @@ func AddInvertibleField(q *elastic.BoolQuery, field *pb.InvertibleField, name st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) recordErrorAndDie(err error) {
|
func (s *Server) recordErrorAndDie(err error) {
|
||||||
// TODO record metric fatal_error_counter
|
metrics.ErrorsCounter.With(prometheus.Labels{"error_type": "fatal"}).Inc()
|
||||||
metrics.FatalErrorCounter.Inc()
|
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +171,6 @@ func RoundUpReleaseTime(q *elastic.BoolQuery, rq *pb.RangeField, name string) *e
|
||||||
//*/
|
//*/
|
||||||
func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs, error) {
|
func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs, error) {
|
||||||
metrics.RequestsCount.With(prometheus.Labels{"method": "search"}).Inc()
|
metrics.RequestsCount.With(prometheus.Labels{"method": "search"}).Inc()
|
||||||
metrics.SessionCount.Inc()
|
|
||||||
defer func() {metrics.SessionCount.Dec()}()
|
|
||||||
defer func(t time.Time) {
|
defer func(t time.Time) {
|
||||||
delta := time.Since(t).Seconds()
|
delta := time.Since(t).Seconds()
|
||||||
metrics.
|
metrics.
|
||||||
|
@ -262,7 +259,7 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
|
||||||
return &pb.Outputs{}, nil
|
return &pb.Outputs{}, nil
|
||||||
|
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
metrics.SearchErrorCounter.Inc()
|
metrics.ErrorsCounter.With(prometheus.Labels{"error_type": "search"}).Inc()
|
||||||
log.Println("Error executing query: ", err)
|
log.Println("Error executing query: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -650,13 +647,12 @@ func (s *Server) getUniqueChannels(records []*record, client *elastic.Client, ct
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if totalChannels == 0 {
|
if totalChannels == 0 {
|
||||||
metrics.ZeroChannelsCounter.Inc()
|
|
||||||
return []*pb.Output{}, make(map[string]*pb.Output)
|
return []*pb.Output{}, make(map[string]*pb.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := mget.Do(ctx)
|
res, err := mget.Do(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.GetUniqueChannelsErrorCounter.Inc()
|
metrics.ErrorsCounter.With(prometheus.Labels{"error_type": "get_unique_channels"}).Inc()
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return []*pb.Output{}, make(map[string]*pb.Output)
|
return []*pb.Output{}, make(map[string]*pb.Output)
|
||||||
}
|
}
|
||||||
|
@ -669,7 +665,7 @@ func (s *Server) getUniqueChannels(records []*record, client *elastic.Client, ct
|
||||||
var r record
|
var r record
|
||||||
err := json.Unmarshal(doc.Source, &r)
|
err := json.Unmarshal(doc.Source, &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.JsonErrorCounter.Inc()
|
metrics.ErrorsCounter.With(prometheus.Labels{"error_type": "json"}).Inc()
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return []*pb.Output{}, make(map[string]*pb.Output)
|
return []*pb.Output{}, make(map[string]*pb.Output)
|
||||||
}
|
}
|
||||||
|
@ -704,13 +700,12 @@ func (s *Server) getClaimsForReposts(ctx context.Context, client *elastic.Client
|
||||||
}
|
}
|
||||||
//mget = mget.Add(nmget)
|
//mget = mget.Add(nmget)
|
||||||
if totalReposted == 0 {
|
if totalReposted == 0 {
|
||||||
metrics.NoRepostedCounter.Inc()
|
|
||||||
return []*pb.Output{}, []*record{}, make(map[string]*pb.Output)
|
return []*pb.Output{}, []*record{}, make(map[string]*pb.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := mget.Do(ctx)
|
res, err := mget.Do(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.MgetErrorCounter.Inc()
|
metrics.ErrorsCounter.With(prometheus.Labels{"error_type": "mget"}).Inc()
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return []*pb.Output{}, []*record{}, make(map[string]*pb.Output)
|
return []*pb.Output{}, []*record{}, make(map[string]*pb.Output)
|
||||||
}
|
}
|
||||||
|
@ -724,7 +719,7 @@ func (s *Server) getClaimsForReposts(ctx context.Context, client *elastic.Client
|
||||||
var r record
|
var r record
|
||||||
err := json.Unmarshal(doc.Source, &r)
|
err := json.Unmarshal(doc.Source, &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.JsonErrorCounter.Inc()
|
metrics.ErrorsCounter.With(prometheus.Labels{"error_type": "json"}).Inc()
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return []*pb.Output{}, []*record{}, make(map[string]*pb.Output)
|
return []*pb.Output{}, []*record{}, make(map[string]*pb.Output)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/lbryio/hub/meta"
|
"github.com/lbryio/hub/meta"
|
||||||
pb "github.com/lbryio/hub/protobuf/go"
|
pb "github.com/lbryio/hub/protobuf/go"
|
||||||
"github.com/olivere/elastic/v7"
|
"github.com/olivere/elastic/v7"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
@ -179,10 +180,11 @@ func (s *Server) Hello(context context.Context, args *FederatedServer) (*Federat
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Ping(context context.Context, args *pb.EmptyMessage) (*pb.StringValue, error) {
|
func (s *Server) Ping(context context.Context, args *pb.EmptyMessage) (*pb.StringValue, error) {
|
||||||
metrics.PingsCounter.Inc()
|
metrics.RequestsCount.With(prometheus.Labels{"method": "ping"}).Inc()
|
||||||
return &pb.StringValue{Value: "Hello, world!"}, nil
|
return &pb.StringValue{Value: "Hello, world!"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Version(context context.Context, args *pb.EmptyMessage) (*pb.StringValue, error) {
|
func (s *Server) Version(context context.Context, args *pb.EmptyMessage) (*pb.StringValue, error) {
|
||||||
|
metrics.RequestsCount.With(prometheus.Labels{"method": "version"}).Inc()
|
||||||
return &pb.StringValue{Value: getVersion()}, nil
|
return &pb.StringValue{Value: getVersion()}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue