Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Drop the registry package
Browse files Browse the repository at this point in the history
This is to shrink the PR open-telemetry#100.

The only place where the registry.Variable type was used was metrics,
so just inline that type into its only user. The use of the
registry.Variable type in core.Key was limited to the Name field.

The stats package also used the registry.Variable type, but seems that
also only the Name field was used and the package is going to be
dropped anyway.
  • Loading branch information
krnowak committed Sep 19, 2019
1 parent cb0d352 commit 0d677f9
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 161 deletions.
6 changes: 2 additions & 4 deletions api/core/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package core
import (
"fmt"
"unsafe"

"go.opentelemetry.io/api/registry"
)

type Key struct {
Variable registry.Variable
Name string
}

type KeyValue struct {
Expand Down Expand Up @@ -148,7 +146,7 @@ func (k Key) Uint(v uint) KeyValue {
}

func (k Key) Defined() bool {
return k.Variable.Defined()
return len(k.Name) != 0
}

// TODO make this a lazy one-time conversion.
Expand Down
7 changes: 2 additions & 5 deletions api/core/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/google/go-cmp/cmp"

"go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/registry"
)

func TestBool(t *testing.T) {
Expand Down Expand Up @@ -306,15 +305,13 @@ func TestDefined(t *testing.T) {
{
name: "Key.Defined() returns true when len(v.Name) != 0",
k: core.Key{
registry.Variable{
Name: "foo",
},
Name: "foo",
},
want: true,
},
{
name: "Key.Defined() returns false when len(v.Name) == 0",
k: core.Key{registry.Variable{}},
k: core.Key{},
want: false,
},
} {
Expand Down
16 changes: 2 additions & 14 deletions api/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@ package key

import (
"go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/registry"
)

type AnyValue struct{}

func (AnyValue) String() string {
return "AnyValue"
}

func New(name string, opts ...registry.Option) core.Key {
func New(name string) core.Key {
return core.Key{
Variable: registry.Register(name, AnyValue{}, opts...),
Name: name,
}
}

var (
WithDescription = registry.WithDescription
WithUnit = registry.WithUnit
)
17 changes: 9 additions & 8 deletions api/metric/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"

"go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/registry"
"go.opentelemetry.io/api/unit"
)

Expand All @@ -40,31 +39,33 @@ type Float64Gauge interface {
}

type Handle struct {
Variable registry.Variable
Name string
Description string
Unit unit.Unit

Type MetricType
Keys []core.Key
}

type Option func(*Handle, *[]registry.Option)
type Option func(*Handle)

// WithDescription applies provided description.
func WithDescription(desc string) Option {
return func(_ *Handle, to *[]registry.Option) {
*to = append(*to, registry.WithDescription(desc))
return func(m *Handle) {
m.Description = desc
}
}

// WithUnit applies provided unit.
func WithUnit(unit unit.Unit) Option {
return func(_ *Handle, to *[]registry.Option) {
*to = append(*to, registry.WithUnit(unit))
return func(m *Handle) {
m.Unit = unit
}
}

// WithKeys applies the provided dimension keys.
func WithKeys(keys ...core.Key) Option {
return func(m *Handle, _ *[]registry.Option) {
return func(m *Handle) {
m.Keys = keys
}
}
Expand Down
10 changes: 2 additions & 8 deletions api/metric/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@

package metric

import (
"go.opentelemetry.io/api/registry"
)

func registerMetric(name string, mtype MetricType, opts []Option, metric *Handle) {
var varOpts []registry.Option

for _, opt := range opts {
opt(metric, &varOpts)
opt(metric)
}

metric.Variable = registry.Register(name, mtype, varOpts...)
metric.Name = name
metric.Type = mtype
}
15 changes: 0 additions & 15 deletions api/registry/doc.go

This file was deleted.

69 changes: 0 additions & 69 deletions api/registry/registry.go

This file was deleted.

28 changes: 8 additions & 20 deletions api/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import (
"sync/atomic"

"go.opentelemetry.io/api/core"
"go.opentelemetry.io/api/registry"
)

type MeasureHandle struct {
Variable registry.Variable
Name string
}

type Measure interface {
V() registry.Variable
N() string
M(value float64) Measurement
}

Expand Down Expand Up @@ -71,20 +70,9 @@ func RecordSingle(ctx context.Context, m Measurement) {
GlobalRecorder().RecordSingle(ctx, m)
}

type AnyStatistic struct{}

func (AnyStatistic) String() string {
return "AnyStatistic"
}

var (
WithDescription = registry.WithDescription
WithUnit = registry.WithUnit
)

func NewMeasure(name string, opts ...registry.Option) *MeasureHandle {
func NewMeasure(name string) *MeasureHandle {
return &MeasureHandle{
Variable: registry.Register(name, AnyStatistic{}, opts...),
Name: name,
}
}

Expand All @@ -95,8 +83,8 @@ func (m *MeasureHandle) M(value float64) Measurement {
}
}

func (m *MeasureHandle) V() registry.Variable {
return m.Variable
func (m *MeasureHandle) N() string {
return m.Name
}

func (noopRecorder) Record(ctx context.Context, m ...Measurement) {
Expand All @@ -113,6 +101,6 @@ func (noopMeasure) M(float64) Measurement {
return Measurement{}
}

func (noopMeasure) V() registry.Variable {
return registry.Variable{}
func (noopMeasure) N() string {
return ""
}
2 changes: 1 addition & 1 deletion api/tag/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Do(ctx context.Context, f func(ctx context.Context)) {
m := FromContext(ctx)
keyvals := make([]string, 0, 2*len(m.m))
for k, v := range m.m {
keyvals = append(keyvals, k.Variable.Name, v.value.Emit())
keyvals = append(keyvals, k.Name, v.value.Emit())
}
pprof.Do(ctx, pprof.Labels(keyvals...), f)
}
7 changes: 3 additions & 4 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"go.opentelemetry.io/api/key"
"go.opentelemetry.io/api/metric"
"go.opentelemetry.io/api/registry"
"go.opentelemetry.io/api/stats"
"go.opentelemetry.io/api/tag"
"go.opentelemetry.io/api/trace"
Expand All @@ -34,9 +33,9 @@ var (

meter = metric.GlobalMeter() // TODO: should share resources ^^^?

fooKey = key.New("ex.com/foo", registry.WithDescription("A Foo var"))
barKey = key.New("ex.com/bar", registry.WithDescription("A Bar var"))
lemonsKey = key.New("ex.com/lemons", registry.WithDescription("A Lemons var"))
fooKey = key.New("ex.com/foo")
barKey = key.New("ex.com/bar")
lemonsKey = key.New("ex.com/lemons")
anotherKey = key.New("ex.com/another")

oneMetric = metric.NewFloat64Gauge("ex.com/one",
Expand Down
8 changes: 4 additions & 4 deletions experimental/streaming/exporter/reader/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
if skipIf && data.Attributes.HasValue(kv.Key) {
return true
}
buf.WriteString(" " + kv.Key.Variable.Name + "=" + kv.Value.Emit())
buf.WriteString(" " + kv.Key.Name + "=" + kv.Value.Emit())
return true
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
buf.WriteString(data.Message)
buf.WriteString(" (")
data.Attributes.Foreach(func(kv core.KeyValue) bool {
buf.WriteString(" " + kv.Key.Variable.Name + "=" + kv.Value.Emit())
buf.WriteString(" " + kv.Key.Name + "=" + kv.Value.Emit())
return true
})
buf.WriteString(")")
Expand All @@ -86,7 +86,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {

for _, s := range data.Stats {
f(false)(core.Key{
Variable: s.Measure.V(),
Name: s.Measure.N(),
}.Float64(s.Value))

buf.WriteString(" {")
Expand All @@ -96,7 +96,7 @@ func AppendEvent(buf *strings.Builder, data reader.Event) {
buf.WriteString(",")
}
i++
buf.WriteString(kv.Key.Variable.Name)
buf.WriteString(kv.Key.Name)
buf.WriteString("=")
buf.WriteString(kv.Value.Emit())
return true
Expand Down
4 changes: 1 addition & 3 deletions experimental/streaming/sdk/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ var (
ErrorKey = key.New("error")
SpanIDKey = key.New("span_id")
TraceIDKey = key.New("trace_id")
MessageKey = key.New("message",
key.WithDescription("message text: info, error, etc"),
)
MessageKey = key.New("message")
)

func New() trace.Tracer {
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func spanDataToThrift(data *trace.SpanData) *gen.Span {
for _, a := range data.MessageEvents {
fields := make([]*gen.Tag, 0, len(a.Attributes))
for _, kv := range a.Attributes {
tag := attributeToTag(kv.Key.Variable.Name, kv.Value.Emit())
tag := attributeToTag(kv.Key.Name, kv.Value.Emit())
if tag != nil {
fields = append(fields, tag)
}
Expand Down
4 changes: 1 addition & 3 deletions plugin/httptrace/clienttrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ var (
HTTPHeaderMIME = key.New("http.mime")
HTTPRemoteAddr = key.New("http.remote")
HTTPLocalAddr = key.New("http.local")
MessageKey = key.New("message",
key.WithDescription("message text: info, error, etc"),
)
MessageKey = key.New("message")
)

type clientTracer struct {
Expand Down
2 changes: 1 addition & 1 deletion plugin/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (h hinjector) Inject(sc core.SpanContext, tags tag.Map) {
// TODO: implement MaxHops
tc.TraceState = append(tc.TraceState, tracestate.Member{
Vendor: Vendor,
Tenant: kv.Key.Variable.Name,
Tenant: kv.Key.Name,
Value: kv.Value.Emit(),
})
return true
Expand Down
Loading

0 comments on commit 0d677f9

Please sign in to comment.