google.golang.org/grpc@v1.74.2/stats/handlers.go (about)

     1  /*
     2   *
     3   * Copyright 2016 gRPC authors.
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   */
    18  
    19  package stats
    20  
    21  import (
    22  	"context"
    23  	"net"
    24  )
    25  
    26  // ConnTagInfo defines the relevant information needed by connection context tagger.
    27  type ConnTagInfo struct {
    28  	// RemoteAddr is the remote address of the corresponding connection.
    29  	RemoteAddr net.Addr
    30  	// LocalAddr is the local address of the corresponding connection.
    31  	LocalAddr net.Addr
    32  }
    33  
    34  // RPCTagInfo defines the relevant information needed by RPC context tagger.
    35  type RPCTagInfo struct {
    36  	// FullMethodName is the RPC method in the format of /package.service/method.
    37  	FullMethodName string
    38  	// FailFast indicates if this RPC is failfast.
    39  	// This field is only valid on client side, it's always false on server side.
    40  	FailFast bool
    41  	// NameResolutionDelay indicates if the RPC needed to wait for the
    42  	// initial name resolver update before it could begin. This should only
    43  	// happen if the channel is IDLE when the RPC is started.  Note that
    44  	// all retry or hedging attempts for an RPC that experienced a delay
    45  	// will have it set.
    46  	//
    47  	// This field is only valid on the client side; it is always false on
    48  	// the server side.
    49  	NameResolutionDelay bool
    50  }
    51  
    52  // Handler defines the interface for the related stats handling (e.g., RPCs, connections).
    53  type Handler interface {
    54  	// TagRPC can attach some information to the given context.
    55  	// The context used for the rest lifetime of the RPC will be derived from
    56  	// the returned context.
    57  	TagRPC(context.Context, *RPCTagInfo) context.Context
    58  	// HandleRPC processes the RPC stats.
    59  	HandleRPC(context.Context, RPCStats)
    60  
    61  	// TagConn can attach some information to the given context.
    62  	// The returned context will be used for stats handling.
    63  	// For conn stats handling, the context used in HandleConn for this
    64  	// connection will be derived from the context returned.
    65  	// For RPC stats handling,
    66  	//  - On server side, the context used in HandleRPC for all RPCs on this
    67  	// connection will be derived from the context returned.
    68  	//  - On client side, the context is not derived from the context returned.
    69  	TagConn(context.Context, *ConnTagInfo) context.Context
    70  	// HandleConn processes the Conn stats.
    71  	HandleConn(context.Context, ConnStats)
    72  }