Skip to content

Commit

Permalink
Qualify stat names to avoid collisions (#92)
Browse files Browse the repository at this point in the history
Standard practice for OpenCensus measure names is to qualify them with
project names so the names are unique. Since measure names are never
exported (only view names), this is a safe change.

Also the measures are now exported so library users can create custom
views with them.

Signed-off-by: Grant Rodgers <grantrodgers@google.com>
  • Loading branch information
grantr authored and n3wscott committed Mar 21, 2019
1 parent dd2323e commit c60ffcc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
8 changes: 5 additions & 3 deletions pkg/cloudevents/client/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
)

var (
latencyMs = stats.Float64("client/latency", "The latency in milliseconds for the CloudEvents client methods.", "ms")
// LatencyMs measures the latency in milliseconds for the CloudEvents
// client methods.
LatencyMs = stats.Float64("cloudevents.io/sdk-go/client/latency", "The latency in milliseconds for the CloudEvents client methods.", "ms")
)

var (
// LatencyView is an OpenCensus view that shows client method latency.
LatencyView = &view.View{
Name: "client/latency",
Measure: latencyMs,
Measure: LatencyMs,
Description: "The distribution of latency inside of client for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
Expand Down Expand Up @@ -62,5 +64,5 @@ func (o observed) MethodName() string {

// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return latencyMs
return LatencyMs
}
8 changes: 5 additions & 3 deletions pkg/cloudevents/codec/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package codec

import (
"fmt"

"github.com/cloudevents/sdk-go/pkg/cloudevents/observability"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
)

var (
latencyMs = stats.Float64("codec/json/latency", "The latency in milliseconds for the CloudEvents json codec methods.", "ms")
// LatencyMs measures the latency in milliseconds for the CloudEvents json codec methods.
LatencyMs = stats.Float64("cloudevents.io/sdk-go/codec/json/latency", "The latency in milliseconds for the CloudEvents json codec methods.", "ms")
)

var (
// LatencyView is an OpenCensus view that shows codec/json method latency.
LatencyView = &view.View{
Name: "codec/json/latency",
Measure: latencyMs,
Measure: LatencyMs,
Description: "The distribution of latency inside of the json codec for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
Expand Down Expand Up @@ -58,7 +60,7 @@ func (o observed) MethodName() string {

// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return latencyMs
return LatencyMs
}

// codecObserved is a wrapper to append version to observed.
Expand Down
8 changes: 5 additions & 3 deletions pkg/cloudevents/datacodec/json/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
)

var (
latencyMs = stats.Float64("datacodec/json/latency", "The latency in milliseconds for the CloudEvents json data codec methods.", "ms")
// LatencyMs measures the latency in milliseconds for the CloudEvents json
// data codec methods.
LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/json/latency", "The latency in milliseconds for the CloudEvents json data codec methods.", "ms")
)

var (
// LatencyView is an OpenCensus view that shows data codec json method latency.
LatencyView = &view.View{
Name: "datacodec/json/latency",
Measure: latencyMs,
Measure: LatencyMs,
Description: "The distribution of latency inside of the json data codec for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
Expand Down Expand Up @@ -57,5 +59,5 @@ func (o observed) MethodName() string {

// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return latencyMs
return LatencyMs
}
8 changes: 5 additions & 3 deletions pkg/cloudevents/datacodec/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
)

var (
latencyMs = stats.Float64("datacodec/latency", "The latency in milliseconds for the CloudEvents generic data codec methods.", "ms")
// LatencyMs measures the latency in milliseconds for the CloudEvents generic
// codec data methods.
LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/latency", "The latency in milliseconds for the CloudEvents generic data codec methods.", "ms")
)

var (
// LatencyView is an OpenCensus view that shows data codec method latency.
LatencyView = &view.View{
Name: "datacodec/latency",
Measure: latencyMs,
Measure: LatencyMs,
Description: "The distribution of latency inside of the generic data codec for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
Expand Down Expand Up @@ -57,5 +59,5 @@ func (o observed) MethodName() string {

// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return latencyMs
return LatencyMs
}
8 changes: 5 additions & 3 deletions pkg/cloudevents/datacodec/xml/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
)

var (
latencyMs = stats.Float64("datacodec/xml/latency", "The latency in milliseconds for the CloudEvents xml data codec methods.", "ms")
// LatencyMs measures the latency in milliseconds for the CloudEvents xml data
// codec methods.
LatencyMs = stats.Float64("cloudevents.io/sdk-go/datacodec/xml/latency", "The latency in milliseconds for the CloudEvents xml data codec methods.", "ms")
)

var (
// LatencyView is an OpenCensus view that shows data codec xml method latency.
LatencyView = &view.View{
Name: "datacodec/xml/latency",
Measure: latencyMs,
Measure: LatencyMs,
Description: "The distribution of latency inside of the xml data codec for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
Expand Down Expand Up @@ -57,5 +59,5 @@ func (o observed) MethodName() string {

// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return latencyMs
return LatencyMs
}
11 changes: 7 additions & 4 deletions pkg/cloudevents/transport/http/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package http

import (
"fmt"

"github.com/cloudevents/sdk-go/pkg/cloudevents/observability"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
)

var (
latencyMs = stats.Float64(
"transport/http/latency",
// LatencyMs measures the latency in milliseconds for the http transport
// methods for CloudEvents.
LatencyMs = stats.Float64(
"cloudevents.io/sdk-go/transport/http/latency",
"The latency in milliseconds for the http transport methods for CloudEvents.",
"ms")
)
Expand All @@ -18,7 +21,7 @@ var (
// LatencyView is an OpenCensus view that shows http transport method latency.
LatencyView = &view.View{
Name: "transport/http/latency",
Measure: latencyMs,
Measure: LatencyMs,
Description: "The distribution of latency inside of http transport for CloudEvents.",
Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
TagKeys: observability.LatencyTags(),
Expand Down Expand Up @@ -76,7 +79,7 @@ func (o observed) MethodName() string {

// LatencyMs implements Observable.LatencyMs
func (o observed) LatencyMs() *stats.Float64Measure {
return latencyMs
return LatencyMs
}

// CodecObserved is a wrapper to append version to observed.
Expand Down

0 comments on commit c60ffcc

Please sign in to comment.