Documentation ¶
Overview ¶
Package model is a generated protocol buffer package.
It is generated from these files:
span.proto trace.proto trace_payload.proto
It has these top-level messages:
Span APITrace TracePayload
Index ¶
- Constants
- Variables
- func AgentPayloadAPIPath() string
- func EncodeAgentPayload(p *AgentPayload) ([]byte, error)
- func EncodeServicesPayload(sm ServicesMetadata) ([]byte, error)
- func EncodeStatsPayload(payload *StatsPayload) ([]byte, error)
- func FilterTags(tags, groups []string) []string
- func GrainKey(name, measure, aggr string) string
- func NormalizeTag(tag string) string
- func Now() int64
- func RandomID() uint64
- func SetAgentPayloadHeaders(h http.Header, extras map[string]string)
- func SetServicesPayloadHeaders(h http.Header)
- func SetSublayersOnSpan(span *Span, values []SublayerValue)
- func SplitTag(tag string) (group, value string)
- func TagGroup(tag string) string
- type APITrace
- func (*APITrace) Descriptor() ([]byte, []int)
- func (m *APITrace) GetSpans() []*Span
- func (m *APITrace) Marshal() (data []byte, err error)
- func (m *APITrace) MarshalTo(data []byte) (int, error)
- func (*APITrace) ProtoMessage()
- func (m *APITrace) Reset()
- func (m *APITrace) Size() (n int)
- func (m *APITrace) String() string
- func (m *APITrace) Unmarshal(data []byte) error
- type AgentPayload
- type AgentPayloadVersion
- type Count
- type Distribution
- type LimitedReader
- type ServicesMetadata
- type Span
- func (z *Span) DecodeMsg(dc *msgp.Reader) (err error)
- func (*Span) Descriptor() ([]byte, []int)
- func (z *Span) EncodeMsg(en *msgp.Writer) (err error)
- func (s *Span) End() int64
- func (s *Span) ForceMetrics() bool
- func (m *Span) GetMeta() map[string]string
- func (m *Span) GetMetrics() map[string]float64
- func (s *Span) IsFlushMarker() bool
- func (m *Span) Marshal() (data []byte, err error)
- func (m *Span) MarshalTo(data []byte) (int, error)
- func (z *Span) Msgsize() (s int)
- func (s *Span) Normalize() error
- func (*Span) ProtoMessage()
- func (m *Span) Reset()
- func (m *Span) Size() (n int)
- func (m *Span) String() string
- func (s *Span) TopLevel() bool
- func (s *Span) Truncate()
- func (m *Span) Unmarshal(data []byte) error
- func (s *Span) Weight() float64
- type StatsBucket
- type StatsPayload
- type StatsRawBucket
- type SublayerValue
- type Subtrace
- type Tag
- type TagSet
- func (t TagSet) Get(name string) Tag
- func (t TagSet) HasExactly(groups []string) bool
- func (t TagSet) Key() string
- func (t TagSet) Len() int
- func (t TagSet) Less(i, j int) bool
- func (t TagSet) Match(groups []string) TagSet
- func (t TagSet) MatchFilters(filters []string) TagSet
- func (t TagSet) Swap(i, j int)
- func (t TagSet) TagKey(m string) string
- func (t TagSet) Unset(name string) TagSet
- type Trace
- func (t Trace) APITrace() *APITrace
- func (t Trace) ChildrenMap() map[uint64][]*Span
- func (t Trace) ComputeTopLevel()
- func (z *Trace) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Trace) EncodeMsg(en *msgp.Writer) (err error)
- func (t Trace) ExtractTopLevelSubtraces(root *Span) []Subtrace
- func (t Trace) GetEnv() string
- func (t Trace) GetRoot() *Span
- func (z Trace) Msgsize() (s int)
- type TracePayload
- func (*TracePayload) Descriptor() ([]byte, []int)
- func (m *TracePayload) GetTraces() []*APITrace
- func (m *TracePayload) GetTransactions() []*Span
- func (m *TracePayload) Marshal() (data []byte, err error)
- func (m *TracePayload) MarshalTo(data []byte) (int, error)
- func (*TracePayload) ProtoMessage()
- func (m *TracePayload) Reset()
- func (m *TracePayload) Size() (n int)
- func (m *TracePayload) String() string
- func (m *TracePayload) Unmarshal(data []byte) error
- type Traces
- type WeightedSpan
- type WeightedTrace
Constants ¶
const ( // MaxServiceLen the maximum length a service can have MaxServiceLen = 100 // MaxNameLen the maximum length a name can have MaxNameLen = 100 // MaxTypeLen the maximum length a span type can have MaxTypeLen = 100 // MaxEndDateOffset the maximum amount of time in the future we // tolerate for span end dates MaxEndDateOffset = 10 * time.Minute )
const ( HITS string = "hits" ERRORS = "errors" DURATION = "duration" )
Hardcoded measures names for ease of reference
const ( // MaxResourceLen the maximum length the resource can have MaxResourceLen = 5000 // MaxMetaKeyLen the maximum length of metadata key MaxMetaKeyLen = 100 // MaxMetaValLen the maximum length of metadata value MaxMetaValLen = 5000 // MaxMetricsKeyLen the maximum length of a metric name key MaxMetricsKeyLen = MaxMetaKeyLen )
const AppType = "app_type"
AppType is one of the pieces of information embedded in ServiceMetadata
const ServiceApp = "app"
ServiceApp represents the app to which certain integration belongs to
const (
// SpanSampleRateMetricKey is the metric key holding the sample rate
SpanSampleRateMetricKey = "_sample_rate"
)
const ( // TraceMetricsKey is a tag key which, if set to true, // ensures all statistics are computed for this span. // [FIXME] *not implemented yet* TraceMetricsKey = "datadog.trace_metrics" )
Variables ¶
var ( ErrInvalidLengthSpan = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowSpan = fmt.Errorf("proto: integer overflow") )
var ( // DefaultCounts is an array of the measures we represent as Count by default DefaultCounts = [...]string{HITS, ERRORS, DURATION} // DefaultDistributions is an array of the measures we represent as Distribution by default // Not really used right now as we don't have a way to easily add new distros DefaultDistributions = [...]string{DURATION} )
var ( ErrInvalidLengthTrace = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowTrace = fmt.Errorf("proto: integer overflow") )
var ( ErrInvalidLengthTracePayload = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowTracePayload = fmt.Errorf("proto: integer overflow") )
var ErrLimitedReaderLimitReached = errors.New("read limit reached")
ErrLimitedReaderLimitReached indicates that the read limit has been reached.
var ( // GlobalAgentPayloadVersion is a default that will be used // in all the AgentPayload method. Override for special cases. GlobalAgentPayloadVersion = AgentPayloadV01 )
Functions ¶
func AgentPayloadAPIPath ¶
func AgentPayloadAPIPath() string
AgentPayloadAPIPath returns the path (after the first slash) to which the payload should be sent to be understood by the API given the configured payload version.
func EncodeAgentPayload ¶
func EncodeAgentPayload(p *AgentPayload) ([]byte, error)
EncodeAgentPayload will return a slice of bytes representing the payload (according to GlobalAgentPayloadVersion)
func EncodeServicesPayload ¶
func EncodeServicesPayload(sm ServicesMetadata) ([]byte, error)
EncodeServicesPayload will return a slice of bytes representing the services metadata, this uses the same versioned endpoint that AgentPayload uses for serialization. Hence watch for GlobalAgentPayloadVersion's value.
func EncodeStatsPayload ¶
func EncodeStatsPayload(payload *StatsPayload) ([]byte, error)
EncodeStatsPayload encodes the stats payload as json/gzip.
func FilterTags ¶
FilterTags will return the tags that have the given group.
func GrainKey ¶
GrainKey generates the key used to aggregate counts and distributions which is of the form: name|measure|aggr for example: serve|duration|service:webserver
func NormalizeTag ¶
NormalizeTag applies some normalization to ensure the tags match the backend requirements taken from dd-go.model.NormalizeTag
func SetAgentPayloadHeaders ¶
SetAgentPayloadHeaders takes a Header struct and adds the appropriate header keys for the API to be able to decode the data.
func SetServicesPayloadHeaders ¶
SetServicesPayloadHeaders takes a Header struct and adds the appropriate header keys for the API to be able to decode the services metadata.
func SetSublayersOnSpan ¶
func SetSublayersOnSpan(span *Span, values []SublayerValue)
SetSublayersOnSpan takes some sublayers and pins them on the given span.Metrics
Types ¶
type APITrace ¶
type APITrace struct { TraceID uint64 `protobuf:"varint,1,opt,name=traceID,proto3" json:"traceID,omitempty"` Spans []*Span `protobuf:"bytes,2,rep,name=spans" json:"spans,omitempty"` StartTime int64 `protobuf:"varint,6,opt,name=startTime,proto3" json:"startTime,omitempty"` EndTime int64 `protobuf:"varint,7,opt,name=endTime,proto3" json:"endTime,omitempty"` }
func (*APITrace) Descriptor ¶
func (*APITrace) ProtoMessage ¶
func (*APITrace) ProtoMessage()
type AgentPayload ¶
type AgentPayload struct { HostName string `json:"hostname"` // the host name that will be resolved by the API Env string `json:"env"` // the default environment this agent uses Traces []Trace `json:"traces"` // the traces we sampled Stats []StatsBucket `json:"stats"` // the statistics we pre-computed // contains filtered or unexported fields }
AgentPayload is the main payload to carry data that has been pre-processed to the Datadog mothership. This is a legacy payload format, used in API v0.1.
func (*AgentPayload) Extras ¶
func (p *AgentPayload) Extras() map[string]string
Extras returns this payloads extra metadata fields
func (*AgentPayload) IsEmpty ¶
func (p *AgentPayload) IsEmpty() bool
IsEmpty tells if a payload contains data. If not, it's useless to flush it.
func (*AgentPayload) SetExtra ¶
func (p *AgentPayload) SetExtra(key, val string)
SetExtra sets the given metadata field on a payload
type AgentPayloadVersion ¶
type AgentPayloadVersion string
AgentPayloadVersion is the version the agent agrees to with the API so that they can encode/decode the data accordingly
const ( // AgentPayloadV01 is a simple json'd/gzip'd dump of the payload AgentPayloadV01 AgentPayloadVersion = "v0.1" )
type Count ¶
type Count struct { Key string `json:"key"` Name string `json:"name"` // the name of the trace/spans we count (was a member of TagSet) Measure string `json:"measure"` // represents the entity we count, e.g. "hits", "errors", "time" (was Name) TagSet TagSet `json:"tagset"` // set of tags for which we account this Distribution TopLevel float64 `json:"top_level"` // number of top-level spans contributing to this count Value float64 `json:"value"` // accumulated values }
Count represents one specific "metric" we track for a given tagset
type Distribution ¶
type Distribution struct { Key string `json:"key"` Name string `json:"name"` // the name of the trace/spans we count (was a member of TagSet) Measure string `json:"measure"` // represents the entity we count, e.g. "hits", "errors", "time" TagSet TagSet `json:"tagset"` // set of tags for which we account this Distribution TopLevel float64 `json:"top_level"` // number of top-level spans contributing to this count Summary *quantile.SliceSummary `json:"summary"` // actual representation of data }
Distribution represents a true image of the spectrum of values, allowing arbitrary quantile queries
func NewDistribution ¶
func NewDistribution(m, ckey, name string, tgs TagSet) Distribution
NewDistribution returns a new Distribution for a metric and a given tag set
func (Distribution) Add ¶
func (d Distribution) Add(v float64, sampleID uint64)
Add inserts the proper values in a given distribution from a span
func (Distribution) Copy ¶
func (d Distribution) Copy() Distribution
Copy returns a distro with the same data but a different underlying summary
func (Distribution) Merge ¶
func (d Distribution) Merge(d2 Distribution)
Merge is used when 2 Distributions represent the same thing and it merges the 2 underlying summaries
func (Distribution) Weigh ¶
func (d Distribution) Weigh(weight float64) Distribution
Weigh applies a weight factor to a distribution and return the result as a new distribution.
type LimitedReader ¶
type LimitedReader struct { Count int64 // contains filtered or unexported fields }
LimitedReader reads from a reader up to a specific limit. When this limit has been reached, any subsequent read will return ErrLimitedReaderLimitReached. The underlying reader has to implement io.ReadCloser so that it can be used with http request bodies.
func NewLimitedReader ¶
func NewLimitedReader(r io.ReadCloser, limit int64) *LimitedReader
NewLimitedReader creates a new LimitedReader.
func (*LimitedReader) Close ¶
func (r *LimitedReader) Close() error
Close closes the underlying reader.
type ServicesMetadata ¶
ServicesMetadata is a standard key/val meta map attached to each named service
func (*ServicesMetadata) DecodeMsg ¶
func (z *ServicesMetadata) DecodeMsg(dc *msgp.Reader) (err error)
DecodeMsg implements msgp.Decodable
func (ServicesMetadata) EncodeMsg ¶
func (z ServicesMetadata) EncodeMsg(en *msgp.Writer) (err error)
EncodeMsg implements msgp.Encodable
func (ServicesMetadata) Merge ¶
func (s1 ServicesMetadata) Merge(s2 ServicesMetadata)
Merge adds all entries from s2 to s1
func (ServicesMetadata) Msgsize ¶
func (z ServicesMetadata) Msgsize() (s int)
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
type Span ¶
type Span struct { Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service" msg:"service"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name" msg:"name"` Resource string `protobuf:"bytes,3,opt,name=resource,proto3" json:"resource" msg:"resource"` TraceID uint64 `protobuf:"varint,4,opt,name=traceID,proto3" json:"trace_id" msg:"trace_id"` SpanID uint64 `protobuf:"varint,5,opt,name=spanID,proto3" json:"span_id" msg:"span_id"` ParentID uint64 `protobuf:"varint,6,opt,name=parentID,proto3" json:"parent_id" msg:"parent_id"` Start int64 `protobuf:"varint,7,opt,name=start,proto3" json:"start" msg:"start"` Duration int64 `protobuf:"varint,8,opt,name=duration,proto3" json:"duration" msg:"duration"` Error int32 `protobuf:"varint,9,opt,name=error,proto3" json:"error" msg:"error"` Meta map[string]string `` /* 144-byte string literal not displayed */ Metrics map[string]float64 `` /* 155-byte string literal not displayed */ Type string `protobuf:"bytes,12,opt,name=type,proto3" json:"type" msg:"type"` }
func (*Span) Descriptor ¶
func (*Span) ForceMetrics ¶
ForceMetrics returns true if statistics computation should be forced for this span.
func (*Span) GetMetrics ¶
func (*Span) IsFlushMarker ¶
IsFlushMarker tells if this is a marker span, which signals the system to flush
func (*Span) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Span) Normalize ¶
Normalize makes sure a Span is properly initialized and encloses the minimum required info
func (*Span) ProtoMessage ¶
func (*Span) ProtoMessage()
type StatsBucket ¶
type StatsBucket struct { Start int64 // Timestamp of start in our format Duration int64 // Duration of a bucket in nanoseconds // Stats indexed by keys Counts map[string]Count // All the counts Distributions map[string]Distribution // All the distributions (e.g.: for quantile queries) ErrDistributions map[string]Distribution // All the error distributions (e.g.: for apdex, as they account for frustrated) }
StatsBucket is a time bucket to track statistic around multiple Counts
func NewStatsBucket ¶
func NewStatsBucket(ts, d int64) StatsBucket
NewStatsBucket opens a new bucket for time ts and initializes it properly
func (StatsBucket) IsEmpty ¶
func (sb StatsBucket) IsEmpty() bool
IsEmpty just says if this stats bucket has no information (in which case it's useless)
type StatsPayload ¶
type StatsPayload struct { HostName string `json:"hostname"` Env string `json:"env"` Stats []StatsBucket `json:"stats"` }
StatsPayload represents the payload to be flushed to the stats endpoint
type StatsRawBucket ¶
type StatsRawBucket struct {
// contains filtered or unexported fields
}
StatsRawBucket is used to compute span data and aggregate it within a time-framed bucket. This should not be used outside the agent, use StatsBucket for this.
func NewStatsRawBucket ¶
func NewStatsRawBucket(ts, d int64) *StatsRawBucket
NewStatsRawBucket opens a new calculation bucket for time ts and initializes it properly
func (*StatsRawBucket) Export ¶
func (sb *StatsRawBucket) Export() StatsBucket
Export transforms a StatsRawBucket into a StatsBucket, typically used before communicating data to the API, as StatsRawBucket is the internal type while StatsBucket is the public, shared one.
func (*StatsRawBucket) HandleSpan ¶
func (sb *StatsRawBucket) HandleSpan(s *WeightedSpan, env string, aggregators []string, sublayers *[]SublayerValue)
HandleSpan adds the span to this bucket stats, aggregated with the finest grain matching given aggregators
type SublayerValue ¶
SublayerValue is just a span-metric placeholder for a given sublayer val
func ComputeSublayers ¶
func ComputeSublayers(trace Trace) []SublayerValue
ComputeSublayers extracts sublayer values by type and service for a trace
Description of the algorithm, with the following trace as an example:
0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 |===|===|===|===|===|===|===|===|===|===|===|===|===|===|===| <-1------------------------------------------------->
<-2-----------------> <-3---------> <-4---------> <-5-------------------> <--6--------------------> <-7------------->
1: service=web-server, type=web, parent=nil 2: service=pg, type=db, parent=1 3: service=render, type=web, parent=1 4: service=pg-read, type=db, parent=2 5: service=redis, type=cache, parent=1 6: service=rpc1, type=rpc, parent=1 7: service=alert, type=rpc, parent=6
Step 1: Find all time intervals to consider (set of start/end time
of spans): [0, 10, 15, 20, 50, 60, 70, 80, 110, 120, 130, 150]
Step 2: Map each time intervals to a set of "active" spans. A span
is considered active for a given time interval if it has no direct child span at that time interval. This is done by iterating over the spans, iterating over each time intervals, and checking if the span has a child running during that time interval. If not, it is considered active: { 0: [ 1 ], 10: [ 2 ], 15: [ 2, 5 ], 20: [ 4, 5 ], ... 110: [ 7 ], 120: [ 1, 7 ], 130: [ 7 ], 150: [], }
Step 4: Build a service and type duration mapping by:
iterating over each time intervals
computing the time interval duration portion (time interval duration / number of active spans)
iterate over each active span of that time interval
add to the active span's type and service duration the duration portion
{ web-server: 10, render: 15, pg: 12.5, pg-read: 15, redis: 27.5, rpc1: 30, alert: 40, } { web: 70, cache: 55, db: 55, rpc: 55, }
func (SublayerValue) GoString ¶
func (v SublayerValue) GoString() string
GoString returns a description of a sublayer value.
func (SublayerValue) String ¶
func (v SublayerValue) String() string
String returns a description of a sublayer value.
type Subtrace ¶
Subtrace represents the combination of a root span and the trace consisting of all its descendant spans
type Tag ¶
Tag represents a key / value dimension on traces and stats.
func NewTagFromString ¶
NewTagFromString returns a new Tag from a raw string
type TagSet ¶
type TagSet []Tag
TagSet is an ordered and unique combination of tags
func NewTagSetFromString ¶
NewTagSetFromString returns a new TagSet from a raw string
func (TagSet) HasExactly ¶
HasExactly returns true if we have tags only for the given groups.
func (TagSet) MatchFilters ¶
MatchFilters returns a tag set of the tags that match certain filters. A filter is defined as : "KEY:VAL" where:
- KEY is a non-empty string
- VALUE is a string (can be empty)
A tag {Name:k, Value:v} from the input tag set will match if:
- KEY==k and VALUE is non-empty and v==VALUE
- KEY==k and VALUE is empty (don't care about v)
type Trace ¶
type Trace []*Span
Trace is a collection of spans with the same trace ID
func NewTraceFlushMarker ¶
func NewTraceFlushMarker() Trace
NewTraceFlushMarker returns a trace with a single span as flush marker
func NormalizeTrace ¶
NormalizeTrace takes a trace and * rejects the trace if there is a trace ID discrepancy between 2 spans * rejects the trace if two spans have the same span_id * rejects empty traces * rejects traces where at least one span cannot be normalized * return the normalized trace and an error:
- nil if the trace can be accepted
- an error string if the trace needs to be dropped
func (Trace) APITrace ¶
APITrace returns an APITrace from the trace, as required by the Datadog API.
func (Trace) ChildrenMap ¶
ChildrenMap returns a map containing for each span id the list of its direct children.
func (Trace) ComputeTopLevel ¶
func (t Trace) ComputeTopLevel()
ComputeTopLevel updates all the spans top-level attribute.
A span is considered top-level if:
- it's a root span
- its parent is unknown (other part of the code, distributed trace)
- its parent belongs to another service (in that case it's a "local root" being the highest ancestor of other spans belonging to this service and attached to it).
func (Trace) ExtractTopLevelSubtraces ¶
ExtractTopLevelSubtraces extracts all subtraces rooted in a toplevel span, ComputeTopLevel should be called before.
type TracePayload ¶
type TracePayload struct { HostName string `protobuf:"bytes,1,opt,name=hostName,proto3" json:"hostName,omitempty"` Env string `protobuf:"bytes,2,opt,name=env,proto3" json:"env,omitempty"` Traces []*APITrace `protobuf:"bytes,3,rep,name=traces" json:"traces,omitempty"` Transactions []*Span `protobuf:"bytes,4,rep,name=transactions" json:"transactions,omitempty"` }
func (*TracePayload) Descriptor ¶
func (*TracePayload) Descriptor() ([]byte, []int)
func (*TracePayload) GetTraces ¶
func (m *TracePayload) GetTraces() []*APITrace
func (*TracePayload) GetTransactions ¶
func (m *TracePayload) GetTransactions() []*Span
func (*TracePayload) Marshal ¶
func (m *TracePayload) Marshal() (data []byte, err error)
func (*TracePayload) ProtoMessage ¶
func (*TracePayload) ProtoMessage()
func (*TracePayload) Reset ¶
func (m *TracePayload) Reset()
func (*TracePayload) Size ¶
func (m *TracePayload) Size() (n int)
func (*TracePayload) String ¶
func (m *TracePayload) String() string
func (*TracePayload) Unmarshal ¶
func (m *TracePayload) Unmarshal(data []byte) error
type Traces ¶
type Traces []Trace
Traces is a list of traces. This model matters as this is what we unpack from msgp.
func TracesFromSpans ¶
TracesFromSpans transforms a slice of spans into a slice of traces grouping them by trace IDs FIXME[1.x] this can be removed as we get pre-assembled traces from clients
type WeightedSpan ¶
type WeightedSpan struct { Weight float64 // Span weight. Similar to the trace root.Weight(). TopLevel bool // Is this span a service top-level or not. Similar to span.TopLevel(). *Span }
WeightedSpan extends Span to contain weights required by the Concentrator.
type WeightedTrace ¶
type WeightedTrace []*WeightedSpan
WeightedTrace is a slice of WeightedSpan pointers.
func NewWeightedTrace ¶
func NewWeightedTrace(trace Trace, root *Span) WeightedTrace
NewWeightedTrace returns a weighted trace, with coefficient required by the concentrator.