mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
Add metrics for GRPC request timing
This commit is contained in:
parent
5df680fb9f
commit
eaf21eb19b
3 changed files with 71 additions and 40 deletions
82
metrics.go
82
metrics.go
|
|
@ -15,43 +15,47 @@
|
|||
package pilosa
|
||||
|
||||
const (
|
||||
MetricCreateIndex = "create_index_total"
|
||||
MetricDeleteIndex = "delete_index_total"
|
||||
MetricCreateField = "create_field_total"
|
||||
MetricDeleteField = "delete_field_total"
|
||||
MetricDeleteAvailableShard = "delete_available_shard_total"
|
||||
MetricRecalculateCache = "recalculate_cache_total"
|
||||
MetricInvalidateCache = "invalidate_cache_total"
|
||||
MetricRankCacheLength = "rank_cache_length"
|
||||
MetricCacheThresholdReached = "cache_threshold_reached_total"
|
||||
MetricRow = "query_row_total"
|
||||
MetricRowBSI = "query_row_bsi_total"
|
||||
MetricSetRowAttrs = "query_setrowattrs_total"
|
||||
MetricSetColumnAttrs = "query_setcolumnattrs_total"
|
||||
MetricSetBit = "set_bit_total"
|
||||
MetricClearBit = "clear_bit_total"
|
||||
MetricImportingN = "importing_total"
|
||||
MetricImportedN = "imported_total"
|
||||
MetricClearingN = "clearing_total"
|
||||
MetricClearedN = "cleared_total"
|
||||
MetricSnapshotDurationSeconds = "snapshot_duration_seconds"
|
||||
MetricBlockRepair = "block_repair_total"
|
||||
MetricSyncFieldDurationSeconds = "sync_field_duration_seconds"
|
||||
MetricSyncIndexDurationSeconds = "sync_index_duration_seconds"
|
||||
MetricColumnAttrStoreBlocks = "ColumnAttrStoreBlocks"
|
||||
MetricColumnAttrDiff = "ColumnAttrDiff"
|
||||
MetricRowAttrStoreBlocks = "RowAttrStoreBlocks"
|
||||
MetricRowAttrDiff = "RowAttrDiff"
|
||||
MetricHTTPRequest = "http_request_total"
|
||||
MetricMaxShard = "maximum_shard"
|
||||
MetricAntiEntropy = "antientropy_total"
|
||||
MetricAntiEntropyDurationSeconds = "antientropy_duration_seconds"
|
||||
MetricGarbageCollection = "garbage_collection_total"
|
||||
MetricGoroutines = "goroutines"
|
||||
MetricOpenFiles = "open_files"
|
||||
MetricHeapAlloc = "heap_alloc"
|
||||
MetricHeapInuse = "heap_inuse"
|
||||
MetricStackInuse = "stack_inuse"
|
||||
MetricMallocs = "mallocs"
|
||||
MetricFrees = "frees"
|
||||
MetricCreateIndex = "create_index_total"
|
||||
MetricDeleteIndex = "delete_index_total"
|
||||
MetricCreateField = "create_field_total"
|
||||
MetricDeleteField = "delete_field_total"
|
||||
MetricDeleteAvailableShard = "delete_available_shard_total"
|
||||
MetricRecalculateCache = "recalculate_cache_total"
|
||||
MetricInvalidateCache = "invalidate_cache_total"
|
||||
MetricRankCacheLength = "rank_cache_length"
|
||||
MetricCacheThresholdReached = "cache_threshold_reached_total"
|
||||
MetricRow = "query_row_total"
|
||||
MetricRowBSI = "query_row_bsi_total"
|
||||
MetricSetRowAttrs = "query_setrowattrs_total"
|
||||
MetricSetColumnAttrs = "query_setcolumnattrs_total"
|
||||
MetricSetBit = "set_bit_total"
|
||||
MetricClearBit = "clear_bit_total"
|
||||
MetricImportingN = "importing_total"
|
||||
MetricImportedN = "imported_total"
|
||||
MetricClearingN = "clearing_total"
|
||||
MetricClearedN = "cleared_total"
|
||||
MetricSnapshotDurationSeconds = "snapshot_duration_seconds"
|
||||
MetricBlockRepair = "block_repair_total"
|
||||
MetricSyncFieldDurationSeconds = "sync_field_duration_seconds"
|
||||
MetricSyncIndexDurationSeconds = "sync_index_duration_seconds"
|
||||
MetricColumnAttrStoreBlocks = "ColumnAttrStoreBlocks"
|
||||
MetricColumnAttrDiff = "ColumnAttrDiff"
|
||||
MetricRowAttrStoreBlocks = "RowAttrStoreBlocks"
|
||||
MetricRowAttrDiff = "RowAttrDiff"
|
||||
MetricHTTPRequest = "http_request_duration_seconds"
|
||||
MetricGRPCUnaryQueryDurationSeconds = "grpc_request_pql_unary_query_duration_seconds"
|
||||
MetricGRPCUnaryFormatDurationSeconds = "grpc_request_pql_unary_format_duration_seconds"
|
||||
MetricGRPCStreamQueryDurationSeconds = "grpc_request_pql_stream_query_duration_seconds"
|
||||
MetricGRPCStreamFormatDurationSeconds = "grpc_request_pql_stream_format_duration_seconds"
|
||||
MetricMaxShard = "maximum_shard"
|
||||
MetricAntiEntropy = "antientropy_total"
|
||||
MetricAntiEntropyDurationSeconds = "antientropy_duration_seconds"
|
||||
MetricGarbageCollection = "garbage_collection_total"
|
||||
MetricGoroutines = "goroutines"
|
||||
MetricOpenFiles = "open_files"
|
||||
MetricHeapAlloc = "heap_alloc"
|
||||
MetricHeapInuse = "heap_inuse"
|
||||
MetricStackInuse = "stack_inuse"
|
||||
MetricMallocs = "mallocs"
|
||||
MetricFrees = "frees"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -20,10 +20,12 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa/v2"
|
||||
"github.com/pilosa/pilosa/v2/logger"
|
||||
pb "github.com/pilosa/pilosa/v2/proto"
|
||||
"github.com/pilosa/pilosa/v2/stats"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
|
@ -37,6 +39,8 @@ type grpcHandler struct {
|
|||
api *pilosa.API
|
||||
|
||||
logger logger.Logger
|
||||
|
||||
stats stats.StatsClient
|
||||
}
|
||||
|
||||
// errorToStatusError appends an appropriate grpc status code
|
||||
|
|
@ -62,16 +66,23 @@ func (h grpcHandler) QueryPQL(req *pb.QueryPQLRequest, stream pb.Pilosa_QueryPQL
|
|||
Index: req.Index,
|
||||
Query: req.Pql,
|
||||
}
|
||||
t := time.Now()
|
||||
resp, err := h.api.Query(context.Background(), &query)
|
||||
dur := time.Since(t)
|
||||
if err != nil {
|
||||
return errToStatusError(err)
|
||||
}
|
||||
h.stats.Timing(pilosa.MetricGRPCStreamQueryDurationSeconds, dur, 0.1)
|
||||
|
||||
t = time.Now()
|
||||
for row := range makeRows(resp, h.logger) {
|
||||
err = stream.Send(row)
|
||||
if err != nil {
|
||||
return errToStatusError(err)
|
||||
}
|
||||
}
|
||||
dur = time.Since(t)
|
||||
h.stats.Timing(pilosa.MetricGRPCStreamFormatDurationSeconds, dur, 0.1)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -82,10 +93,15 @@ func (h grpcHandler) QueryPQLUnary(ctx context.Context, req *pb.QueryPQLRequest)
|
|||
Index: req.Index,
|
||||
Query: req.Pql,
|
||||
}
|
||||
t := time.Now()
|
||||
resp, err := h.api.Query(context.Background(), &query)
|
||||
dur := time.Since(t)
|
||||
if err != nil {
|
||||
return nil, errToStatusError(err)
|
||||
}
|
||||
h.stats.Timing(pilosa.MetricGRPCUnaryQueryDurationSeconds, dur, 0.1)
|
||||
|
||||
t = time.Now()
|
||||
response := &pb.TableResponse{
|
||||
Rows: make([]*pb.Row, 0),
|
||||
}
|
||||
|
|
@ -95,6 +111,8 @@ func (h grpcHandler) QueryPQLUnary(ctx context.Context, req *pb.QueryPQLRequest)
|
|||
}
|
||||
response.Rows = append(response.Rows, &pb.Row{Columns: row.Columns})
|
||||
}
|
||||
dur = time.Since(t)
|
||||
h.stats.Timing(pilosa.MetricGRPCUnaryFormatDurationSeconds, dur, 0.1)
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
|
@ -878,6 +896,7 @@ type grpcServer struct {
|
|||
hostPort string
|
||||
|
||||
logger logger.Logger
|
||||
stats stats.StatsClient
|
||||
}
|
||||
|
||||
type grpcServerOption func(s *grpcServer) error
|
||||
|
|
@ -904,6 +923,13 @@ func OptGRPCServerLogger(logger logger.Logger) grpcServerOption {
|
|||
}
|
||||
}
|
||||
|
||||
func OptGRPCServerStats(stats stats.StatsClient) grpcServerOption {
|
||||
return func(s *grpcServer) error {
|
||||
s.stats = stats
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *grpcServer) Serve(tlsConfig *tls.Config) error {
|
||||
// create listener
|
||||
lis, err := net.Listen("tcp", s.hostPort)
|
||||
|
|
@ -920,7 +946,7 @@ func (s *grpcServer) Serve(tlsConfig *tls.Config) error {
|
|||
|
||||
// create grpc server
|
||||
s.grpcServer = grpc.NewServer(opts...)
|
||||
pb.RegisterPilosaServer(s.grpcServer, grpcHandler{api: s.api, logger: s.logger})
|
||||
pb.RegisterPilosaServer(s.grpcServer, grpcHandler{api: s.api, logger: s.logger, stats: s.stats})
|
||||
|
||||
// register the server so its services are available to grpc_cli and others
|
||||
reflection.Register(s.grpcServer)
|
||||
|
|
|
|||
|
|
@ -376,6 +376,7 @@ func (m *Command) SetupServer() error {
|
|||
OptGRPCServerAPI(m.API),
|
||||
OptGRPCServerURI(grpcURI),
|
||||
OptGRPCServerLogger(m.logger),
|
||||
OptGRPCServerStats(statsClient),
|
||||
)
|
||||
return errors.Wrap(err, "new grpc server")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue