This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use stats.handler instead of interceptor and add message size monitor
- Loading branch information
Showing
14 changed files
with
792 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package grpc_prometheus | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc/stats" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
type clientStatsHandler struct { | ||
clientMetrics *ClientMetrics | ||
} | ||
|
||
// TagRPC implements the stats.Hanlder interface. | ||
func (h *clientStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { | ||
rpcInfo := newRPCInfo(info.FullMethodName) | ||
return context.WithValue(ctx, &rpcInfoKey, rpcInfo) | ||
} | ||
|
||
// HandleRPC implements the stats.Hanlder interface. | ||
func (h *clientStatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats) { | ||
v, ok := ctx.Value(&rpcInfoKey).(*rpcInfo) | ||
if !ok { | ||
return | ||
} | ||
monitor := newClientReporterForStatsHanlder(v.startTime, h.clientMetrics, v.fullMethodName) | ||
switch s := s.(type) { | ||
case *stats.Begin: | ||
v.startTime = s.BeginTime | ||
monitor.StartedConn() | ||
case *stats.End: | ||
monitor.Handled(status.Code(s.Error)) | ||
case *stats.InHeader: | ||
monitor.ReceivedMessageSize(Header, float64(s.WireLength)) | ||
case *stats.InPayload: | ||
// TODO: remove the +5 offset on wire length here, which is a temporary stand-in for the missing grpc framing offset | ||
// See: https://github.com/grpc/grpc-go/issues/1647 | ||
monitor.ReceivedMessageSize(Payload, float64(s.WireLength+5)) | ||
case *stats.InTrailer: | ||
monitor.ReceivedMessageSize(Tailer, float64(s.WireLength)) | ||
case *stats.OutHeader: | ||
// TODO: Add the sent header message size stats, if the wire length of the send header is provided | ||
case *stats.OutPayload: | ||
// TODO(tonywang): response latency (seconds) of the gRPC single message send | ||
monitor.SentMessageSize(Payload, float64(s.WireLength)) | ||
case *stats.OutTrailer: | ||
monitor.SentMessageSize(Tailer, float64(s.WireLength)) | ||
} | ||
} | ||
|
||
// TagConn implements the stats.Hanlder interface. | ||
func (h *clientStatsHandler) TagConn(ctx context.Context, info *stats.ConnTagInfo) context.Context { | ||
return ctx | ||
} | ||
|
||
// HandleConn implements the stats.Hanlder interface. | ||
func (h *clientStatsHandler) HandleConn(ctx context.Context, s stats.ConnStats) { | ||
} |
Oops, something went wrong.