diff --git a/cmd/etl/main.go b/cmd/etl/main.go index c387f03c..4010377d 100644 --- a/cmd/etl/main.go +++ b/cmd/etl/main.go @@ -26,7 +26,6 @@ import ( "golang.org/x/discovery/internal/proxy" "contrib.go.opencensus.io/integrations/ocsql" - "go.opencensus.io/plugin/ochttp" ) var ( @@ -84,15 +83,14 @@ func main() { router := dcensus.NewRouter(nil) server.Install(router.Handle) - views := append(ochttp.DefaultServerViews, ochttp.DefaultClientViews...) - views = append(views, dcensus.ViewByCodeRouteMethod, dcensus.ViewByCodeRouteMethodLatencyDistribution) + views := append(dcensus.ClientViews, dcensus.ServerViews...) if err := dcensus.Init(views...); err != nil { log.Fatal(err) } // We are not currently forwarding any ports on AppEngine, so serving debug // information is broken. if !config.OnAppEngine() { - dcensusServer, err := dcensus.NewServer(views...) + dcensusServer, err := dcensus.NewServer() if err != nil { log.Fatal(err) } diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index 23751270..4870d334 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -14,7 +14,6 @@ import ( "cloud.google.com/go/logging" "contrib.go.opencensus.io/integrations/ocsql" - "go.opencensus.io/plugin/ochttp" "golang.org/x/discovery/internal/config" "golang.org/x/discovery/internal/dcensus" "golang.org/x/discovery/internal/frontend" @@ -68,14 +67,13 @@ func main() { router := dcensus.NewRouter(frontend.TagRoute) server.Install(router.Handle) - views := append(ochttp.DefaultServerViews, dcensus.ViewByCodeRouteMethod, dcensus.ViewByCodeRouteMethodLatencyDistribution) - if err := dcensus.Init(views...); err != nil { + if err := dcensus.Init(dcensus.ServerViews...); err != nil { log.Fatal(err) } // We are not currently forwarding any ports on AppEngine, so serving debug // information is broken. if !config.OnAppEngine() { - dcensusServer, err := dcensus.NewServer(views...) + dcensusServer, err := dcensus.NewServer() if err != nil { log.Fatal(err) } diff --git a/cmd/prober/main.go b/cmd/prober/main.go index 5075eea5..471ee006 100644 --- a/cmd/prober/main.go +++ b/cmd/prober/main.go @@ -102,7 +102,7 @@ var ( ) firstByteLatencyDistribution = &view.View{ - Name: "go-discovery/first_byte_latency", + Name: "custom.googleapis.com/go-discovery/prober/first_byte_latency", Measure: firstByteLatency, Aggregation: ochttp.DefaultLatencyDistribution, Description: "first-byte latency, by probe name and response status", diff --git a/internal/dcensus/dcensus.go b/internal/dcensus/dcensus.go index a17ff32b..ca2cf52d 100644 --- a/internal/dcensus/dcensus.go +++ b/internal/dcensus/dcensus.go @@ -87,7 +87,7 @@ func Init(views ...*view.View) error { } // NewServer creates a new http.Handler for serving debug information. -func NewServer(views ...*view.View) (http.Handler, error) { +func NewServer() (http.Handler, error) { pe, err := prometheus.NewExporter(prometheus.Options{}) if err != nil { return nil, fmt.Errorf("dcensus.NewServer: prometheus.NewExporter: %v", err) @@ -170,27 +170,74 @@ func NewViewExporter() (_ *stackdriver.Exporter, err error) { }) } -const ( - codeRouteMethodCount = "opencensus.io/http/server/response_count_by_status_code_route_method" - codeRouteMethodLatency = "opencensus.io/http/server/response_latency_distribution_by_status_code_route_method" +// Customizations of ochttp views. Views are updated as follows: +// + names are changed to use the custom.googleapis.com prefix, in accordance +// with https://cloud.google.com/monitoring/api/v3/metrics-details#label_names +// + 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. +var ( + ClientCompletedCount = &view.View{ + Name: "custom.googleapis.com/go-discovery/http/client/completed_count", + Measure: ochttp.ClientRoundtripLatency, + Aggregation: view.Count(), + Description: "Count of completed requests, by HTTP method and response status", + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientStatus}, + } + ClientRoundtripLatencyDistribution = &view.View{ + Name: "custom.googleapis.com/go-discovery/http/client/roundtrip_latency", + Measure: ochttp.ClientRoundtripLatency, + Aggregation: ochttp.DefaultLatencyDistribution, + Description: "End-to-end latency, by ClientHost and ClientStatus", + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientStatus}, + } + ClientReceivedBytesDistribution = &view.View{ + Name: "custom.googleapis.com/go-discovery/http/client/received_bytes", + Measure: ochttp.ClientReceivedBytes, + Aggregation: ochttp.DefaultSizeDistribution, + Description: "Total bytes received in response bodies (not including headers but including " + + "error responses with bodies), by ClientHost and ClientStatus", + TagKeys: []tag.Key{ochttp.KeyClientHost, ochttp.KeyClientStatus}, + } + ServerRequestCount = &view.View{ + Name: "custom.googleapis.com/go-discovery/http/server/request_count", + Description: "Count of HTTP requests started by ServerRoute", + TagKeys: []tag.Key{ochttp.KeyServerRoute}, + Measure: ochttp.ServerRequestCount, + Aggregation: view.Count(), + } + ServerResponseCount = &view.View{ + Name: "custom.googleapis.com/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: "custom.googleapis.com/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: "custom.googleapis.com/go-discovery/http/server/response_bytes", + Description: "Size distribution of HTTP response body", + TagKeys: []tag.Key{ochttp.KeyServerRoute}, + Measure: ochttp.ServerResponseBytes, + Aggregation: ochttp.DefaultSizeDistribution, + } + ClientViews = []*view.View{ + ClientCompletedCount, + ClientRoundtripLatencyDistribution, + ClientReceivedBytesDistribution, + } + ServerViews = []*view.View{ + ServerRequestCount, + ServerResponseCount, + ServerLatency, + ServerResponseBytes, + } ) - -// ViewByCodeRouteMethod is a view of HTTP server requests parameterized -// by StatusCode, Route, and HTTP method. -var ViewByCodeRouteMethod = &view.View{ - Name: codeRouteMethodCount, - Description: "Server response count by status code", - TagKeys: []tag.Key{ochttp.StatusCode, ochttp.KeyServerRoute, ochttp.Method}, - Measure: ochttp.ServerLatency, - Aggregation: view.Count(), -} - -// ViewByCodeRouteMethodLatencyDistribution is a view of HTTP server requests -// parameterized by StatusCode, Route, and HTTP method. -var ViewByCodeRouteMethodLatencyDistribution = &view.View{ - Name: codeRouteMethodLatency, - Description: "Server response distribution by status code", - TagKeys: []tag.Key{ochttp.StatusCode, ochttp.KeyServerRoute, ochttp.Method}, - Measure: ochttp.ServerLatency, - Aggregation: ochttp.DefaultLatencyDistribution, -} diff --git a/internal/dcensus/dcensus_test.go b/internal/dcensus/dcensus_test.go index bd4d3ce6..6389118e 100644 --- a/internal/dcensus/dcensus_test.go +++ b/internal/dcensus/dcensus_test.go @@ -16,7 +16,7 @@ import ( ) func TestRouter(t *testing.T) { - view.Register(ViewByCodeRouteMethod) + view.Register(ServerResponseCount) handler := func(w http.ResponseWriter, r *http.Request) {} tagger := func(route string, r *http.Request) string { tag := strings.Trim(route, "/") @@ -40,7 +40,7 @@ func TestRouter(t *testing.T) { } resp.Body.Close() } - rows, err := view.RetrieveData(codeRouteMethodCount) + rows, err := view.RetrieveData(ServerResponseCount.Name) if err != nil { t.Fatal(err) }