Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sub-package value from kv #968

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Removed

- Removed dependency on `github.com/open-telemetry/opentelemetry-collector`. (#943)
- Removed `go.opentelemetry.io/otel/api/kv/value` by flattening all value functionality and structures into the `go.opentelemetry.io/otel/api/kv` package. (#968)

## [0.8.0] - 2020-07-09

Expand Down
6 changes: 2 additions & 4 deletions api/correlation/correlation_context_propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"strings"
"testing"

"go.opentelemetry.io/otel/api/kv/value"

"github.com/google/go-cmp/cmp"

"go.opentelemetry.io/otel/api/correlation"
Expand Down Expand Up @@ -105,7 +103,7 @@ func TestExtractValidDistributedContextFromHTTPReq(t *testing.T) {
totalDiff := ""
wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool {
val, _ := gotCorCtx.Value(keyValue.Key)
diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(value.Value{}))
diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(kv.Value{}))
if diff != "" {
totalDiff += diff + "\n"
}
Expand Down Expand Up @@ -166,7 +164,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
totalDiff := ""
wantCorCtx.Foreach(func(keyValue kv.KeyValue) bool {
val, _ := gotCorCtx.Value(keyValue.Key)
diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(value.Value{}))
diff := cmp.Diff(keyValue, kv.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(kv.Value{}))
if diff != "" {
totalDiff += diff + "\n"
}
Expand Down
5 changes: 2 additions & 3 deletions api/correlation/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ package correlation

import (
"go.opentelemetry.io/otel/api/kv"
"go.opentelemetry.io/otel/api/kv/value"
)

type rawMap map[kv.Key]value.Value
type rawMap map[kv.Key]kv.Value
type keySet map[kv.Key]struct{}

// Map is an immutable storage for correlations.
Expand Down Expand Up @@ -147,7 +146,7 @@ func getNewMapSize(m rawMap, delSet, addSet keySet) int {

// Value gets a value from correlations map and returns a boolean
// value indicating whether the key exist in the map.
func (m Map) Value(k kv.Key) (value.Value, bool) {
func (m Map) Value(k kv.Key) (kv.Value, bool) {
value, ok := m.m[k]
return value, ok
}
Expand Down
4 changes: 1 addition & 3 deletions api/correlation/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"fmt"
"testing"

"go.opentelemetry.io/otel/api/kv/value"

"go.opentelemetry.io/otel/api/kv"
)

Expand Down Expand Up @@ -281,7 +279,7 @@ func getTestCases() []testCase {
func makeTestMap(ints []int) Map {
r := make(rawMap, len(ints))
for _, v := range ints {
r[kv.Key(fmt.Sprintf("key%d", v))] = value.Int(v)
r[kv.Key(fmt.Sprintf("key%d", v))] = kv.IntValue(v)
}
return newMap(r)
}
8 changes: 3 additions & 5 deletions api/global/internal/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"io/ioutil"
"testing"

"go.opentelemetry.io/otel/api/kv/value"

"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/api/global"
Expand All @@ -39,7 +37,7 @@ type measured struct {
Name string
InstrumentationName string
InstrumentationVersion string
Labels map[kv.Key]value.Value
Labels map[kv.Key]kv.Value
Number metric.Number
}

Expand All @@ -59,8 +57,8 @@ func asStructs(batches []metrictest.Batch) []measured {
return r
}

func asMap(kvs ...kv.KeyValue) map[kv.Key]value.Value {
m := map[kv.Key]value.Value{}
func asMap(kvs ...kv.KeyValue) map[kv.Key]kv.Value {
m := map[kv.Key]kv.Value{}
for _, kv := range kvs {
m[kv.Key] = kv.Value
}
Expand Down
26 changes: 11 additions & 15 deletions api/kv/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

package kv

import (
"go.opentelemetry.io/otel/api/kv/value"
)

// Key represents the key part in key-value pairs. It's a string. The
// allowed character set in the key depends on the use of the key.
type Key string
Expand All @@ -31,7 +27,7 @@ type Key string
func (k Key) Bool(v bool) KeyValue {
return KeyValue{
Key: k,
Value: value.Bool(v),
Value: BoolValue(v),
}
}

Expand All @@ -44,7 +40,7 @@ func (k Key) Bool(v bool) KeyValue {
func (k Key) Int64(v int64) KeyValue {
return KeyValue{
Key: k,
Value: value.Int64(v),
Value: Int64Value(v),
}
}

Expand All @@ -57,7 +53,7 @@ func (k Key) Int64(v int64) KeyValue {
func (k Key) Uint64(v uint64) KeyValue {
return KeyValue{
Key: k,
Value: value.Uint64(v),
Value: Uint64Value(v),
}
}

Expand All @@ -70,7 +66,7 @@ func (k Key) Uint64(v uint64) KeyValue {
func (k Key) Float64(v float64) KeyValue {
return KeyValue{
Key: k,
Value: value.Float64(v),
Value: Float64Value(v),
}
}

Expand All @@ -83,7 +79,7 @@ func (k Key) Float64(v float64) KeyValue {
func (k Key) Int32(v int32) KeyValue {
return KeyValue{
Key: k,
Value: value.Int32(v),
Value: Int32Value(v),
}
}

Expand All @@ -96,7 +92,7 @@ func (k Key) Int32(v int32) KeyValue {
func (k Key) Uint32(v uint32) KeyValue {
return KeyValue{
Key: k,
Value: value.Uint32(v),
Value: Uint32Value(v),
}
}

Expand All @@ -109,7 +105,7 @@ func (k Key) Uint32(v uint32) KeyValue {
func (k Key) Float32(v float32) KeyValue {
return KeyValue{
Key: k,
Value: value.Float32(v),
Value: Float32Value(v),
}
}

Expand All @@ -122,7 +118,7 @@ func (k Key) Float32(v float32) KeyValue {
func (k Key) String(v string) KeyValue {
return KeyValue{
Key: k,
Value: value.String(v),
Value: StringValue(v),
}
}

Expand All @@ -136,7 +132,7 @@ func (k Key) String(v string) KeyValue {
func (k Key) Int(v int) KeyValue {
return KeyValue{
Key: k,
Value: value.Int(v),
Value: IntValue(v),
}
}

Expand All @@ -150,7 +146,7 @@ func (k Key) Int(v int) KeyValue {
func (k Key) Uint(v uint) KeyValue {
return KeyValue{
Key: k,
Value: value.Uint(v),
Value: UintValue(v),
}
}

Expand All @@ -168,6 +164,6 @@ func (k Key) Defined() bool {
func (k Key) Array(v interface{}) KeyValue {
return KeyValue{
Key: k,
Value: value.Array(v),
Value: ArrayValue(v),
}
}
30 changes: 14 additions & 16 deletions api/kv/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"go.opentelemetry.io/otel/api/kv"

"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/api/kv/value"
)

func TestDefined(t *testing.T) {
Expand Down Expand Up @@ -68,47 +66,47 @@ func TestJSONValue(t *testing.T) {
func TestEmit(t *testing.T) {
for _, testcase := range []struct {
name string
v value.Value
v kv.Value
want string
}{
{
name: `test Key.Emit() can emit a string representing self.BOOL`,
v: value.Bool(true),
v: kv.BoolValue(true),
want: "true",
},
{
name: `test Key.Emit() can emit a string representing self.INT32`,
v: value.Int32(42),
v: kv.Int32Value(42),
want: "42",
},
{
name: `test Key.Emit() can emit a string representing self.INT64`,
v: value.Int64(42),
v: kv.Int64Value(42),
want: "42",
},
{
name: `test Key.Emit() can emit a string representing self.UINT32`,
v: value.Uint32(42),
v: kv.Uint32Value(42),
want: "42",
},
{
name: `test Key.Emit() can emit a string representing self.UINT64`,
v: value.Uint64(42),
v: kv.Uint64Value(42),
want: "42",
},
{
name: `test Key.Emit() can emit a string representing self.FLOAT32`,
v: value.Float32(42.1),
v: kv.Float32Value(42.1),
want: "42.1",
},
{
name: `test Key.Emit() can emit a string representing self.FLOAT64`,
v: value.Float64(42.1),
v: kv.Float64Value(42.1),
want: "42.1",
},
{
name: `test Key.Emit() can emit a string representing self.STRING`,
v: value.String("foo"),
v: kv.StringValue("foo"),
want: "foo",
},
} {
Expand All @@ -125,39 +123,39 @@ func TestEmit(t *testing.T) {
func BenchmarkEmitBool(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
n := value.Bool(i%2 == 0)
n := kv.BoolValue(i%2 == 0)
_ = n.Emit()
}
}

func BenchmarkEmitInt64(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
n := value.Int64(int64(i))
n := kv.Int64Value(int64(i))
_ = n.Emit()
}
}

func BenchmarkEmitUInt64(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
n := value.Uint64(uint64(i))
n := kv.Uint64Value(uint64(i))
_ = n.Emit()
}
}

func BenchmarkEmitFloat64(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
n := value.Float64(float64(i))
n := kv.Float64Value(float64(i))
_ = n.Emit()
}
}

func BenchmarkEmitFloat32(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
n := value.Float32(float32(i))
n := kv.Float32Value(float32(i))
_ = n.Emit()
}
}
4 changes: 1 addition & 3 deletions api/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import (
"encoding/json"
"fmt"
"reflect"

"go.opentelemetry.io/otel/api/kv/value"
)

// KeyValue holds a key and value pair.
type KeyValue struct {
Key Key
Value value.Value
Value Value
}

// Bool creates a new key-value pair with a passed name and a bool
Expand Down
Loading