Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/indexgateway/grpc.go

47 lines
1.3 KiB

package indexgateway
import (
"context"
"github.com/grafana/dskit/tenant"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"google.golang.org/grpc"
"github.com/grafana/loki/v3/pkg/util/constants"
)
type ServerInterceptors struct {
reqCount *prometheus.CounterVec
PerTenantRequestCount grpc.UnaryServerInterceptor
}
func NewServerInterceptors(r prometheus.Registerer) *ServerInterceptors {
requestCount := promauto.With(r).NewCounterVec(prometheus.CounterOpts{
Namespace: constants.Loki,
Subsystem: "index_gateway",
Name: "requests_total",
Help: "Total amount of requests served by the index gateway",
}, []string{"operation", "status", "tenant"})
perTenantRequestCount := func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
tenantID, err := tenant.TenantID(ctx)
if err != nil {
// ignore requests without tenantID
return handler(ctx, req)
}
resp, err = handler(ctx, req)
status := "success"
if err != nil {
status = "error"
}
requestCount.WithLabelValues(info.FullMethod, status, tenantID).Inc()
return
}
return &ServerInterceptors{
reqCount: requestCount,
PerTenantRequestCount: perTenantRequestCount,
}
}