houyi

package module
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: Apache-2.0 Imports: 24 Imported by: 1

README

Houyi Client API for Golang

Instrumentation library that implements an OpenTracing Go Tracer for Houyi.

Four types of sampler have been support:

  • Const
  • Probability
  • Rate-limit
  • Adaptive
  • Dynamic

All development works of this project was based on Jeager.

Documentation

Index

Constants

View Source
const (
	DefaultPullStrategiesInterval = time.Second * 10
	DefaultReporterType           = "remote"
	DefaultAgentAddr              = "localhost"
	DefaultAgentPort              = ports.AgentGrpcListenPort
	DefaultBufferRefreshInterval  = time.Second * 1
	DefaultQueueSize              = 100
	DefaultMaxBufferedSize        = 65000
)

flags.go

View Source
const (
	ReporterType_Null    = "null"
	ReporterType_Logging = "logging"
	ReporterType_Remote  = "remote"
)

reporter.go

View Source
const (
	SamplerTypeKey          = "sampler.type"
	SamplerParamKey         = "sampler.param"
	SamplerTypeConst        = "const"
	SamplerTypeDynamic      = "dynamic"
	SamplerTypeAdaptive     = "adaptive"
	SamplerTypeProbability  = "probability"
	SamplerTypeRateLimiting = "rate-limiting"
)

sampler.go

View Source
const (
	BaggageServiceNameKey   = "svc"
	BaggageOperationNameKey = "op"

	ParentServiceNameTagKey   = "p-svc"
	ParentOperationNameTagKey = "p-op"
)

tracer.go

View Source
const (
	TraceContextHeaderName   = "houyi-tx-ctx"
	TraceBaggageHeaderPrefix = "houyi-"
)

propagation.go

Variables

View Source
var (
	ErrEmptyContextString   = fmt.Errorf("context string can not be empty")
	ErrInvalidFormatContext = fmt.Errorf("split parts of context string should be length 5")
)

Functions

func AddFlags

func AddFlags(flags *flag.FlagSet)

func ContextFromString added in v1.0.0

func ContextFromString(context *SpanContext, value string) error

ContextFromString reconstructs the Context encoded in a string

func HexToUint64 added in v1.0.0

func HexToUint64(value string) (uint64, error)

HexToUint64 converts a hexadecimal string to it's actual value of type uint64.

Types

type AdaptiveSampler added in v1.6.0

type AdaptiveSampler struct {
	ProbabilitySampler
}

func (*AdaptiveSampler) OnCreateSpan added in v1.6.0

func (s *AdaptiveSampler) OnCreateSpan(span *Span) SamplingDecision

type BinaryPropagator added in v1.0.0

type BinaryPropagator struct {
	// contains filtered or unexported fields
}

func (*BinaryPropagator) Extract added in v1.0.0

func (p *BinaryPropagator) Extract(carrier interface{}) (SpanContext, error)

func (*BinaryPropagator) Inject added in v1.0.0

func (p *BinaryPropagator) Inject(ctx SpanContext, carrier interface{}) error

type ConstSampler added in v1.0.0

type ConstSampler struct {
	// contains filtered or unexported fields
}

ConstSampler

func (*ConstSampler) Close added in v1.0.0

func (s *ConstSampler) Close() error

func (*ConstSampler) IsSampled added in v1.0.0

func (s *ConstSampler) IsSampled(span *Span) (bool, []opentracing.Tag)

func (*ConstSampler) OnCreateSpan added in v1.0.0

func (s *ConstSampler) OnCreateSpan(_ *Span) SamplingDecision

func (*ConstSampler) String added in v1.0.0

func (s *ConstSampler) String() string

type DynamicSampler added in v1.6.0

type DynamicSampler struct {
	ProbabilitySampler
}

func (*DynamicSampler) OnCreateSpan added in v1.6.0

func (s *DynamicSampler) OnCreateSpan(span *Span) SamplingDecision

type Extractor added in v1.0.0

type Extractor interface {
	// Extract decodes a SpanContext instance from the given `carrier`,
	// or (nil, opentracing.ErrSpanContextNotFound) if no context could
	// be found in the `carrier`.
	Extract(carrier interface{}) (SpanContext, error)
}

