swarm: integrate OpenTracing; propagate ctx to internal APIs (#17169)
* swarm: propagate ctx, enable opentracing * swarm/tracing: log error when tracing is misconfigured
This commit is contained in:
committed by
Balint Gabor
parent
f7d3678c28
commit
7c9314f231
cmd/swarm
p2p
swarm
api
fuse
network
pss
spancontext
storage
chunker.gochunker_test.gochunkstore.gocommon.gocommon_test.godbapi.gohasherstore.gohasherstore_test.goldbstore.goldbstore_test.golocalstore.gomemstore.gomemstore_test.go
swarm.gomru
netstore.gonetstore_test.gopyramid.gotypes.gotracing
vendor
github.com
codahale
opentracing
opentracing-go
uber
jaeger-client-go
CHANGELOG.mdCONTRIBUTING.mdDCOGopkg.lockGopkg.tomlLICENSEMakefileREADME.mdRELEASE.mdbaggage_setter.gointerop.gojaeger_tag.gojaeger_thrift_span.go
config
constants.gocontext.gocontrib_observer.godoc.goglide.lockglide.yamlheader.gointernal
baggage
spanlog
throttler
log
logger.gometrics.goobserver.goprocess.gopropagation.goreference.goreporter.goreporter_options.gorpcmetrics
sampler.gosampler_options.gospan.gothrift-gen
agent
baggage
jaeger
sampling
zipkincore
thrift
README.mdapplication_exception.gobinary_protocol.gocompact_protocol.goexception.gomemory_buffer.gomessagetype.gonumeric.goprocessor.goprotocol.goprotocol_exception.goprotocol_factory.gorich_transport.goserializer.gosimple_json_protocol.gotransport.gotransport_exception.gotransport_factory.gotype.go
tracer.gotracer_options.gotransport.gotransport_udp.goutils
zipkin.gozipkin_thrift_span.gojaeger-lib
87
vendor/github.com/uber/jaeger-client-go/utils/utils.go
generated
vendored
Normal file
87
vendor/github.com/uber/jaeger-client-go/utils/utils.go
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2017 Uber Technologies, Inc.
|
||||
//
|
||||
// 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 utils
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrEmptyIP an error for empty ip strings
|
||||
ErrEmptyIP = errors.New("empty string given for ip")
|
||||
|
||||
// ErrNotHostColonPort an error for invalid host port string
|
||||
ErrNotHostColonPort = errors.New("expecting host:port")
|
||||
|
||||
// ErrNotFourOctets an error for the wrong number of octets after splitting a string
|
||||
ErrNotFourOctets = errors.New("Wrong number of octets")
|
||||
)
|
||||
|
||||
// ParseIPToUint32 converts a string ip (e.g. "x.y.z.w") to an uint32
|
||||
func ParseIPToUint32(ip string) (uint32, error) {
|
||||
if ip == "" {
|
||||
return 0, ErrEmptyIP
|
||||
}
|
||||
|
||||
if ip == "localhost" {
|
||||
return 127<<24 | 1, nil
|
||||
}
|
||||
|
||||
octets := strings.Split(ip, ".")
|
||||
if len(octets) != 4 {
|
||||
return 0, ErrNotFourOctets
|
||||
}
|
||||
|
||||
var intIP uint32
|
||||
for i := 0; i < 4; i++ {
|
||||
octet, err := strconv.Atoi(octets[i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
intIP = (intIP << 8) | uint32(octet)
|
||||
}
|
||||
|
||||
return intIP, nil
|
||||
}
|
||||
|
||||
// ParsePort converts port number from string to uin16
|
||||
func ParsePort(portString string) (uint16, error) {
|
||||
port, err := strconv.ParseUint(portString, 10, 16)
|
||||
return uint16(port), err
|
||||
}
|
||||
|
||||
// PackIPAsUint32 packs an IPv4 as uint32
|
||||
func PackIPAsUint32(ip net.IP) uint32 {
|
||||
if ipv4 := ip.To4(); ipv4 != nil {
|
||||
return binary.BigEndian.Uint32(ipv4)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// TimeToMicrosecondsSinceEpochInt64 converts Go time.Time to a long
|
||||
// representing time since epoch in microseconds, which is used expected
|
||||
// in the Jaeger spans encoded as Thrift.
|
||||
func TimeToMicrosecondsSinceEpochInt64(t time.Time) int64 {
|
||||
// ^^^ Passing time.Time by value is faster than passing a pointer!
|
||||
// BenchmarkTimeByValue-8 2000000000 1.37 ns/op
|
||||
// BenchmarkTimeByPtr-8 2000000000 1.98 ns/op
|
||||
|
||||
return t.UnixNano() / 1000
|
||||
}
|
Reference in New Issue
Block a user