...

Source file src/go.opencensus.io/plugin/ocgrpc/client_metrics.go

Documentation: go.opencensus.io/plugin/ocgrpc

     1  // Copyright 2017, OpenCensus Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  package ocgrpc
    17  
    18  import (
    19  	"go.opencensus.io/stats"
    20  	"go.opencensus.io/stats/view"
    21  	"go.opencensus.io/tag"
    22  )
    23  
    24  // The following variables are measures are recorded by ClientHandler:
    25  var (
    26  	ClientSentMessagesPerRPC     = stats.Int64("grpc.io/client/sent_messages_per_rpc", "Number of messages sent in the RPC (always 1 for non-streaming RPCs).", stats.UnitDimensionless)
    27  	ClientSentBytesPerRPC        = stats.Int64("grpc.io/client/sent_bytes_per_rpc", "Total bytes sent across all request messages per RPC.", stats.UnitBytes)
    28  	ClientReceivedMessagesPerRPC = stats.Int64("grpc.io/client/received_messages_per_rpc", "Number of response messages received per RPC (always 1 for non-streaming RPCs).", stats.UnitDimensionless)
    29  	ClientReceivedBytesPerRPC    = stats.Int64("grpc.io/client/received_bytes_per_rpc", "Total bytes received across all response messages per RPC.", stats.UnitBytes)
    30  	ClientRoundtripLatency       = stats.Float64("grpc.io/client/roundtrip_latency", "Time between first byte of request sent to last byte of response received, or terminal error.", stats.UnitMilliseconds)
    31  	ClientStartedRPCs            = stats.Int64("grpc.io/client/started_rpcs", "Number of started client RPCs.", stats.UnitDimensionless)
    32  	ClientServerLatency          = stats.Float64("grpc.io/client/server_latency", `Propagated from the server and should have the same value as "grpc.io/server/latency".`, stats.UnitMilliseconds)
    33  )
    34  
    35  // Predefined views may be registered to collect data for the above measures.
    36  // As always, you may also define your own custom views over measures collected by this
    37  // package. These are declared as a convenience only; none are registered by
    38  // default.
    39  var (
    40  	ClientSentBytesPerRPCView = &view.View{
    41  		Measure:     ClientSentBytesPerRPC,
    42  		Name:        "grpc.io/client/sent_bytes_per_rpc",
    43  		Description: "Distribution of bytes sent per RPC, by method.",
    44  		TagKeys:     []tag.Key{KeyClientMethod},
    45  		Aggregation: DefaultBytesDistribution,
    46  	}
    47  
    48  	ClientReceivedBytesPerRPCView = &view.View{
    49  		Measure:     ClientReceivedBytesPerRPC,
    50  		Name:        "grpc.io/client/received_bytes_per_rpc",
    51  		Description: "Distribution of bytes received per RPC, by method.",
    52  		TagKeys:     []tag.Key{KeyClientMethod},
    53  		Aggregation: DefaultBytesDistribution,
    54  	}
    55  
    56  	ClientRoundtripLatencyView = &view.View{
    57  		Measure:     ClientRoundtripLatency,
    58  		Name:        "grpc.io/client/roundtrip_latency",
    59  		Description: "Distribution of round-trip latency, by method.",
    60  		TagKeys:     []tag.Key{KeyClientMethod},
    61  		Aggregation: DefaultMillisecondsDistribution,
    62  	}
    63  
    64  	// Purposely reuses the count from `ClientRoundtripLatency`, tagging
    65  	// with method and status to result in ClientCompletedRpcs.
    66  	ClientCompletedRPCsView = &view.View{
    67  		Measure:     ClientRoundtripLatency,
    68  		Name:        "grpc.io/client/completed_rpcs",
    69  		Description: "Count of RPCs by method and status.",
    70  		TagKeys:     []tag.Key{KeyClientMethod, KeyClientStatus},
    71  		Aggregation: view.Count(),
    72  	}
    73  
    74  	ClientStartedRPCsView = &view.View{
    75  		Measure:     ClientStartedRPCs,
    76  		Name:        "grpc.io/client/started_rpcs",
    77  		Description: "Number of started client RPCs.",
    78  		TagKeys:     []tag.Key{KeyClientMethod},
    79  		Aggregation: view.Count(),
    80  	}
    81  
    82  	ClientSentMessagesPerRPCView = &view.View{
    83  		Measure:     ClientSentMessagesPerRPC,
    84  		Name:        "grpc.io/client/sent_messages_per_rpc",
    85  		Description: "Distribution of sent messages count per RPC, by method.",
    86  		TagKeys:     []tag.Key{KeyClientMethod},
    87  		Aggregation: DefaultMessageCountDistribution,
    88  	}
    89  
    90  	ClientReceivedMessagesPerRPCView = &view.View{
    91  		Measure:     ClientReceivedMessagesPerRPC,
    92  		Name:        "grpc.io/client/received_messages_per_rpc",
    93  		Description: "Distribution of received messages count per RPC, by method.",
    94  		TagKeys:     []tag.Key{KeyClientMethod},
    95  		Aggregation: DefaultMessageCountDistribution,
    96  	}
    97  
    98  	ClientServerLatencyView = &view.View{
    99  		Measure:     ClientServerLatency,
   100  		Name:        "grpc.io/client/server_latency",
   101  		Description: "Distribution of server latency as viewed by client, by method.",
   102  		TagKeys:     []tag.Key{KeyClientMethod},
   103  		Aggregation: DefaultMillisecondsDistribution,
   104  	}
   105  )
   106  
   107  // DefaultClientViews are the default client views provided by this package.
   108  var DefaultClientViews = []*view.View{
   109  	ClientSentBytesPerRPCView,
   110  	ClientReceivedBytesPerRPCView,
   111  	ClientRoundtripLatencyView,
   112  	ClientCompletedRPCsView,
   113  }
   114  
   115  // TODO(jbd): Add roundtrip_latency, uncompressed_request_bytes, uncompressed_response_bytes, request_count, response_count.
   116  // TODO(acetechnologist): This is temporary and will need to be replaced by a
   117  // mechanism to load these defaults from a common repository/config shared by
   118  // all supported languages. Likely a serialized protobuf of these defaults.
   119  

View as plain text