Skip to content

Commit

Permalink
update comments and descriptions (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyinma authored Jul 5, 2022
1 parent b68d3c6 commit d6aa1cd
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions occonnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

// Package occonnect is a Go implementation of OpenCensus as a Connect interceptor.
// It adds support for OpenCensus application metrics collection on a Connect server
// or client. It provides multiple tags, stats, and views to be tracked and recorded.
package occonnect

import (
Expand All @@ -27,11 +29,13 @@ const statusOK = "ok"

// The following Connect client metrics are supported for use in custom views.
var (
// ClientSentMessagesPerRPC is the client metrics of number of request messages sent by client in the RPC.
ClientSentMessagesPerRPC = stats.Int64(
"connectrpc.com/client/sent_messages_per_rpc",
"Number of request messages sent by client in the RPC (always 1 for non-streaming RPCs).",
stats.UnitDimensionless,
)
// ClientReceivedMessagesPerRPC is the client metrics of number of response messages received by client per RPC.
ClientReceivedMessagesPerRPC = stats.Int64(
"connectrpc.com/client/received_messages_per_rpc",
"Number of response messages received by client per RPC (always 1 for non-streaming RPCs).",
Expand All @@ -41,62 +45,70 @@ var (

// The following Connect server metrics are supported for use in custom views.
var (
// ServerSentMessagesPerRPC is the server metrics of number of response messages sent by server in each RPC.
ServerSentMessagesPerRPC = stats.Int64(
"connectrpc.com/server/sent_messages_per_rpc",
"Number of response messages sent by server in each RPC. Has value 1 for non-streaming RPCs.",
"Number of response messages sent by server in each RPC (always 1 for non-streaming RPCs).",
stats.UnitDimensionless,
)
// ServerReceivedMessagesPerRPC is the server metrics of number of request messages received by server in each RPC.
ServerReceivedMessagesPerRPC = stats.Int64(
"connectrpc.com/server/received_messages_per_rpc",
"Number of request messages received by server in each RPC. Has value 1 for non-streaming RPCs.",
"Number of request messages received by server in each RPC (always 1 for non-streaming RPCs).",
stats.UnitDimensionless,
)
)

var (
DefaultLatencyDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
// DefaultLatencyDistribution is the default distribution of RPC latency.
DefaultLatencyDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
// DefaultMessageCountDistribution is the default distribution of message count of each RPC.
DefaultMessageCountDistribution = view.Distribution(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536)
)

// Server tags are applied to the context used to process each RPC.
var (
KeyServerMethod = tag.MustNewKey("connect_server_method")
// KeyServerStatus is the tag's key for status for each RPC in the server side.
KeyServerStatus = tag.MustNewKey("connect_server_status")
)

// Client tags are applied to the context used to process each RPC.
var (
KeyClientMethod = tag.MustNewKey("connect_client_method")
// KeyClientStatus is the tag's key for status for each RPC in the client side.
KeyClientStatus = tag.MustNewKey("connect_client_status")
)

// Package occonnect provides some convenient view for client metrics.
// You still need to register these views for data to actually be collected.
var (
// ClientRoundtripLatencyView is the distribution view of the end-to-end latency in the client side by RPC method.
// Purposely reuses the measure from ochttp.ClientRoundtripLatency.
ClientRoundtripLatencyView = &view.View{
Name: "connectrpc.com/client/roundtrip_latency",
Description: "End-to-end latency, by method.",
Description: "Distribution of end-to-end latency, by method.",
TagKeys: []tag.Key{ochttp.KeyClientPath},
Measure: ochttp.ClientRoundtripLatency,
Aggregation: DefaultLatencyDistribution,
}

// ClientCompletedRPCsView is the counting view of the completed RPC in the client side by RPC method and status.
// Purposely reuses the count from ClientReceivedMessagesPerRPC (note that this is the count of collected records,
// not the underlying received messages count).
ClientCompletedRPCsView = &view.View{
Name: "connectrpc.com/client/completed_rpcs",
Description: "Count of RPCs by method and status.",
TagKeys: []tag.Key{ochttp.KeyClientPath, KeyClientStatus},
Measure: ClientReceivedMessagesPerRPC,
Aggregation: view.Count(),
}

// ClientSentMessagesPerRPCView is the distribution view of the count of sent messages per RPC in the client side by RPC method.
ClientSentMessagesPerRPCView = &view.View{
Name: "connectrpc.com/client/sent_messages_per_rpc",
Description: "Distribution of sent messages count per RPC, by method.",
TagKeys: []tag.Key{ochttp.KeyClientPath},
Measure: ClientSentMessagesPerRPC,
Aggregation: DefaultMessageCountDistribution,
}

// ClientReceivedMessagesPerRPCView is the distribution view of the count of received messages per RPC in the client side by RPC method.
ClientReceivedMessagesPerRPCView = &view.View{
Name: "connectrpc.com/client/received_messages_per_rpc",
Description: "Distribution of received messages count per RPC, by method.",
Expand All @@ -109,30 +121,34 @@ var (
// Package occonnect provides some convenient view for server metrics.
// You still need to register these views for data to actually be collected.
var (
// ServerLatencyView is the distribution view of the server latency by RPC method.
// Purposely reuses the measure from ochttp.ServerLatency.
ServerLatencyView = &view.View{
Name: "connectrpc.com/server/server_latency",
Description: "Distribution of server latency in milliseconds, by method.",
TagKeys: []tag.Key{ochttp.KeyServerRoute},
Measure: ochttp.ServerLatency,
Aggregation: DefaultLatencyDistribution,
}

// ServerCompletedRPCsView is the counting view of the completed RPC in the server side by RPC method and status.
// Purposely reuses the count from ServerSentMessagesPerRPC (note that this is the count of collected records,
// not the underlying sent messages count).
ServerCompletedRPCsView = &view.View{
Name: "connectrpc.com/server/completed_rpcs",
Description: "Count of RPCs by method and status.",
TagKeys: []tag.Key{ochttp.KeyServerRoute, KeyServerStatus},
Measure: ServerSentMessagesPerRPC,
Aggregation: view.Count(),
}

// ServerSentMessagesPerRPCView is the distribution view of the count of sent messages per RPC in the server side by RPC method.
ServerSentMessagesPerRPCView = &view.View{
Name: "connectrpc.com/server/sent_messages_per_rpc",
Description: "Distribution of messages sent count per RPC, by method.",
TagKeys: []tag.Key{ochttp.KeyServerRoute},
Measure: ServerSentMessagesPerRPC,
Aggregation: DefaultMessageCountDistribution,
}

// ServerReceivedMessagesPerRPCView is the distribution view of the count of received messages per RPC in the server side by RPC method.
ServerReceivedMessagesPerRPCView = &view.View{
Name: "connectrpc.com/server/received_messages_per_rpc",
Description: "Distribution of messages received count per RPC, by method.",
Expand Down

0 comments on commit d6aa1cd

Please sign in to comment.