Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
example/main.go: avoid using clashing/unpublished ocagent version
Browse files Browse the repository at this point in the history
Because of clashes with unpublished versions of opencensus-proto
as per census-instrumentation/opencensus-proto#161

we can't update ocagent to use the view.Exporter code, because
the unpublished opencensus-proto is what provides support for
the grpc-gateway. Hence this commit checks in the previous version
of example/main.go until that release.
  • Loading branch information
odeke-em committed Jan 10, 2019
1 parent 7d2b3ae commit af92f35
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (
"time"

"contrib.go.opencensus.io/exporter/ocagent"

"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.opencensus.io/trace"
)

Expand All @@ -35,50 +31,14 @@ func main() {
log.Fatalf("Failed to create ocagent-exporter: %v", err)
}
trace.RegisterExporter(oce)
view.RegisterExporter(oce)

trace.ApplyConfig(trace.Config{
DefaultSampler: trace.AlwaysSample(),
})

// By setting the reporting period to 4s, the underlying view.Data that's
// generated will be submitted to the view.Exporter-s every 4s.
view.SetReportingPeriod(4 * time.Second)

// Some stats
keyClient, _ := tag.NewKey("client")
keyMethod, _ := tag.NewKey("method")

mLatencyMs := stats.Float64("latency", "The latency in milliseconds", "ms")
views := []*view.View{
&view.View{
Name: "opdemo/latency",
Description: "The latency of each iteration",
Measure: mLatencyMs,
Aggregation: view.Distribution(0, 10, 50, 100, 200, 400, 800, 1000, 1400, 2000, 5000, 10000),
TagKeys: []tag.Key{keyClient, keyMethod},
},
&view.View{
Name: "opdemo/process_counts",
Description: "The various counts",
Measure: mLatencyMs,
Aggregation: view.Count(),
TagKeys: []tag.Key{keyClient, keyMethod},
},
}

if err := view.Register(views...); err != nil {
log.Fatalf("Failed to register views for metrics: %v", err)
}

ctx, _ := tag.New(context.Background(), tag.Insert(keyMethod, "repl"), tag.Insert(keyClient, "cli"))
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
for {
startTime := time.Now()
_, span := trace.StartSpan(ctx, "Foo")
time.Sleep(time.Duration(rng.Int63n(13000)) * time.Millisecond)
_, span := trace.StartSpan(context.Background(), "foo")
time.Sleep(time.Duration(rng.Int63n(1000)) * time.Millisecond)
span.End()
latencyMs := float64(time.Since(startTime) / time.Millisecond)
stats.Record(ctx, mLatencyMs.M(latencyMs))
}
}

0 comments on commit af92f35

Please sign in to comment.