ocgrpc

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package ocgrpc contains OpenCensus stats and trace integrations for gRPC.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ClientErrorCount, _       = stats.Int64("grpc.io/client/error_count", "RPC Errors", stats.UnitNone)
	ClientRequestBytes, _     = stats.Int64("grpc.io/client/request_bytes", "Request bytes", stats.UnitBytes)
	ClientResponseBytes, _    = stats.Int64("grpc.io/client/response_bytes", "Response bytes", stats.UnitBytes)
	ClientStartedCount, _     = stats.Int64("grpc.io/client/started_count", "Number of client RPCs (streams) started", stats.UnitNone)
	ClientFinishedCount, _    = stats.Int64("grpc.io/client/finished_count", "Number of client RPCs (streams) finished", stats.UnitNone)
	ClientRequestCount, _     = stats.Int64("grpc.io/client/request_count", "Number of client RPC request messages", stats.UnitNone)
	ClientResponseCount, _    = stats.Int64("grpc.io/client/response_count", "Number of client RPC response messages", stats.UnitNone)
	ClientRoundTripLatency, _ = stats.Float64("grpc.io/client/roundtrip_latency", "RPC roundtrip latency in msecs", stats.UnitMilliseconds)
)

The following variables are measures are recorded by ClientHandler:

View Source
var (
	ClientErrorCountView = &view.View{
		Name:        "grpc.io/client/error_count",
		Description: "RPC Errors",
		TagKeys:     []tag.Key{KeyStatus, KeyMethod},
		Measure:     ClientErrorCount,
		Aggregation: view.MeanAggregation{},
	}

	ClientRoundTripLatencyView = &view.View{
		Name:        "grpc.io/client/roundtrip_latency",
		Description: "Latency in msecs",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ClientRoundTripLatency,
		Aggregation: DefaultMillisecondsDistribution,
	}

	ClientRequestBytesView = &view.View{
		Name:        "grpc.io/client/request_bytes",
		Description: "Request bytes",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ClientRequestBytes,
		Aggregation: DefaultBytesDistribution,
	}

	ClientResponseBytesView = &view.View{
		Name:        "grpc.io/client/response_bytes",
		Description: "Response bytes",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ClientResponseBytes,
		Aggregation: DefaultBytesDistribution,
	}

	ClientRequestCountView = &view.View{
		Name:        "grpc.io/client/request_count",
		Description: "Count of request messages per client RPC",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ClientRequestCount,
		Aggregation: DefaultMessageCountDistribution,
	}

	ClientResponseCountView = &view.View{
		Name:        "grpc.io/client/response_count",
		Description: "Count of response messages per client RPC",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ClientResponseCount,
		Aggregation: DefaultMessageCountDistribution,
	}
)

Predefined views may be subscribed to collect data for the above measures. As always, you may also define your own custom views over measures collected by this package. These are declared as a convenience only; none are subscribed by default.

View Source
var (
	ServerErrorCount, _        = stats.Int64("grpc.io/server/error_count", "RPC Errors", stats.UnitNone)
	ServerServerElapsedTime, _ = stats.Float64("grpc.io/server/server_elapsed_time", "Server elapsed time in msecs", stats.UnitMilliseconds)
	ServerRequestBytes, _      = stats.Int64("grpc.io/server/request_bytes", "Request bytes", stats.UnitBytes)
	ServerResponseBytes, _     = stats.Int64("grpc.io/server/response_bytes", "Response bytes", stats.UnitBytes)
	ServerStartedCount, _      = stats.Int64("grpc.io/server/started_count", "Number of server RPCs (streams) started", stats.UnitNone)
	ServerFinishedCount, _     = stats.Int64("grpc.io/server/finished_count", "Number of server RPCs (streams) finished", stats.UnitNone)
	ServerRequestCount, _      = stats.Int64("grpc.io/server/request_count", "Number of server RPC request messages", stats.UnitNone)
	ServerResponseCount, _     = stats.Int64("grpc.io/server/response_count", "Number of server RPC response messages", stats.UnitNone)
)

The following variables are measures are recorded by ServerHandler:

