aboutsummaryrefslogtreecommitdiff
path: root/vendor/go.opencensus.io/tag
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.opencensus.io/tag')
-rw-r--r--vendor/go.opencensus.io/tag/context.go41
-rw-r--r--vendor/go.opencensus.io/tag/doc.go26
-rw-r--r--vendor/go.opencensus.io/tag/key.go35
-rw-r--r--vendor/go.opencensus.io/tag/map.go197
-rw-r--r--vendor/go.opencensus.io/tag/map_codec.go234
-rw-r--r--vendor/go.opencensus.io/tag/profile_19.go31
-rw-r--r--vendor/go.opencensus.io/tag/profile_not19.go23
-rw-r--r--vendor/go.opencensus.io/tag/validate.go56
8 files changed, 0 insertions, 643 deletions
diff --git a/vendor/go.opencensus.io/tag/context.go b/vendor/go.opencensus.io/tag/context.go
deleted file mode 100644
index ed528bc..0000000
--- a/vendor/go.opencensus.io/tag/context.go
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2017, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-package tag
-
-import "context"
-
-// FromContext returns the tag map stored in the context.
-func FromContext(ctx context.Context) *Map {
- // The returned tag map shouldn't be mutated.
- ts := ctx.Value(mapCtxKey)
- if ts == nil {
- return nil
- }
- return ts.(*Map)
-}
-
-// NewContext creates a new context with the given tag map.
-// To propagate a tag map to downstream methods and downstream RPCs, add a tag map
-// to the current context. NewContext will return a copy of the current context,
-// and put the tag map into the returned one.
-// If there is already a tag map in the current context, it will be replaced with m.
-func NewContext(ctx context.Context, m *Map) context.Context {
- return context.WithValue(ctx, mapCtxKey, m)
-}
-
-type ctxKey struct{}
-
-var mapCtxKey = ctxKey{}
diff --git a/vendor/go.opencensus.io/tag/doc.go b/vendor/go.opencensus.io/tag/doc.go
deleted file mode 100644
index da16b74..0000000
--- a/vendor/go.opencensus.io/tag/doc.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2017, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/*
-Package tag contains OpenCensus tags.
-
-Tags are key-value pairs. Tags provide additional cardinality to
-the OpenCensus instrumentation data.
-
-Tags can be propagated on the wire and in the same
-process via context.Context. Encode and Decode should be
-used to represent tags into their binary propagation form.
-*/
-package tag // import "go.opencensus.io/tag"
diff --git a/vendor/go.opencensus.io/tag/key.go b/vendor/go.opencensus.io/tag/key.go
deleted file mode 100644
index ebbed95..0000000
--- a/vendor/go.opencensus.io/tag/key.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2017, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-package tag
-
-// Key represents a tag key.
-type Key struct {
- name string
-}
-
-// NewKey creates or retrieves a string key identified by name.
-// Calling NewKey consequently with the same name returns the same key.
-func NewKey(name string) (Key, error) {
- if !checkKeyName(name) {
- return Key{}, errInvalidKeyName
- }
- return Key{name: name}, nil
-}
-
-// Name returns the name of the key.
-func (k Key) Name() string {
- return k.name
-}
diff --git a/vendor/go.opencensus.io/tag/map.go b/vendor/go.opencensus.io/tag/map.go
deleted file mode 100644
index 5b72ba6..0000000
--- a/vendor/go.opencensus.io/tag/map.go
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright 2017, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-package tag
-
-import (
- "bytes"
- "context"
- "fmt"
- "sort"
-)
-
-// Tag is a key value pair that can be propagated on wire.
-type Tag struct {
- Key Key
- Value string
-}
-
-// Map is a map of tags. Use New to create a context containing
-// a new Map.
-type Map struct {
- m map[Key]string
-}
-
-// Value returns the value for the key if a value for the key exists.
-func (m *Map) Value(k Key) (string, bool) {
- if m == nil {
- return "", false
- }
- v, ok := m.m[k]
- return v, ok
-}
-
-func (m *Map) String() string {
- if m == nil {
- return "nil"
- }
- keys := make([]Key, 0, len(m.m))
- for k := range m.m {
- keys = append(keys, k)
- }
- sort.Slice(keys, func(i, j int) bool { return keys[i].Name() < keys[j].Name() })
-
- var buffer bytes.Buffer
- buffer.WriteString("{ ")
- for _, k := range keys {
- buffer.WriteString(fmt.Sprintf("{%v %v}", k.name, m.m[k]))
- }
- buffer.WriteString(" }")
- return buffer.String()
-}
-
-func (m *Map) insert(k Key, v string) {
- if _, ok := m.m[k]; ok {
- return
- }
- m.m[k] = v
-}
-
-func (m *Map) update(k Key, v string) {
- if _, ok := m.m[k]; ok {
- m.m[k] = v
- }
-}
-
-func (m *Map) upsert(k Key, v string) {
- m.m[k] = v
-}
-
-func (m *Map) delete(k Key) {
- delete(m.m, k)
-}
-
-func newMap() *Map {
- return &Map{m: make(map[Key]string)}
-}
-
-// Mutator modifies a tag map.
-type Mutator interface {
- Mutate(t *Map) (*Map, error)
-}
-
-// Insert returns a mutator that inserts a
-// value associated with k. If k already exists in the tag map,
-// mutator doesn't update the value.
-func Insert(k Key, v string) Mutator {
- return &mutator{
- fn: func(m *Map) (*Map, error) {
- if !checkValue(v) {
- return nil, errInvalidValue
- }
- m.insert(k, v)
- return m, nil
- },
- }
-}
-
-// Update returns a mutator that updates the
-// value of the tag associated with k with v. If k doesn't
-// exists in the tag map, the mutator doesn't insert the value.
-func Update(k Key, v string) Mutator {
- return &mutator{
- fn: func(m *Map) (*Map, error) {
- if !checkValue(v) {
- return nil, errInvalidValue
- }
- m.update(k, v)
- return m, nil
- },
- }
-}
-
-// Upsert returns a mutator that upserts the
-// value of the tag associated with k with v. It inserts the
-// value if k doesn't exist already. It mutates the value
-// if k already exists.
-func Upsert(k Key, v string) Mutator {
- return &mutator{
- fn: func(m *Map) (*Map, error) {
- if !checkValue(v) {
- return nil, errInvalidValue
- }
- m.upsert(k, v)
- return m, nil
- },
- }
-}
-
-// Delete returns a mutator that deletes
-// the value associated with k.
-func Delete(k Key) Mutator {
- return &mutator{
- fn: func(m *Map) (*Map, error) {
- m.delete(k)
- return m, nil
- },
- }
-}
-
-// New returns a new context that contains a tag map
-// originated from the incoming context and modified
-// with the provided mutators.
-func New(ctx context.Context, mutator ...Mutator) (context.Context, error) {
- m := newMap()
- orig := FromContext(ctx)
- if orig != nil {
- for k, v := range orig.m {
- if !checkKeyName(k.Name()) {
- return ctx, fmt.Errorf("key:%q: %v", k, errInvalidKeyName)
- }
- if !checkValue(v) {
- return ctx, fmt.Errorf("key:%q value:%q: %v", k.Name(), v, errInvalidValue)
- }
- m.insert(k, v)
- }
- }
- var err error
- for _, mod := range mutator {
- m, err = mod.Mutate(m)
- if err != nil {
- return ctx, err
- }
- }
- return NewContext(ctx, m), nil
-}
-
-// Do is similar to pprof.Do: a convenience for installing the tags
-// from the context as Go profiler labels. This allows you to
-// correlated runtime profiling with stats.
-//
-// It converts the key/values from the given map to Go profiler labels
-// and calls pprof.Do.
-//
-// Do is going to do nothing if your Go version is below 1.9.
-func Do(ctx context.Context, f func(ctx context.Context)) {
- do(ctx, f)
-}
-
-type mutator struct {
- fn func(t *Map) (*Map, error)
-}
-
-func (m *mutator) Mutate(t *Map) (*Map, error) {
- return m.fn(t)
-}
diff --git a/vendor/go.opencensus.io/tag/map_codec.go b/vendor/go.opencensus.io/tag/map_codec.go
deleted file mode 100644
index 3e99895..0000000
--- a/vendor/go.opencensus.io/tag/map_codec.go
+++ /dev/null
@@ -1,234 +0,0 @@
-// Copyright 2017, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-package tag
-
-import (
- "encoding/binary"
- "fmt"
-)
-
-// KeyType defines the types of keys allowed. Currently only keyTypeString is
-// supported.
-type keyType byte
-
-const (
- keyTypeString keyType = iota
- keyTypeInt64
- keyTypeTrue
- keyTypeFalse
-
- tagsVersionID = byte(0)
-)
-
-type encoderGRPC struct {
- buf []byte
- writeIdx, readIdx int
-}
-
-// writeKeyString writes the fieldID '0' followed by the key string and value
-// string.
-func (eg *encoderGRPC) writeTagString(k, v string) {
- eg.writeByte(byte(keyTypeString))
- eg.writeStringWithVarintLen(k)
- eg.writeStringWithVarintLen(v)
-}
-
-func (eg *encoderGRPC) writeTagUint64(k string, i uint64) {
- eg.writeByte(byte(keyTypeInt64))
- eg.writeStringWithVarintLen(k)
- eg.writeUint64(i)
-}
-
-func (eg *encoderGRPC) writeTagTrue(k string) {
- eg.writeByte(byte(keyTypeTrue))
- eg.writeStringWithVarintLen(k)
-}
-
-func (eg *encoderGRPC) writeTagFalse(k string) {
- eg.writeByte(byte(keyTypeFalse))
- eg.writeStringWithVarintLen(k)
-}
-
-func (eg *encoderGRPC) writeBytesWithVarintLen(bytes []byte) {
- length := len(bytes)
-
- eg.growIfRequired(binary.MaxVarintLen64 + length)
- eg.writeIdx += binary.PutUvarint(eg.buf[eg.writeIdx:], uint64(length))
- copy(eg.buf[eg.writeIdx:], bytes)
- eg.writeIdx += length
-}
-
-func (eg *encoderGRPC) writeStringWithVarintLen(s string) {
- length := len(s)
-
- eg.growIfRequired(binary.MaxVarintLen64 + length)
- eg.writeIdx += binary.PutUvarint(eg.buf[eg.writeIdx:], uint64(length))
- copy(eg.buf[eg.writeIdx:], s)
- eg.writeIdx += length
-}
-
-func (eg *encoderGRPC) writeByte(v byte) {
- eg.growIfRequired(1)
- eg.buf[eg.writeIdx] = v
- eg.writeIdx++
-}
-
-func (eg *encoderGRPC) writeUint32(i uint32) {
- eg.growIfRequired(4)
- binary.LittleEndian.PutUint32(eg.buf[eg.writeIdx:], i)
- eg.writeIdx += 4
-}
-
-func (eg *encoderGRPC) writeUint64(i uint64) {
- eg.growIfRequired(8)
- binary.LittleEndian.PutUint64(eg.buf[eg.writeIdx:], i)
- eg.writeIdx += 8
-}
-
-func (eg *encoderGRPC) readByte() byte {
- b := eg.buf[eg.readIdx]
- eg.readIdx++
- return b
-}
-
-func (eg *encoderGRPC) readUint32() uint32 {
- i := binary.LittleEndian.Uint32(eg.buf[eg.readIdx:])
- eg.readIdx += 4
- return i
-}
-
-func (eg *encoderGRPC) readUint64() uint64 {
- i := binary.LittleEndian.Uint64(eg.buf[eg.readIdx:])
- eg.readIdx += 8
- return i
-}
-
-func (eg *encoderGRPC) readBytesWithVarintLen() ([]byte, error) {
- if eg.readEnded() {
- return nil, fmt.Errorf("unexpected end while readBytesWithVarintLen '%x' starting at idx '%v'", eg.buf, eg.readIdx)
- }
- length, valueStart := binary.Uvarint(eg.buf[eg.readIdx:])
- if valueStart <= 0 {
- return nil, fmt.Errorf("unexpected end while readBytesWithVarintLen '%x' starting at idx '%v'", eg.buf, eg.readIdx)
- }
-
- valueStart += eg.readIdx
- valueEnd := valueStart + int(length)
- if valueEnd > len(eg.buf) {
- return nil, fmt.Errorf("malformed encoding: length:%v, upper:%v, maxLength:%v", length, valueEnd, len(eg.buf))
- }
-
- eg.readIdx = valueEnd
- return eg.buf[valueStart:valueEnd], nil
-}
-
-func (eg *encoderGRPC) readStringWithVarintLen() (string, error) {
- bytes, err := eg.readBytesWithVarintLen()
- if err != nil {
- return "", err
- }
- return string(bytes), nil
-}
-
-func (eg *encoderGRPC) growIfRequired(expected int) {
- if len(eg.buf)-eg.writeIdx < expected {
- tmp := make([]byte, 2*(len(eg.buf)+1)+expected)
- copy(tmp, eg.buf)
- eg.buf = tmp
- }
-}
-
-func (eg *encoderGRPC) readEnded() bool {
- return eg.readIdx >= len(eg.buf)
-}
-
-func (eg *encoderGRPC) bytes() []byte {
- return eg.buf[:eg.writeIdx]
-}
-
-// Encode encodes the tag map into a []byte. It is useful to propagate
-// the tag maps on wire in binary format.
-func Encode(m *Map) []byte {
- eg := &encoderGRPC{
- buf: make([]byte, len(m.m)),
- }
- eg.writeByte(byte(tagsVersionID))
- for k, v := range m.m {
- eg.writeByte(byte(keyTypeString))
- eg.writeStringWithVarintLen(k.name)
- eg.writeBytesWithVarintLen([]byte(v))
- }
- return eg.bytes()
-}
-
-// Decode decodes the given []byte into a tag map.
-func Decode(bytes []byte) (*Map, error) {
- ts := newMap()
- err := DecodeEach(bytes, ts.upsert)
- if err != nil {
- // no partial failures
- return nil, err
- }
- return ts, nil
-}
-
-// DecodeEach decodes the given serialized tag map, calling handler for each
-// tag key and value decoded.
-func DecodeEach(bytes []byte, fn func(key Key, val string)) error {
- eg := &encoderGRPC{
- buf: bytes,
- }
- if len(eg.buf) == 0 {
- return nil
- }
-
- version := eg.readByte()
- if version > tagsVersionID {
- return fmt.Errorf("cannot decode: unsupported version: %q; supports only up to: %q", version, tagsVersionID)
- }
-
- for !eg.readEnded() {
- typ := keyType(eg.readByte())
-
- if typ != keyTypeString {
- return fmt.Errorf("cannot decode: invalid key type: %q", typ)
- }
-
- k, err := eg.readBytesWithVarintLen()
- if err != nil {
- return err
- }
-
- v, err := eg.readBytesWithVarintLen()
- if err != nil {
- return err
- }
-
- key, err := NewKey(string(k))
- if err != nil {
- return err
- }
- val := string(v)
- if !checkValue(val) {
- return errInvalidValue
- }
- fn(key, val)
- if err != nil {
- return err
- }
- }
- return nil
-}
diff --git a/vendor/go.opencensus.io/tag/profile_19.go b/vendor/go.opencensus.io/tag/profile_19.go
deleted file mode 100644
index f81cd0b..0000000
--- a/vendor/go.opencensus.io/tag/profile_19.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2018, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// +build go1.9
-
-package tag
-
-import (
- "context"
- "runtime/pprof"
-)
-
-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.Name(), v)
- }
- pprof.Do(ctx, pprof.Labels(keyvals...), f)
-}
diff --git a/vendor/go.opencensus.io/tag/profile_not19.go b/vendor/go.opencensus.io/tag/profile_not19.go
deleted file mode 100644
index 83adbce..0000000
--- a/vendor/go.opencensus.io/tag/profile_not19.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2018, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// +build !go1.9
-
-package tag
-
-import "context"
-
-func do(ctx context.Context, f func(ctx context.Context)) {
- f(ctx)
-}
diff --git a/vendor/go.opencensus.io/tag/validate.go b/vendor/go.opencensus.io/tag/validate.go
deleted file mode 100644
index 0939fc6..0000000
--- a/vendor/go.opencensus.io/tag/validate.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2017, OpenCensus Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package tag
-
-import "errors"
-
-const (
- maxKeyLength = 255
-
- // valid are restricted to US-ASCII subset (range 0x20 (' ') to 0x7e ('~')).
- validKeyValueMin = 32
- validKeyValueMax = 126
-)
-
-var (
- errInvalidKeyName = errors.New("invalid key name: only ASCII characters accepted; max length must be 255 characters")
- errInvalidValue = errors.New("invalid value: only ASCII characters accepted; max length must be 255 characters")
-)
-
-func checkKeyName(name string) bool {
- if len(name) == 0 {
- return false
- }
- if len(name) > maxKeyLength {
- return false
- }
- return isASCII(name)
-}
-
-func isASCII(s string) bool {
- for _, c := range s {
- if (c < validKeyValueMin) || (c > validKeyValueMax) {
- return false
- }
- }
- return true
-}
-
-func checkValue(v string) bool {
- if len(v) > maxKeyLength {
- return false
- }
- return isASCII(v)
-}