Extractor is responsible for extracting SpanContext instances from a format-specific "carrier" object. Typically the extraction will take place on the server side of an RPC boundary, but message queues and other IPC mechanisms are also reasonable places to use an Extractor.

type Factory

type Factory interface {
	InitFromViper(*viper.Viper)
	CreateTracer(serviceName string, logger *zap.Logger) (opentracing.Tracer, io.Closer)
}

func NewTracerFactory added in v1.1.0

func NewTracerFactory() Factory

type HttpHeadersPropagator added in v1.0.0

type HttpHeadersPropagator struct{}

func (*HttpHeadersPropagator) Extract added in v1.0.0

func (p *HttpHeadersPropagator) Extract(carrier interface{}) (SpanContext, error)

func (*HttpHeadersPropagator) Inject added in v1.0.0

func (p *HttpHeadersPropagator) Inject(ctx SpanContext, carrier interface{}) error

type Injector added in v1.0.0

type Injector interface {
	// Inject takes `SpanContext` and injects it into `carrier`. The actual type
	// of `carrier` depends on the `format` passed to `Tracer.Inject()`.
	//
	// Implementations may return opentracing.ErrInvalidCarrier or any other
	// implementation-specific error if injection fails.
	Inject(ctx SpanContext, carrier interface{}) error
}

Injector is responsible for injecting SpanContext instances in a manner suitable for propagation via a format-specific "carrier" object. Typically the injection will take place across an RPC boundary, but message queues and other IPC mechanisms are also reasonable places to use an Injector.

type Operation added in v1.0.0

type Operation struct {
	Service string  `json:"service"`
	Name    string  `json:"name"`
	Qps     float64 `json:"qpsStat"`
}

func (Operation) String added in v1.0.0

func (op Operation) String() string

type Options

type Options struct {
	PullStrategiesInterval time.Duration
	ReporterType           string
	AgentAddr              string
	AgentPort              int
	BufferRefreshInterval  time.Duration
	MaxBufferedSize        int
	QueueSize              int
}

func (*Options) InitFromViper

func (opts *Options) InitFromViper(v *viper.Viper) *Options

type PerOperationSampler added in v1.0.0

type PerOperationSampler struct {
	// contains filtered or unexported fields
}

PerOperationSampler

func (*PerOperationSampler) Close added in v1.0.0

func (s *PerOperationSampler) Close() error

func (*PerOperationSampler) IsSampled added in v1.0.0

func (s *PerOperationSampler) IsSampled(span *Span) (bool, []opentracing.Tag)

func (*PerOperationSampler) OnCreateSpan added in v1.0.0

func (s *PerOperationSampler) OnCreateSpan(span *Span) SamplingDecision

func (*PerOperationSampler) String added in v1.0.0

func (s *PerOperationSampler) String() string

type ProbabilitySampler added in v1.0.0

type ProbabilitySampler struct {
	// contains filtered or unexported fields
}

ProbabilitySampler

func (*ProbabilitySampler) Close added in v1.0.0

func (s *ProbabilitySampler) Close() error

func (*ProbabilitySampler) IsSampled added in v1.0.0

func (s *ProbabilitySampler) IsSampled(span *Span) (bool, []opentracing.Tag)

func (*ProbabilitySampler) OnCreateSpan added in v1.0.0

func (s *ProbabilitySampler) OnCreateSpan(span *Span) SamplingDecision

func (*ProbabilitySampler) String added in v1.0.0

func (s *ProbabilitySampler) String() string

type Process added in v1.0.0

type Process struct {
	Service string
	UUID    string
	Tags    []opentracing.Tag
}

type RateLimitingSampler added in v1.0.0

type RateLimitingSampler struct {
	// contains filtered or unexported fields
}

RateLimitingSampler

func (*RateLimitingSampler) Close added in v1.0.0

func (s *RateLimitingSampler) Close() error

func (*RateLimitingSampler) IsSampled added in v1.0.0