View Source
var (
	ServerErrorCountView = &view.View{
		Name:        "grpc.io/server/error_count",
		Description: "RPC Errors",
		TagKeys:     []tag.Key{KeyMethod, KeyStatus},
		Measure:     ServerErrorCount,
		Aggregation: view.CountAggregation{},
	}

	ServerServerElapsedTimeView = &view.View{
		Name:        "grpc.io/server/server_elapsed_time",
		Description: "Server elapsed time in msecs",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ServerServerElapsedTime,
		Aggregation: DefaultMillisecondsDistribution,
	}

	ServerRequestBytesView = &view.View{
		Name:        "grpc.io/server/request_bytes",
		Description: "Request bytes",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ServerRequestBytes,
		Aggregation: DefaultBytesDistribution,
	}

	ServerResponseBytesView = &view.View{
		Name:        "grpc.io/server/response_bytes",
		Description: "Response bytes",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ServerResponseBytes,
		Aggregation: DefaultBytesDistribution,
	}

	ServerRequestCountView = &view.View{
		Name:        "grpc.io/server/request_count",
		Description: "Count of request messages per server RPC",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ServerRequestCount,
		Aggregation: DefaultMessageCountDistribution,
	}

	ServerResponseCountView = &view.View{
		Name:        "grpc.io/server/response_count",
		Description: "Count of response messages per server RPC",
		TagKeys:     []tag.Key{KeyMethod},
		Measure:     ServerResponseCount,
		Aggregation: DefaultMessageCountDistribution,
	}
)

Predefined views may be subscribed to collect data for the above measures. As always, you may also define your own custom views over measures collected by this package. These are declared as a convenience only; none are subscribed by default.

View Source
var (
	DefaultBytesDistribution        = view.DistributionAggregation([]float64{0, 1024, 2048, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864, 268435456, 1073741824, 4294967296})
	DefaultMillisecondsDistribution = view.DistributionAggregation([]float64{0, 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 = view.DistributionAggregation([]float64{0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536})
)

The following variables define the default hard-coded auxiliary data used by both the default GRPC client and GRPC server metrics.

View Source
var (
	KeyMethod, _ = tag.NewKey("method")           // gRPC service and method name
	KeyStatus, _ = tag.NewKey("canonical_status") // Canonical status code
)

All the default client views provided by this package:

All default server views provided by this package:

Functions

func NewClientStatsHandler

func NewClientStatsHandler() stats.Handler

NewClientStatsHandler enables OpenCensus stats and trace for gRPC clients. Deprecated, construct a ClientHandler directly.

func NewServerStatsHandler

func NewServerStatsHandler() stats.Handler

NewServerStatsHandler enables OpenCensus stats and trace for gRPC servers. Deprecated, construct a ServerHandler directly.

Types

type ClientHandler added in v0.4.0

type ClientHandler struct {
	// NoTrace may be set to disable recording OpenCensus Spans around
	// gRPC methods.
	NoTrace bool

	// NoStats may be set to disable recording OpenCensus Stats around each
	// gRPC method.
	NoStats bool
}

ClientHandler implements a gRPC stats.Handler for recording OpenCensus stats and traces. Use with gRPC clients only.

Example
package main

import (
	"log"

	"go.opencensus.io/plugin/ocgrpc"
	"go.opencensus.io/stats/view"
	"google.golang.org/grpc"
)

func main() {
	// Subscribe views to collect data.
	err := view.Subscribe(ocgrpc.DefaultClientViews...)
	if err != nil {
		log.Fatal(err)
	}

	// Set up a connection to the server with the OpenCensus
	// stats handler to enable stats and tracing.
	conn, err := grpc.Dial("address", grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
}
Output:

func (*ClientHandler) HandleConn added in v0.4.0

func (c *ClientHandler) HandleConn(ctx context.Context, cs stats.ConnStats)

func (*ClientHandler) HandleRPC added in v0.4.0

func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

func (*ClientHandler) TagConn added in v0.4.0

func (*ClientHandler) TagRPC added in v0.4.0

type ServerHandler added in v0.4.0

type ServerHandler struct {
	// NoTrace may be set to disable recording OpenCensus Spans around
	// gRPC methods.
	NoTrace bool

	// NoStats may be set to disable recording OpenCensus Stats around each
	// gRPC method.
	NoStats bool
}

ServerHandler implements gRPC stats.Handler recording OpenCensus stats and traces. Use with gRPC servers.

Example
package main

import (
	"log"

	"go.opencensus.io/plugin/ocgrpc"
	"go.opencensus.io/stats/view"
	"google.golang.org/grpc"
)

func main() {
	// Subscribe to views to collect data.
	err := view.Subscribe(ocgrpc.DefaultServerViews...)
	if err != nil {
		log.Fatal(err)
	}

	// Set up a new server with the OpenCensus
	// stats handler to enable stats and tracing.
	s := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
	_ = s // use s
}
Output:

func (*ServerHandler) HandleConn added in v0.4.0

func (s *ServerHandler) HandleConn(ctx context.Context, cs stats.ConnStats)

func (*ServerHandler) HandleRPC added in v0.4.0

func (s *ServerHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

func (*ServerHandler) TagConn added in v0.4.0

func (*ServerHandler) TagRPC added in v0.4.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL