From 0919c44499509e1597af96f593ff18e699834c24 Mon Sep 17 00:00:00 2001 From: Ramon Nogueira Date: Thu, 15 Mar 2018 11:07:48 -0700 Subject: [PATCH] Links in tracez should be relative Fixes: #559 --- examples/grpc/helloworld_server/main.go | 11 ++++++++++- stats/view/worker.go | 3 +-- zpages/rpcz_test.go | 5 ++++- zpages/tracez.go | 10 ++++------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/examples/grpc/helloworld_server/main.go b/examples/grpc/helloworld_server/main.go index e1a2898c5..fc6c48e6f 100644 --- a/examples/grpc/helloworld_server/main.go +++ b/examples/grpc/helloworld_server/main.go @@ -18,13 +18,16 @@ package main import ( "log" + "math/rand" "net" "net/http" + "time" "go.opencensus.io/examples/exporter" pb "go.opencensus.io/examples/grpc/proto" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/stats/view" + "go.opencensus.io/trace" "go.opencensus.io/zpages" "golang.org/x/net/context" "google.golang.org/grpc" @@ -38,11 +41,17 @@ type server struct{} // SayHello implements helloworld.GreeterServer func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { + ctx, span := trace.StartSpan(ctx, "sleep") + time.Sleep(time.Duration(rand.Float64() * float64(time.Second))) + span.End() return &pb.HelloReply{Message: "Hello " + in.Name}, nil } func main() { - go func() { log.Fatal(http.ListenAndServe(":8081", zpages.Handler)) }() + go func() { + http.Handle("/debug/", http.StripPrefix("/debug", zpages.Handler)) + log.Fatal(http.ListenAndServe(":8081", nil)) + }() // Register stats and trace exporters to export // the collected data. view.RegisterExporter(&exporter.PrintExporter{}) diff --git a/stats/view/worker.go b/stats/view/worker.go index 2eaf430f0..924ffe5c7 100644 --- a/stats/view/worker.go +++ b/stats/view/worker.go @@ -80,8 +80,7 @@ func (v *View) Subscribe() error { // Once a view is subscribed, it reports data to the registered exporters. func Subscribe(views ...*View) error { for _, v := range views { - err := v.canonicalize() - if err != nil { + if err := v.canonicalize(); err != nil { return err } } diff --git a/zpages/rpcz_test.go b/zpages/rpcz_test.go index dabf9f5bf..3f511efb9 100644 --- a/zpages/rpcz_test.go +++ b/zpages/rpcz_test.go @@ -1,4 +1,4 @@ -// Copyright 2017, OpenCensus Authors +// Copyright 2018, OpenCensus Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -102,6 +102,9 @@ func TestRpcz(t *testing.T) { time.Sleep(2 * time.Millisecond) view.SetReportingPeriod(time.Second) + mu.Lock() + defer mu.Unlock() + if len(snaps) == 0 { t.Fatal("Expected len(snaps) > 0") } diff --git a/zpages/tracez.go b/zpages/tracez.go index cff903546..e3ff2c4ab 100644 --- a/zpages/tracez.go +++ b/zpages/tracez.go @@ -408,14 +408,10 @@ type summaryPageRow struct { Errors int } -func (s *summaryPageData) Len() int { return len(s.Rows) } -func (s *summaryPageData) Less(i, j int) bool { return s.Rows[i].Name < s.Rows[j].Name } -func (s *summaryPageData) Swap(i, j int) { s.Rows[i], s.Rows[j] = s.Rows[j], s.Rows[i] } - func getSummaryPageData() summaryPageData { data := summaryPageData{ Links: true, - TracesEndpoint: "/tracez", + TracesEndpoint: "tracez", } internalTrace := internal.Trace.(interface { ReportSpansPerMethod() map[string]internal.PerMethodSummary @@ -443,6 +439,8 @@ func getSummaryPageData() summaryPageData { } data.Rows = append(data.Rows, row) } - sort.Sort(&data) + sort.Slice(data.Rows, func(i, j int) bool { + return data.Rows[i].Name < data.Rows[j].Name + }) return data }