func (s *RateLimitingSampler) IsSampled(span *Span) (bool, []opentracing.Tag)

func (*RateLimitingSampler) OnCreateSpan added in v1.0.0

func (s *RateLimitingSampler) OnCreateSpan(_ *Span) SamplingDecision

func (*RateLimitingSampler) String added in v1.0.0

func (s *RateLimitingSampler) String() string

type RemoteReporterParams added in v1.1.0

type RemoteReporterParams struct {
	Logger    *zap.Logger
	QueueSize int
	Interval  time.Duration
	Transport Transport
}

type RemoteSampler added in v1.0.0

type RemoteSampler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RemoteSampler implements a type of sampler that pulls sampling strategies from remote strategy manger.

func (*RemoteSampler) Close added in v1.0.0

func (s *RemoteSampler) Close() error

func (*RemoteSampler) IsSampled added in v1.0.0

func (s *RemoteSampler) IsSampled(span *Span) (bool, []opentracing.Tag)

func (*RemoteSampler) OnCreateSpan added in v1.0.0

func (s *RemoteSampler) OnCreateSpan(span *Span) SamplingDecision

func (*RemoteSampler) String added in v1.0.0

func (s *RemoteSampler) String() string

type RemoteSamplerParams added in v1.0.0

type RemoteSamplerParams struct {
	Logger        *zap.Logger
	ServiceName   string
	PullInterval  time.Duration
	AgentEndpoint routing.Endpoint
}

type Reporter added in v1.0.0

type Reporter interface {
	Report(span *Span)
	io.Closer
}

func NewLogReporter added in v1.0.0

func NewLogReporter(logger *zap.Logger) Reporter

func NewNullReporter added in v1.0.0

func NewNullReporter() Reporter

func NewRemoteReporter added in v1.0.0

func NewRemoteReporter(params *RemoteReporterParams) Reporter

type Sampler added in v1.0.0

type Sampler interface {
	OnCreateSpan(span *Span) SamplingDecision
	IsSampled(span *Span) (bool, []opentracing.Tag)

	fmt.Stringer
	io.Closer
}

func NewAdaptiveSampler added in v1.6.0

func NewAdaptiveSampler(samplingRate float64) Sampler

func NewConstSampler added in v1.0.0

func NewConstSampler(decision bool) Sampler

func NewDynamicSampler added in v1.6.0

func NewDynamicSampler(samplingRate float64) Sampler

func NewProbabilitySampler added in v1.0.0

func NewProbabilitySampler(samplingRate float64) Sampler

func NewRateLimitingSampler added in v1.0.0

func NewRateLimitingSampler(maxTracesPerSecond float64) Sampler

func NewRemoteSampler added in v1.0.0

func NewRemoteSampler(params *RemoteSamplerParams) Sampler

type SamplerUpdater added in v1.0.0

type SamplerUpdater interface {
	Update(sampler *RemoteSampler, strategies *api_v1.StrategiesResponse) error
}

func NewSamplerUpdater added in v1.6.0

func NewSamplerUpdater(logger *zap.Logger) SamplerUpdater

type SamplingDecision added in v1.0.0

type SamplingDecision struct {
	Sampled bool
	Tag     []opentracing.Tag
}

type SamplingStrategyFetcher added in v1.0.0

type SamplingStrategyFetcher interface {
	Fetch(service string, operations []Operation) (*api_v1.StrategiesResponse, error)
}

func NewSamplingStrategyFetcher added in v1.0.0

func NewSamplingStrategyFetcher(agentEp routing.Endpoint) SamplingStrategyFetcher

type Span added in v1.0.0

type Span struct {
	// contains filtered or unexported fields
}

func (*Span) BaggageItem added in v1.0.0

func (s *Span) BaggageItem(restrictedKey string) string

func (*Span) Context added in v1.0.0

func (s *Span) Context() opentracing.SpanContext

func (*Span) Duration added in v1.0.0

func (s *Span) Duration() time.Duration

func (*Span) Finish added in v1.0.0

func (s *Span) Finish()

func (*Span) FinishWithOptions added in v1.0.0

func (s *Span) FinishWithOptions(options opentracing.FinishOptions)

