dcensus

package
v0.0.0-...-642d756 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package dcensus provides functionality for debug instrumentation.

Index

Constants

This section is empty.

Variables

View Source
var (
	ServerRequestCount = &view.View{
		Name:        "go-discovery/http/server/request_count",
		Description: "Count of HTTP requests started by Method",
		TagKeys:     []tag.Key{ochttp.Method},
		Measure:     ochttp.ServerRequestCount,
		Aggregation: view.Count(),
	}
	ServerResponseCount = &view.View{
		Name:        "go-discovery/http/server/response_count",
		Description: "Server response count by status code and route",
		TagKeys:     []tag.Key{ochttp.StatusCode, ochttp.KeyServerRoute},
		Measure:     ochttp.ServerLatency,
		Aggregation: view.Count(),
	}
	ServerLatency = &view.View{
		Name:        "go-discovery/http/server/response_latency",
		Description: "Server response distribution by status code and route",
		TagKeys:     []tag.Key{ochttp.KeyServerRoute},
		Measure:     ochttp.ServerLatency,
		Aggregation: ochttp.DefaultLatencyDistribution,
	}
	ServerResponseBytes = &view.View{
		Name:        "go-discovery/http/server/response_bytes",
		Description: "Size distribution of HTTP response body",
		TagKeys:     []tag.Key{ochttp.KeyServerRoute},
		Measure:     ochttp.ServerResponseBytes,
		Aggregation: ochttp.DefaultSizeDistribution,
	}
	ServerViews = []*view.View{
		ServerRequestCount,
		ServerResponseCount,
		ServerLatency,
		ServerResponseBytes,
	}
)

Customizations of ochttp views. Views are updated as follows:

  • ClientHost and ServerRoute are added to resp. client and server metrics. Since these are bounded cardinality in our metrics, they are useful to add additional context.
  • Method tags are removed. We don't have any routes that accept more than one HTTP method.
View Source
var KeyStatus = tag.MustNewKey("status")

KeyStatus is a tag key named "status".

Functions

func DebugHandler

func DebugHandler() (http.Handler, error)

DebugHandler creates a new http.Handler for serving debug information.

func Init

func Init(cfg *config.Config, views ...*view.View) error

Init configures tracing and aggregation according to the given Views. If running on GCP, Init also configures exporting to StackDriver.

func MDur

MDur returns the latency value used for recording a measurement with opencensus.

func NewViewExporter

func NewViewExporter(cfg *config.Config) (_ *stackdriver.Exporter, err error)

NewViewExporter creates a StackDriver exporter for stats.

func RecordWithTag

func RecordWithTag(ctx context.Context, key tag.Key, val string, m stats.Measurement)

RecordWithTag is a convenience function for recording a single measurement with a single tag.

Types

type RouteTagger

type RouteTagger func(route string, r *http.Request) string

RouteTagger is a func that can be used to derive a dynamic route tag for an incoming request.

type Router

type Router struct {
	http.Handler
	// contains filtered or unexported fields
}

Router is an http multiplexer that instruments per-handler debugging information and census instrumentation.

func NewRouter

func NewRouter(tagger RouteTagger) *Router

NewRouter creates a new Router, using tagger to tag incoming requests in monitoring. If tagger is nil, a default route tagger is used.

func (*Router) Handle

func (r *Router) Handle(route string, handler http.Handler)

Handle registers handler with the given route. It has the same routing semantics as http.ServeMux.

func (*Router) HandleFunc

func (r *Router) HandleFunc(route string, handler http.HandlerFunc)

HandleFunc is a wrapper around Handle for http.HandlerFuncs.

Jump to

Keyboard shortcuts

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