MCPcopy
hub / github.com/grpc/grpc-go / TestAllMetricsOneFunction

Method TestAllMetricsOneFunction

stats/opencensus/e2e_test.go:276–1058  ·  view source on GitHub ↗

TestAllMetricsOneFunction tests emitted metrics from gRPC. It registers all the metrics provided by this package. It then configures a system with a gRPC Client and gRPC server with the OpenCensus Dial and Server Option configured, and makes a Unary RPC and a Streaming RPC. These two RPCs should cau

(t *testing.T)

Source from the content-addressed store, hash-verified

274// certain emissions for each registered metric through the OpenCensus View
275// package.
276func (s) TestAllMetricsOneFunction(t *testing.T) {
277 allViews := []*view.View{
278 ClientStartedRPCsView,
279 ServerStartedRPCsView,
280 ClientCompletedRPCsView,
281 ServerCompletedRPCsView,
282 ClientSentBytesPerRPCView,
283 ClientSentCompressedMessageBytesPerRPCView,
284 ServerSentBytesPerRPCView,
285 ServerSentCompressedMessageBytesPerRPCView,
286 ClientReceivedBytesPerRPCView,
287 ClientReceivedCompressedMessageBytesPerRPCView,
288 ServerReceivedBytesPerRPCView,
289 ServerReceivedCompressedMessageBytesPerRPCView,
290 ClientSentMessagesPerRPCView,
291 ServerSentMessagesPerRPCView,
292 ClientReceivedMessagesPerRPCView,
293 ServerReceivedMessagesPerRPCView,
294 ClientRoundtripLatencyView,
295 ServerLatencyView,
296 ClientAPILatencyView,
297 }
298 view.Register(allViews...)
299 // Unregister unconditionally in this defer to correctly cleanup globals in
300 // error conditions.
301 defer view.Unregister(allViews...)
302 fe := &fakeExporter{
303 t: t,
304 seenViews: make(map[string]*viewInformation),
305 }
306 view.RegisterExporter(fe)
307 defer view.UnregisterExporter(fe)
308
309 ss := &stubserver.StubServer{
310 UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
311 return &testpb.SimpleResponse{Payload: &testpb.Payload{
312 Body: make([]byte, 10000),
313 }}, nil
314 },
315 FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
316 for {
317 _, err := stream.Recv()
318 if err == io.EOF {
319 return nil
320 }
321 }
322 },
323 }
324 if err := ss.Start([]grpc.ServerOption{ServerOption(TraceOptions{})}, DialOption(TraceOptions{})); err != nil {
325 t.Fatalf("Error starting endpoint server: %v", err)
326 }
327 defer ss.Stop()
328 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
329 defer cancel()
330 // Make two RPC's, a unary RPC and a streaming RPC. These should cause
331 // certain metrics to be emitted.
332 if _, err := ss.Client.UnaryCall(ctx, &testpb.SimpleRequest{Payload: &testpb.Payload{
333 Body: make([]byte, 10000),

Callers

nothing calls this directly

Calls 13

StartMethod · 0.95
StopMethod · 0.95
UseCompressorFunction · 0.92
ServerOptionFunction · 0.70
DialOptionFunction · 0.70
RecvMethod · 0.65
FatalfMethod · 0.65
UnaryCallMethod · 0.65
FullDuplexCallMethod · 0.65
CloseSendMethod · 0.65

Tested by

no test coverage detected