func (*Span) IsIngress added in v1.0.0

func (s *Span) IsIngress() bool

func (*Span) Log added in v1.0.0

func (s *Span) Log(data opentracing.LogData)

func (*Span) LogEvent added in v1.0.0

func (s *Span) LogEvent(event string)

func (*Span) LogEventWithPayload added in v1.0.0

func (s *Span) LogEventWithPayload(event string, payload interface{})

func (*Span) LogFields added in v1.0.0

func (s *Span) LogFields(fields ...log.Field)

func (*Span) LogKV added in v1.0.0

func (s *Span) LogKV(alternatingKeyValues ...interface{})

func (*Span) Logs added in v1.0.0

func (s *Span) Logs() []opentracing.LogRecord

func (*Span) OperationName added in v1.0.0

func (s *Span) OperationName() string

func (*Span) References added in v1.0.0

func (s *Span) References() []opentracing.SpanReference

func (*Span) SetBaggageItem added in v1.0.0

func (s *Span) SetBaggageItem(restrictedKey, value string) opentracing.Span

func (*Span) SetOperationName added in v1.0.0

func (s *Span) SetOperationName(operationName string) opentracing.Span

func (*Span) SetTag added in v1.0.0

func (s *Span) SetTag(key string, value interface{}) opentracing.Span

func (*Span) SpanContext added in v1.0.0

func (s *Span) SpanContext() SpanContext

func (*Span) StartTime added in v1.0.0

func (s *Span) StartTime() time.Time

func (*Span) Tags added in v1.0.0

func (s *Span) Tags() []opentracing.Tag

func (*Span) Tracer added in v1.0.0

func (s *Span) Tracer() opentracing.Tracer

type SpanContext added in v1.0.0

type SpanContext struct {
	// contains filtered or unexported fields
}

func NewSpanContext added in v1.0.0

func NewSpanContext(
	traceID TraceID,
	spanID SpanID,
	parentSpanID SpanID,
	sampled bool,
	baggage map[string]string) SpanContext

func (SpanContext) ForeachBaggageItem added in v1.0.0

func (s SpanContext) ForeachBaggageItem(handler func(k string, v string) bool)

func (SpanContext) IsSampled added in v1.0.0

func (s SpanContext) IsSampled() bool

func (SpanContext) ParentID added in v1.0.0

func (s SpanContext) ParentID() SpanID

func (SpanContext) SpanID added in v1.0.0

func (s SpanContext) SpanID() SpanID

func (SpanContext) String added in v1.0.0

func (s SpanContext) String() string

func (SpanContext) TraceID added in v1.0.0

func (s SpanContext) TraceID() TraceID

type SpanID added in v1.0.0

type SpanID uint64

func (SpanID) String added in v1.0.0

func (s SpanID) String() string

type Throughput added in v1.0.0

type Throughput struct {
	Since      time.Time
	Throughput int64
}

type TraceID added in v1.0.0

type TraceID struct {
	Low  uint64
	High uint64
}

func (TraceID) String added in v1.0.0

func (t TraceID) String() string

type Tracer added in v1.0.0

type Tracer interface {
	opentracing.Tracer
	io.Closer

	Sampler() Sampler
	Tags() []opentracing.Tag
}

func NewTracer added in v1.0.0

func NewTracer(serviceName string, params *TracerParams) Tracer

type TracerParams added in v1.0.0

type TracerParams struct {
	Logger   *zap.Logger
	Reporter Reporter
	Sampler  Sampler
}

type Transport added in v1.0.0

type Transport interface {
	// Append appends a span into transport but the span would not be reported to agent until
	// cache is full.
	Append(span *Span) (int, error)

	// Flush would immediately transport all spans in cache to agent.
	Flush() (int, error)

	io.Closer
}

Transport is to provide robust communication with agent for reporter.

func NewTransport added in v1.0.0

func NewTransport(params *TransportParams) Transport

type TransportParams added in v1.1.0

type TransportParams struct {
	Logger          *zap.Logger
	MaxBufferedSize int
	AgentEndpoint   routing.Endpoint
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL