Skip to content

Commit

Permalink
update type style (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou authored and rghetia committed Jun 28, 2019
1 parent f5ec719 commit 36f5138
Show file tree
Hide file tree
Showing 23 changed files with 362 additions and 412 deletions.
138 changes: 68 additions & 70 deletions api/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,98 +24,96 @@ import (
"github.com/open-telemetry/opentelemetry-go/api/unit"
)

type (
ScopeID struct {
EventID
SpanContext
}
type ScopeID struct {
EventID
SpanContext
}

SpanContext struct {
TraceIDHigh uint64
TraceIDLow uint64
SpanID uint64
}
type SpanContext struct {
TraceIDHigh uint64
TraceIDLow uint64
SpanID uint64
}

EventID uint64
type EventID uint64

BaseMeasure interface {
Name() string
Description() string
Unit() unit.Unit
type BaseMeasure interface {
Name() string
Description() string
Unit() unit.Unit

DefinitionID() EventID
}
DefinitionID() EventID
}

Measure interface {
BaseMeasure
type Measure interface {
BaseMeasure

M(float64) Measurement
V(float64) KeyValue
}
M(float64) Measurement
V(float64) KeyValue
}

Measurement struct {
// NOTE: If we add a ScopeID field this can carry
// pre-aggregated measures via the stats.Record API.
Measure Measure
Value float64
ScopeID ScopeID
}
type Measurement struct {
// NOTE: If we add a ScopeID field this can carry
// pre-aggregated measures via the stats.Record API.
Measure Measure
Value float64
ScopeID ScopeID
}

Key interface {
BaseMeasure
type Key interface {
BaseMeasure

Value(ctx context.Context) KeyValue
Value(ctx context.Context) KeyValue

Bool(v bool) KeyValue
Bool(v bool) KeyValue

Int(v int) KeyValue
Int32(v int32) KeyValue
Int64(v int64) KeyValue
Int(v int) KeyValue
Int32(v int32) KeyValue
Int64(v int64) KeyValue

Uint(v uint) KeyValue
Uint32(v uint32) KeyValue
Uint64(v uint64) KeyValue
Uint(v uint) KeyValue
Uint32(v uint32) KeyValue
Uint64(v uint64) KeyValue

Float32(v float32) KeyValue
Float64(v float64) KeyValue
Float32(v float32) KeyValue
Float64(v float64) KeyValue

String(v string) KeyValue
Bytes(v []byte) KeyValue
}
String(v string) KeyValue
Bytes(v []byte) KeyValue
}

KeyValue struct {
Key Key
Value Value
}
type KeyValue struct {
Key Key
Value Value
}

ValueType int
type ValueType int

Value struct {
Type ValueType
Bool bool
Int64 int64
Uint64 uint64
Float64 float64
String string
Bytes []byte
type Value struct {
Type ValueType
Bool bool
Int64 int64
Uint64 uint64
Float64 float64
String string
Bytes []byte

// TODO Lazy value type?
}
// TODO Lazy value type?
}

MutatorOp int
type MutatorOp int

Mutator struct {
MutatorOp
KeyValue
MeasureMetadata
}
type Mutator struct {
MutatorOp
KeyValue
MeasureMetadata
}

MeasureMetadata struct {
MaxHops int // -1 == infinite, 0 == do not propagate
type MeasureMetadata struct {
MaxHops int // -1 == infinite, 0 == do not propagate

// TODO time to live?
}
)
// TODO time to live?
}

const (
INVALID ValueType = iota
Expand Down
16 changes: 7 additions & 9 deletions api/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import (
"github.com/open-telemetry/opentelemetry-go/api/core"
)

type (
// Event interface provides methods to retrieve Event properties.
Event interface {
// Event interface provides methods to retrieve Event properties.
type Event interface {

// Message interface retrieves message string of the Event.
Message() string
// Message interface retrieves message string of the Event.
Message() string

// Attributes interface returns a copy of attributes associated with the Event.
Attributes() []core.KeyValue
}
)
// Attributes interface returns a copy of attributes associated with the Event.
Attributes() []core.KeyValue
}
25 changes: 10 additions & 15 deletions api/metric/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ import (
"github.com/open-telemetry/opentelemetry-go/api/unit"
)

type (
Metric interface {
Measure() core.Measure
type Metric interface {
Measure() core.Measure

DefinitionID() core.EventID
DefinitionID() core.EventID

Type() MetricType
Fields() []core.Key
Err() error
Type() MetricType
Fields() []core.Key
Err() error

base() *baseMetric
}

MetricType int
)
base() *baseMetric
}
type MetricType int

const (
Invalid MetricType = iota
Expand All @@ -48,9 +45,7 @@ const (
DerivedCumulativeFloat64
)

type (
Option func(*baseMetric, *[]tag.Option)
)
type Option func(*baseMetric, *[]tag.Option)

// WithDescription applies provided description.
func WithDescription(desc string) Option {
Expand Down
28 changes: 13 additions & 15 deletions api/metric/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@ import (
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
)

type (
baseMetric struct {
measure core.Measure

mtype MetricType
keys []core.Key
eventID core.EventID
status error // Indicates registry conflict
}
type baseMetric struct {
measure core.Measure

baseEntry struct {
base *baseMetric
metric Metric
eventID core.EventID
}
)
mtype MetricType
keys []core.Key
eventID core.EventID
status error // Indicates registry conflict
}

type baseEntry struct {
base *baseMetric
metric Metric
eventID core.EventID
}

func initBaseMetric(name string, mtype MetricType, opts []Option, init Metric) Metric {
var tagOpts []tag.Option
Expand Down
16 changes: 7 additions & 9 deletions api/metric/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import (
"github.com/open-telemetry/opentelemetry-go/api/stats"
)

type (
Float64Gauge struct {
baseMetric
}

Float64Entry struct {
baseEntry
}
)
type Float64Gauge struct {
baseMetric
}

type Float64Entry struct {
baseEntry
}

func NewFloat64Gauge(name string, mos ...Option) *Float64Gauge {
m := initBaseMetric(name, GaugeFloat64, mos, &Float64Gauge{}).(*Float64Gauge)
Expand Down
20 changes: 9 additions & 11 deletions api/metric/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ import (
"sync"
)

type (
// Registry is a mechanism for avoiding duplicate registration
// of different-type pre-aggregated metrics (in one process).
Registry interface {
RegisterMetric(Metric) (Metric, error)
ForeachMetric(func(string, Metric))
}
// Registry is a mechanism for avoiding duplicate registration
// of different-type pre-aggregated metrics (in one process).
type Registry interface {
RegisterMetric(Metric) (Metric, error)
ForeachMetric(func(string, Metric))
}

registry struct {
nameType sync.Map // map[string]Metric
}
)
type registry struct {
nameType sync.Map // map[string]Metric
}

var (
registryLock sync.Mutex
Expand Down
30 changes: 14 additions & 16 deletions api/scope/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,25 @@ import (
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
)

type (
Scope interface {
ScopeID() core.ScopeID
}
type Scope interface {
ScopeID() core.ScopeID
}

Mutable interface {
Scope
type Mutable interface {
Scope

SetAttribute(core.KeyValue)
SetAttributes(...core.KeyValue)
SetAttribute(core.KeyValue)
SetAttributes(...core.KeyValue)

ModifyAttribute(core.Mutator)
ModifyAttributes(...core.Mutator)
}
ModifyAttribute(core.Mutator)
ModifyAttributes(...core.Mutator)
}

scopeIdent struct {
id core.ScopeID
}
type scopeIdent struct {
id core.ScopeID
}

scopeKeyType struct{}
)
type scopeKeyType struct{}

var (
scopeKey = &scopeKeyType{}
Expand Down
16 changes: 7 additions & 9 deletions api/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import (
"github.com/open-telemetry/opentelemetry-go/exporter/observer"
)

type (
Interface interface {
Record(ctx context.Context, m ...core.Measurement)
RecordSingle(ctx context.Context, m core.Measurement)
}
type Interface interface {
Record(ctx context.Context, m ...core.Measurement)
RecordSingle(ctx context.Context, m core.Measurement)
}

Recorder struct {
core.ScopeID
}
)
type Recorder struct {
core.ScopeID
}

func With(scope scope.Scope) Recorder {
return Recorder{scope.ScopeID()}
Expand Down
Loading

0 comments on commit 36f5138

Please sign in to comment.