Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Links in tracez should be relative
Browse files Browse the repository at this point in the history
Fixes: #559
  • Loading branch information
Ramon Nogueira committed Mar 16, 2018
1 parent 5e1a3e8 commit 0919c44
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
11 changes: 10 additions & 1 deletion examples/grpc/helloworld_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{})
Expand Down
3 changes: 1 addition & 2 deletions stats/view/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
5 changes: 4 additions & 1 deletion zpages/rpcz_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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")
}
Expand Down
10 changes: 4 additions & 6 deletions zpages/tracez.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 0919c44

Please sign in to comment.