Add stats labels and slow-query log in GRPC endpoints

This commit is contained in:
Alan Bernstein 2020-04-10 13:26:37 -05:00 committed by Matt Jaffee
parent eaf21eb19b
commit 9947c92e8e
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -66,13 +66,18 @@ func (h grpcHandler) QueryPQL(req *pb.QueryPQLRequest, stream pb.Pilosa_QueryPQL
Index: req.Index,
Query: req.Pql,
}
statsTags := make([]string, 0, 5)
t := time.Now()
resp, err := h.api.Query(context.Background(), &query)
dur := time.Since(t)
durQuery := time.Since(t)
if err != nil {
return errToStatusError(err)
}
h.stats.Timing(pilosa.MetricGRPCStreamQueryDurationSeconds, dur, 0.1)
longQueryTime := h.api.LongQueryTime()
if longQueryTime > 0 && durQuery > longQueryTime {
h.logger.Printf("GRPC QueryPQL %v %s", durQuery, query.Query)
}
t = time.Now()
for row := range makeRows(resp, h.logger) {
@ -81,8 +86,17 @@ func (h grpcHandler) QueryPQL(req *pb.QueryPQLRequest, stream pb.Pilosa_QueryPQL
return errToStatusError(err)
}
}
dur = time.Since(t)
h.stats.Timing(pilosa.MetricGRPCStreamFormatDurationSeconds, dur, 0.1)
durFormat := time.Since(t)
if query.Remote {
statsTags = append(statsTags, "where:external")
} else {
statsTags = append(statsTags, "where:internal")
}
stats := h.stats.WithTags(statsTags...)
if stats != nil {
stats.Timing(pilosa.MetricGRPCStreamQueryDurationSeconds, durQuery, 0.1)
stats.Timing(pilosa.MetricGRPCStreamFormatDurationSeconds, durFormat, 0.1)
}
return nil
}
@ -93,13 +107,18 @@ func (h grpcHandler) QueryPQLUnary(ctx context.Context, req *pb.QueryPQLRequest)
Index: req.Index,
Query: req.Pql,
}
statsTags := make([]string, 0, 5)
t := time.Now()
resp, err := h.api.Query(context.Background(), &query)
dur := time.Since(t)
durQuery := time.Since(t)
if err != nil {
return nil, errToStatusError(err)
}
h.stats.Timing(pilosa.MetricGRPCUnaryQueryDurationSeconds, dur, 0.1)
longQueryTime := h.api.LongQueryTime()
if longQueryTime > 0 && durQuery > longQueryTime {
h.logger.Printf("GRPC QueryPQLUnary %v %s", durQuery, query.Query)
}
t = time.Now()
response := &pb.TableResponse{
@ -111,8 +130,17 @@ 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)
durFormat := time.Since(t)
if query.Remote {
statsTags = append(statsTags, "where:external")
} else {
statsTags = append(statsTags, "where:internal")
}
stats := h.stats.WithTags(statsTags...)
if stats != nil {
h.stats.Timing(pilosa.MetricGRPCUnaryQueryDurationSeconds, durQuery, 0.1)
h.stats.Timing(pilosa.MetricGRPCUnaryFormatDurationSeconds, durFormat, 0.1)
}
return response, nil
}