id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
13,300 | stripe/veneur | samplers/samplers.go | Sample | func (c *Counter) Sample(sample float64, sampleRate float32) {
c.value += int64(sample) * int64(1/sampleRate)
} | go | func (c *Counter) Sample(sample float64, sampleRate float32) {
c.value += int64(sample) * int64(1/sampleRate)
} | [
"func",
"(",
"c",
"*",
"Counter",
")",
"Sample",
"(",
"sample",
"float64",
",",
"sampleRate",
"float32",
")",
"{",
"c",
".",
"value",
"+=",
"int64",
"(",
"sample",
")",
"*",
"int64",
"(",
"1",
"/",
"sampleRate",
")",
"\n",
"}"
] | // Sample adds a sample to the counter. | [
"Sample",
"adds",
"a",
"sample",
"to",
"the",
"counter",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L142-L144 |
13,301 | stripe/veneur | samplers/samplers.go | Flush | func (c *Counter) Flush(interval time.Duration) []InterMetric {
tags := make([]string, len(c.Tags))
copy(tags, c.Tags)
return []InterMetric{{
Name: c.Name,
Timestamp: time.Now().Unix(),
Value: float64(c.value),
Tags: tags,
Type: CounterMetric,
Sinks: routeInfo(tags),
}}
} | go | func (c *Counter) Flush(interval time.Duration) []InterMetric {
tags := make([]string, len(c.Tags))
copy(tags, c.Tags)
return []InterMetric{{
Name: c.Name,
Timestamp: time.Now().Unix(),
Value: float64(c.value),
Tags: tags,
Type: CounterMetric,
Sinks: routeInfo(tags),
}}
} | [
"func",
"(",
"c",
"*",
"Counter",
")",
"Flush",
"(",
"interval",
"time",
".",
"Duration",
")",
"[",
"]",
"InterMetric",
"{",
"tags",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"c",
".",
"Tags",
")",
")",
"\n",
"copy",
"(",
"tags",
... | // Flush generates an InterMetric from the current state of this Counter. | [
"Flush",
"generates",
"an",
"InterMetric",
"from",
"the",
"current",
"state",
"of",
"this",
"Counter",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L147-L158 |
13,302 | stripe/veneur | samplers/samplers.go | Metric | func (c *Counter) Metric() (*metricpb.Metric, error) {
return &metricpb.Metric{
Name: c.Name,
Tags: c.Tags,
Type: metricpb.Type_Counter,
Value: &metricpb.Metric_Counter{&metricpb.CounterValue{Value: c.value}},
}, nil
} | go | func (c *Counter) Metric() (*metricpb.Metric, error) {
return &metricpb.Metric{
Name: c.Name,
Tags: c.Tags,
Type: metricpb.Type_Counter,
Value: &metricpb.Metric_Counter{&metricpb.CounterValue{Value: c.value}},
}, nil
} | [
"func",
"(",
"c",
"*",
"Counter",
")",
"Metric",
"(",
")",
"(",
"*",
"metricpb",
".",
"Metric",
",",
"error",
")",
"{",
"return",
"&",
"metricpb",
".",
"Metric",
"{",
"Name",
":",
"c",
".",
"Name",
",",
"Tags",
":",
"c",
".",
"Tags",
",",
"Type... | // Metric returns a protobuf-compatible metricpb.Metric with values set
// at the time this function was called. This should be used to export
// a Counter for forwarding. | [
"Metric",
"returns",
"a",
"protobuf",
"-",
"compatible",
"metricpb",
".",
"Metric",
"with",
"values",
"set",
"at",
"the",
"time",
"this",
"function",
"was",
"called",
".",
"This",
"should",
"be",
"used",
"to",
"export",
"a",
"Counter",
"for",
"forwarding",
... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L198-L205 |
13,303 | stripe/veneur | samplers/samplers.go | Merge | func (c *Counter) Merge(v *metricpb.CounterValue) {
c.value += v.Value
} | go | func (c *Counter) Merge(v *metricpb.CounterValue) {
c.value += v.Value
} | [
"func",
"(",
"c",
"*",
"Counter",
")",
"Merge",
"(",
"v",
"*",
"metricpb",
".",
"CounterValue",
")",
"{",
"c",
".",
"value",
"+=",
"v",
".",
"Value",
"\n",
"}"
] | // Merge adds the value from the input CounterValue to this one. | [
"Merge",
"adds",
"the",
"value",
"from",
"the",
"input",
"CounterValue",
"to",
"this",
"one",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L208-L210 |
13,304 | stripe/veneur | samplers/samplers.go | NewCounter | func NewCounter(Name string, Tags []string) *Counter {
return &Counter{Name: Name, Tags: Tags}
} | go | func NewCounter(Name string, Tags []string) *Counter {
return &Counter{Name: Name, Tags: Tags}
} | [
"func",
"NewCounter",
"(",
"Name",
"string",
",",
"Tags",
"[",
"]",
"string",
")",
"*",
"Counter",
"{",
"return",
"&",
"Counter",
"{",
"Name",
":",
"Name",
",",
"Tags",
":",
"Tags",
"}",
"\n",
"}"
] | // NewCounter generates and returns a new Counter. | [
"NewCounter",
"generates",
"and",
"returns",
"a",
"new",
"Counter",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L213-L215 |
13,305 | stripe/veneur | samplers/samplers.go | Flush | func (g *Gauge) Flush() []InterMetric {
tags := make([]string, len(g.Tags))
copy(tags, g.Tags)
return []InterMetric{{
Name: g.Name,
Timestamp: time.Now().Unix(),
Value: float64(g.value),
Tags: tags,
Type: GaugeMetric,
Sinks: routeInfo(tags),
}}
} | go | func (g *Gauge) Flush() []InterMetric {
tags := make([]string, len(g.Tags))
copy(tags, g.Tags)
return []InterMetric{{
Name: g.Name,
Timestamp: time.Now().Unix(),
Value: float64(g.value),
Tags: tags,
Type: GaugeMetric,
Sinks: routeInfo(tags),
}}
} | [
"func",
"(",
"g",
"*",
"Gauge",
")",
"Flush",
"(",
")",
"[",
"]",
"InterMetric",
"{",
"tags",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"g",
".",
"Tags",
")",
")",
"\n",
"copy",
"(",
"tags",
",",
"g",
".",
"Tags",
")",
"\n",
"... | // Flush generates an InterMetric from the current state of this gauge. | [
"Flush",
"generates",
"an",
"InterMetric",
"from",
"the",
"current",
"state",
"of",
"this",
"gauge",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L230-L242 |
13,306 | stripe/veneur | samplers/samplers.go | Export | func (g *Gauge) Export() (JSONMetric, error) {
var buf bytes.Buffer
err := binary.Write(&buf, binary.LittleEndian, g.value)
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: g.Name,
Type: "gauge",
JoinedTags: strings.Join(g.Tags, ","),
},
Tags: g.Tags,
Value: buf.Bytes(),
}, nil
} | go | func (g *Gauge) Export() (JSONMetric, error) {
var buf bytes.Buffer
err := binary.Write(&buf, binary.LittleEndian, g.value)
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: g.Name,
Type: "gauge",
JoinedTags: strings.Join(g.Tags, ","),
},
Tags: g.Tags,
Value: buf.Bytes(),
}, nil
} | [
"func",
"(",
"g",
"*",
"Gauge",
")",
"Export",
"(",
")",
"(",
"JSONMetric",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"err",
":=",
"binary",
".",
"Write",
"(",
"&",
"buf",
",",
"binary",
".",
"LittleEndian",
",",
"g",
... | // Export converts a Gauge into a JSONMetric. | [
"Export",
"converts",
"a",
"Gauge",
"into",
"a",
"JSONMetric",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L245-L262 |
13,307 | stripe/veneur | samplers/samplers.go | Metric | func (g *Gauge) Metric() (*metricpb.Metric, error) {
return &metricpb.Metric{
Name: g.Name,
Tags: g.Tags,
Type: metricpb.Type_Gauge,
Value: &metricpb.Metric_Gauge{&metricpb.GaugeValue{Value: g.value}},
}, nil
} | go | func (g *Gauge) Metric() (*metricpb.Metric, error) {
return &metricpb.Metric{
Name: g.Name,
Tags: g.Tags,
Type: metricpb.Type_Gauge,
Value: &metricpb.Metric_Gauge{&metricpb.GaugeValue{Value: g.value}},
}, nil
} | [
"func",
"(",
"g",
"*",
"Gauge",
")",
"Metric",
"(",
")",
"(",
"*",
"metricpb",
".",
"Metric",
",",
"error",
")",
"{",
"return",
"&",
"metricpb",
".",
"Metric",
"{",
"Name",
":",
"g",
".",
"Name",
",",
"Tags",
":",
"g",
".",
"Tags",
",",
"Type",... | // Metric returns a protobuf-compatible metricpb.Metric with values set
// at the time this function was called. This should be used to export
// a Gauge for forwarding. | [
"Metric",
"returns",
"a",
"protobuf",
"-",
"compatible",
"metricpb",
".",
"Metric",
"with",
"values",
"set",
"at",
"the",
"time",
"this",
"function",
"was",
"called",
".",
"This",
"should",
"be",
"used",
"to",
"export",
"a",
"Gauge",
"for",
"forwarding",
"... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L287-L294 |
13,308 | stripe/veneur | samplers/samplers.go | Merge | func (g *Gauge) Merge(v *metricpb.GaugeValue) {
g.value = v.Value
} | go | func (g *Gauge) Merge(v *metricpb.GaugeValue) {
g.value = v.Value
} | [
"func",
"(",
"g",
"*",
"Gauge",
")",
"Merge",
"(",
"v",
"*",
"metricpb",
".",
"GaugeValue",
")",
"{",
"g",
".",
"value",
"=",
"v",
".",
"Value",
"\n",
"}"
] | // Merge sets the value of this Gauge to the value of the other. | [
"Merge",
"sets",
"the",
"value",
"of",
"this",
"Gauge",
"to",
"the",
"value",
"of",
"the",
"other",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L297-L299 |
13,309 | stripe/veneur | samplers/samplers.go | Flush | func (s *StatusCheck) Flush() []InterMetric {
s.Timestamp = time.Now().Unix()
s.Type = StatusMetric
s.Sinks = routeInfo(s.Tags)
return []InterMetric{s.InterMetric}
} | go | func (s *StatusCheck) Flush() []InterMetric {
s.Timestamp = time.Now().Unix()
s.Type = StatusMetric
s.Sinks = routeInfo(s.Tags)
return []InterMetric{s.InterMetric}
} | [
"func",
"(",
"s",
"*",
"StatusCheck",
")",
"Flush",
"(",
")",
"[",
"]",
"InterMetric",
"{",
"s",
".",
"Timestamp",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Unix",
"(",
")",
"\n",
"s",
".",
"Type",
"=",
"StatusMetric",
"\n",
"s",
".",
"Sinks",
"... | // Flush generates an InterMetric from the current state of this status check. | [
"Flush",
"generates",
"an",
"InterMetric",
"from",
"the",
"current",
"state",
"of",
"this",
"status",
"check",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L319-L324 |
13,310 | stripe/veneur | samplers/samplers.go | Export | func (s *StatusCheck) Export() (JSONMetric, error) {
var buf bytes.Buffer
err := binary.Write(&buf, binary.LittleEndian, s.Value)
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: s.Name,
Type: "status",
JoinedTags: strings.Join(s.Tags, ","),
},
Tags: s.Tags,
Value: buf.Bytes(),
}, nil
} | go | func (s *StatusCheck) Export() (JSONMetric, error) {
var buf bytes.Buffer
err := binary.Write(&buf, binary.LittleEndian, s.Value)
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: s.Name,
Type: "status",
JoinedTags: strings.Join(s.Tags, ","),
},
Tags: s.Tags,
Value: buf.Bytes(),
}, nil
} | [
"func",
"(",
"s",
"*",
"StatusCheck",
")",
"Export",
"(",
")",
"(",
"JSONMetric",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"err",
":=",
"binary",
".",
"Write",
"(",
"&",
"buf",
",",
"binary",
".",
"LittleEndian",
",",
"... | // Export converts a StatusCheck into a JSONMetric. | [
"Export",
"converts",
"a",
"StatusCheck",
"into",
"a",
"JSONMetric",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L327-L344 |
13,311 | stripe/veneur | samplers/samplers.go | Sample | func (s *Set) Sample(sample string, sampleRate float32) {
s.Hll.Insert([]byte(sample))
} | go | func (s *Set) Sample(sample string, sampleRate float32) {
s.Hll.Insert([]byte(sample))
} | [
"func",
"(",
"s",
"*",
"Set",
")",
"Sample",
"(",
"sample",
"string",
",",
"sampleRate",
"float32",
")",
"{",
"s",
".",
"Hll",
".",
"Insert",
"(",
"[",
"]",
"byte",
"(",
"sample",
")",
")",
"\n",
"}"
] | // Sample checks if the supplied value has is already in the filter. If not, it increments
// the counter! | [
"Sample",
"checks",
"if",
"the",
"supplied",
"value",
"has",
"is",
"already",
"in",
"the",
"filter",
".",
"If",
"not",
"it",
"increments",
"the",
"counter!"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L375-L377 |
13,312 | stripe/veneur | samplers/samplers.go | NewSet | func NewSet(Name string, Tags []string) *Set {
// error is only returned if precision is outside the 4-18 range
// TODO: this is the maximum precision, should it be configurable?
Hll := hyperloglog.New()
return &Set{
Name: Name,
Tags: Tags,
Hll: Hll,
}
} | go | func NewSet(Name string, Tags []string) *Set {
// error is only returned if precision is outside the 4-18 range
// TODO: this is the maximum precision, should it be configurable?
Hll := hyperloglog.New()
return &Set{
Name: Name,
Tags: Tags,
Hll: Hll,
}
} | [
"func",
"NewSet",
"(",
"Name",
"string",
",",
"Tags",
"[",
"]",
"string",
")",
"*",
"Set",
"{",
"// error is only returned if precision is outside the 4-18 range",
"// TODO: this is the maximum precision, should it be configurable?",
"Hll",
":=",
"hyperloglog",
".",
"New",
... | // NewSet generates a new Set and returns it | [
"NewSet",
"generates",
"a",
"new",
"Set",
"and",
"returns",
"it"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L380-L389 |
13,313 | stripe/veneur | samplers/samplers.go | Flush | func (s *Set) Flush() []InterMetric {
tags := make([]string, len(s.Tags))
copy(tags, s.Tags)
return []InterMetric{{
Name: s.Name,
Timestamp: time.Now().Unix(),
Value: float64(s.Hll.Estimate()),
Tags: tags,
Type: GaugeMetric,
Sinks: routeInfo(tags),
}}
} | go | func (s *Set) Flush() []InterMetric {
tags := make([]string, len(s.Tags))
copy(tags, s.Tags)
return []InterMetric{{
Name: s.Name,
Timestamp: time.Now().Unix(),
Value: float64(s.Hll.Estimate()),
Tags: tags,
Type: GaugeMetric,
Sinks: routeInfo(tags),
}}
} | [
"func",
"(",
"s",
"*",
"Set",
")",
"Flush",
"(",
")",
"[",
"]",
"InterMetric",
"{",
"tags",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"s",
".",
"Tags",
")",
")",
"\n",
"copy",
"(",
"tags",
",",
"s",
".",
"Tags",
")",
"\n",
"re... | // Flush generates an InterMetric for the state of this Set. | [
"Flush",
"generates",
"an",
"InterMetric",
"for",
"the",
"state",
"of",
"this",
"Set",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L392-L403 |
13,314 | stripe/veneur | samplers/samplers.go | Export | func (s *Set) Export() (JSONMetric, error) {
val, err := s.Hll.MarshalBinary()
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: s.Name,
Type: "set",
JoinedTags: strings.Join(s.Tags, ","),
},
Tags: s.Tags,
Value: val,
}, nil
} | go | func (s *Set) Export() (JSONMetric, error) {
val, err := s.Hll.MarshalBinary()
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: s.Name,
Type: "set",
JoinedTags: strings.Join(s.Tags, ","),
},
Tags: s.Tags,
Value: val,
}, nil
} | [
"func",
"(",
"s",
"*",
"Set",
")",
"Export",
"(",
")",
"(",
"JSONMetric",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"s",
".",
"Hll",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"JSONMetric",
"{",
"}",
"... | // Export converts a Set into a JSONMetric which reports the Tags in the set. | [
"Export",
"converts",
"a",
"Set",
"into",
"a",
"JSONMetric",
"which",
"reports",
"the",
"Tags",
"in",
"the",
"set",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L406-L420 |
13,315 | stripe/veneur | samplers/samplers.go | Metric | func (s *Set) Metric() (*metricpb.Metric, error) {
encoded, err := s.Hll.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("failed to encode the HyperLogLog: %v", err)
}
return &metricpb.Metric{
Name: s.Name,
Tags: s.Tags,
Type: metricpb.Type_Set,
Value: &metricpb.Metric_Set{&metricpb.SetValue{HyperLogLog: encoded}},
}, nil
} | go | func (s *Set) Metric() (*metricpb.Metric, error) {
encoded, err := s.Hll.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("failed to encode the HyperLogLog: %v", err)
}
return &metricpb.Metric{
Name: s.Name,
Tags: s.Tags,
Type: metricpb.Type_Set,
Value: &metricpb.Metric_Set{&metricpb.SetValue{HyperLogLog: encoded}},
}, nil
} | [
"func",
"(",
"s",
"*",
"Set",
")",
"Metric",
"(",
")",
"(",
"*",
"metricpb",
".",
"Metric",
",",
"error",
")",
"{",
"encoded",
",",
"err",
":=",
"s",
".",
"Hll",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ni... | // Metric returns a protobuf-compatible metricpb.Metric with values set
// at the time this function was called. This should be used to export
// a Set for forwarding. | [
"Metric",
"returns",
"a",
"protobuf",
"-",
"compatible",
"metricpb",
".",
"Metric",
"with",
"values",
"set",
"at",
"the",
"time",
"this",
"function",
"was",
"called",
".",
"This",
"should",
"be",
"used",
"to",
"export",
"a",
"Set",
"for",
"forwarding",
"."... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L445-L457 |
13,316 | stripe/veneur | samplers/samplers.go | Merge | func (s *Set) Merge(v *metricpb.SetValue) error {
return s.Combine(v.HyperLogLog)
} | go | func (s *Set) Merge(v *metricpb.SetValue) error {
return s.Combine(v.HyperLogLog)
} | [
"func",
"(",
"s",
"*",
"Set",
")",
"Merge",
"(",
"v",
"*",
"metricpb",
".",
"SetValue",
")",
"error",
"{",
"return",
"s",
".",
"Combine",
"(",
"v",
".",
"HyperLogLog",
")",
"\n",
"}"
] | // Merge combines the HyperLogLog with that of the input Set. Since the
// HyperLogLog is marshalled in the value, it unmarshals it first. | [
"Merge",
"combines",
"the",
"HyperLogLog",
"with",
"that",
"of",
"the",
"input",
"Set",
".",
"Since",
"the",
"HyperLogLog",
"is",
"marshalled",
"in",
"the",
"value",
"it",
"unmarshals",
"it",
"first",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L461-L463 |
13,317 | stripe/veneur | samplers/samplers.go | Sample | func (h *Histo) Sample(sample float64, sampleRate float32) {
weight := float64(1 / sampleRate)
h.Value.Add(sample, weight)
h.LocalWeight += weight
h.LocalMin = math.Min(h.LocalMin, sample)
h.LocalMax = math.Max(h.LocalMax, sample)
h.LocalSum += sample * weight
h.LocalReciprocalSum += (1 / sample) * weight
} | go | func (h *Histo) Sample(sample float64, sampleRate float32) {
weight := float64(1 / sampleRate)
h.Value.Add(sample, weight)
h.LocalWeight += weight
h.LocalMin = math.Min(h.LocalMin, sample)
h.LocalMax = math.Max(h.LocalMax, sample)
h.LocalSum += sample * weight
h.LocalReciprocalSum += (1 / sample) * weight
} | [
"func",
"(",
"h",
"*",
"Histo",
")",
"Sample",
"(",
"sample",
"float64",
",",
"sampleRate",
"float32",
")",
"{",
"weight",
":=",
"float64",
"(",
"1",
"/",
"sampleRate",
")",
"\n",
"h",
".",
"Value",
".",
"Add",
"(",
"sample",
",",
"weight",
")",
"\... | // Sample adds the supplied value to the histogram. | [
"Sample",
"adds",
"the",
"supplied",
"value",
"to",
"the",
"histogram",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L484-L494 |
13,318 | stripe/veneur | samplers/samplers.go | NewHist | func NewHist(Name string, Tags []string) *Histo {
return &Histo{
Name: Name,
Tags: Tags,
// we're going to allocate a lot of these, so we don't want them to be huge
Value: tdigest.NewMerging(100, false),
LocalMin: math.Inf(+1),
LocalMax: math.Inf(-1),
LocalSum: 0,
}
} | go | func NewHist(Name string, Tags []string) *Histo {
return &Histo{
Name: Name,
Tags: Tags,
// we're going to allocate a lot of these, so we don't want them to be huge
Value: tdigest.NewMerging(100, false),
LocalMin: math.Inf(+1),
LocalMax: math.Inf(-1),
LocalSum: 0,
}
} | [
"func",
"NewHist",
"(",
"Name",
"string",
",",
"Tags",
"[",
"]",
"string",
")",
"*",
"Histo",
"{",
"return",
"&",
"Histo",
"{",
"Name",
":",
"Name",
",",
"Tags",
":",
"Tags",
",",
"// we're going to allocate a lot of these, so we don't want them to be huge",
"Va... | // NewHist generates a new Histo and returns it. | [
"NewHist",
"generates",
"a",
"new",
"Histo",
"and",
"returns",
"it",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L497-L507 |
13,319 | stripe/veneur | samplers/samplers.go | Export | func (h *Histo) Export() (JSONMetric, error) {
val, err := h.Value.GobEncode()
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: h.Name,
Type: "histogram",
JoinedTags: strings.Join(h.Tags, ","),
},
Tags: h.Tags,
Value: val,
}, nil
} | go | func (h *Histo) Export() (JSONMetric, error) {
val, err := h.Value.GobEncode()
if err != nil {
return JSONMetric{}, err
}
return JSONMetric{
MetricKey: MetricKey{
Name: h.Name,
Type: "histogram",
JoinedTags: strings.Join(h.Tags, ","),
},
Tags: h.Tags,
Value: val,
}, nil
} | [
"func",
"(",
"h",
"*",
"Histo",
")",
"Export",
"(",
")",
"(",
"JSONMetric",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"h",
".",
"Value",
".",
"GobEncode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"JSONMetric",
"{",
"}",
"... | // Export converts a Histogram into a JSONMetric | [
"Export",
"converts",
"a",
"Histogram",
"into",
"a",
"JSONMetric"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L678-L692 |
13,320 | stripe/veneur | samplers/samplers.go | Metric | func (h *Histo) Metric() (*metricpb.Metric, error) {
return &metricpb.Metric{
Name: h.Name,
Tags: h.Tags,
Type: metricpb.Type_Histogram,
Value: &metricpb.Metric_Histogram{&metricpb.HistogramValue{
TDigest: h.Value.Data(),
}},
}, nil
} | go | func (h *Histo) Metric() (*metricpb.Metric, error) {
return &metricpb.Metric{
Name: h.Name,
Tags: h.Tags,
Type: metricpb.Type_Histogram,
Value: &metricpb.Metric_Histogram{&metricpb.HistogramValue{
TDigest: h.Value.Data(),
}},
}, nil
} | [
"func",
"(",
"h",
"*",
"Histo",
")",
"Metric",
"(",
")",
"(",
"*",
"metricpb",
".",
"Metric",
",",
"error",
")",
"{",
"return",
"&",
"metricpb",
".",
"Metric",
"{",
"Name",
":",
"h",
".",
"Name",
",",
"Tags",
":",
"h",
".",
"Tags",
",",
"Type",... | // Metric returns a protobuf-compatible metricpb.Metric with values set
// at the time this function was called. This should be used to export
// a Histo for forwarding. | [
"Metric",
"returns",
"a",
"protobuf",
"-",
"compatible",
"metricpb",
".",
"Metric",
"with",
"values",
"set",
"at",
"the",
"time",
"this",
"function",
"was",
"called",
".",
"This",
"should",
"be",
"used",
"to",
"export",
"a",
"Histo",
"for",
"forwarding",
"... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L713-L722 |
13,321 | stripe/veneur | samplers/samplers.go | Merge | func (h *Histo) Merge(v *metricpb.HistogramValue) {
if v.TDigest != nil {
h.Value.Merge(tdigest.NewMergingFromData(v.TDigest))
}
} | go | func (h *Histo) Merge(v *metricpb.HistogramValue) {
if v.TDigest != nil {
h.Value.Merge(tdigest.NewMergingFromData(v.TDigest))
}
} | [
"func",
"(",
"h",
"*",
"Histo",
")",
"Merge",
"(",
"v",
"*",
"metricpb",
".",
"HistogramValue",
")",
"{",
"if",
"v",
".",
"TDigest",
"!=",
"nil",
"{",
"h",
".",
"Value",
".",
"Merge",
"(",
"tdigest",
".",
"NewMergingFromData",
"(",
"v",
".",
"TDige... | // Merge merges the t-digests of the two histograms and mutates the state
// of this one. | [
"Merge",
"merges",
"the",
"t",
"-",
"digests",
"of",
"the",
"two",
"histograms",
"and",
"mutates",
"the",
"state",
"of",
"this",
"one",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/samplers.go#L726-L730 |
13,322 | stripe/veneur | samplers/parser.go | ToPB | func (m MetricScope) ToPB() metricpb.Scope {
switch m {
case MixedScope:
return metricpb.Scope_Mixed
case LocalOnly:
return metricpb.Scope_Local
case GlobalOnly:
return metricpb.Scope_Global
}
return 0
} | go | func (m MetricScope) ToPB() metricpb.Scope {
switch m {
case MixedScope:
return metricpb.Scope_Mixed
case LocalOnly:
return metricpb.Scope_Local
case GlobalOnly:
return metricpb.Scope_Global
}
return 0
} | [
"func",
"(",
"m",
"MetricScope",
")",
"ToPB",
"(",
")",
"metricpb",
".",
"Scope",
"{",
"switch",
"m",
"{",
"case",
"MixedScope",
":",
"return",
"metricpb",
".",
"Scope_Mixed",
"\n",
"case",
"LocalOnly",
":",
"return",
"metricpb",
".",
"Scope_Local",
"\n",
... | // ToPB maps the metric scope to a protobuf Scope type. | [
"ToPB",
"maps",
"the",
"metric",
"scope",
"to",
"a",
"protobuf",
"Scope",
"type",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L40-L50 |
13,323 | stripe/veneur | samplers/parser.go | ScopeFromPB | func ScopeFromPB(scope metricpb.Scope) MetricScope {
switch scope {
case metricpb.Scope_Global:
return GlobalOnly
case metricpb.Scope_Local:
return LocalOnly
case metricpb.Scope_Mixed:
return MixedScope
}
return 0
} | go | func ScopeFromPB(scope metricpb.Scope) MetricScope {
switch scope {
case metricpb.Scope_Global:
return GlobalOnly
case metricpb.Scope_Local:
return LocalOnly
case metricpb.Scope_Mixed:
return MixedScope
}
return 0
} | [
"func",
"ScopeFromPB",
"(",
"scope",
"metricpb",
".",
"Scope",
")",
"MetricScope",
"{",
"switch",
"scope",
"{",
"case",
"metricpb",
".",
"Scope_Global",
":",
"return",
"GlobalOnly",
"\n",
"case",
"metricpb",
".",
"Scope_Local",
":",
"return",
"LocalOnly",
"\n"... | // ScopeFromPB creates an internal MetricScope type from the protobuf Scope type. | [
"ScopeFromPB",
"creates",
"an",
"internal",
"MetricScope",
"type",
"from",
"the",
"protobuf",
"Scope",
"type",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L53-L64 |
13,324 | stripe/veneur | samplers/parser.go | NewMetricKeyFromMetric | func NewMetricKeyFromMetric(m *metricpb.Metric) MetricKey {
return MetricKey{
Name: m.Name,
Type: strings.ToLower(m.Type.String()),
JoinedTags: strings.Join(m.Tags, ","),
}
} | go | func NewMetricKeyFromMetric(m *metricpb.Metric) MetricKey {
return MetricKey{
Name: m.Name,
Type: strings.ToLower(m.Type.String()),
JoinedTags: strings.Join(m.Tags, ","),
}
} | [
"func",
"NewMetricKeyFromMetric",
"(",
"m",
"*",
"metricpb",
".",
"Metric",
")",
"MetricKey",
"{",
"return",
"MetricKey",
"{",
"Name",
":",
"m",
".",
"Name",
",",
"Type",
":",
"strings",
".",
"ToLower",
"(",
"m",
".",
"Type",
".",
"String",
"(",
")",
... | // NewMetricKeyFromMetric initializes a MetricKey from the protobuf-compatible
// metricpb.Metric | [
"NewMetricKeyFromMetric",
"initializes",
"a",
"MetricKey",
"from",
"the",
"protobuf",
"-",
"compatible",
"metricpb",
".",
"Metric"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L81-L87 |
13,325 | stripe/veneur | samplers/parser.go | String | func (m MetricKey) String() string {
var buff bytes.Buffer
buff.WriteString(m.Name)
buff.WriteString(m.Type)
buff.WriteString(m.JoinedTags)
return buff.String()
} | go | func (m MetricKey) String() string {
var buff bytes.Buffer
buff.WriteString(m.Name)
buff.WriteString(m.Type)
buff.WriteString(m.JoinedTags)
return buff.String()
} | [
"func",
"(",
"m",
"MetricKey",
")",
"String",
"(",
")",
"string",
"{",
"var",
"buff",
"bytes",
".",
"Buffer",
"\n",
"buff",
".",
"WriteString",
"(",
"m",
".",
"Name",
")",
"\n",
"buff",
".",
"WriteString",
"(",
"m",
".",
"Type",
")",
"\n",
"buff",
... | // ToString returns a string representation of this MetricKey | [
"ToString",
"returns",
"a",
"string",
"representation",
"of",
"this",
"MetricKey"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L90-L96 |
13,326 | stripe/veneur | samplers/parser.go | ConvertMetrics | func ConvertMetrics(m *ssf.SSFSpan) ([]UDPMetric, error) {
samples := m.Metrics
metrics := make([]UDPMetric, 0, len(samples)+1)
invalid := []*ssf.SSFSample{}
for _, metricPacket := range samples {
metric, err := ParseMetricSSF(metricPacket)
if err != nil || !ValidMetric(metric) {
invalid = append(invalid, metricPacket)
continue
}
metrics = append(metrics, metric)
}
if len(invalid) != 0 {
return metrics, &invalidMetrics{invalid}
}
return metrics, nil
} | go | func ConvertMetrics(m *ssf.SSFSpan) ([]UDPMetric, error) {
samples := m.Metrics
metrics := make([]UDPMetric, 0, len(samples)+1)
invalid := []*ssf.SSFSample{}
for _, metricPacket := range samples {
metric, err := ParseMetricSSF(metricPacket)
if err != nil || !ValidMetric(metric) {
invalid = append(invalid, metricPacket)
continue
}
metrics = append(metrics, metric)
}
if len(invalid) != 0 {
return metrics, &invalidMetrics{invalid}
}
return metrics, nil
} | [
"func",
"ConvertMetrics",
"(",
"m",
"*",
"ssf",
".",
"SSFSpan",
")",
"(",
"[",
"]",
"UDPMetric",
",",
"error",
")",
"{",
"samples",
":=",
"m",
".",
"Metrics",
"\n",
"metrics",
":=",
"make",
"(",
"[",
"]",
"UDPMetric",
",",
"0",
",",
"len",
"(",
"... | // ConvertMetrics examines an SSF message, parses and returns a new
// array containing any metrics contained in the message. If any parse
// error occurs in processing any of the metrics, ExtractMetrics
// collects them into the error type InvalidMetrics and returns this
// error alongside any valid metrics that could be parsed. | [
"ConvertMetrics",
"examines",
"an",
"SSF",
"message",
"parses",
"and",
"returns",
"a",
"new",
"array",
"containing",
"any",
"metrics",
"contained",
"in",
"the",
"message",
".",
"If",
"any",
"parse",
"error",
"occurs",
"in",
"processing",
"any",
"of",
"the",
... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L103-L120 |
13,327 | stripe/veneur | samplers/parser.go | ValidMetric | func ValidMetric(sample UDPMetric) bool {
ret := true
ret = ret && sample.Name != ""
ret = ret && sample.Value != nil
return ret
} | go | func ValidMetric(sample UDPMetric) bool {
ret := true
ret = ret && sample.Name != ""
ret = ret && sample.Value != nil
return ret
} | [
"func",
"ValidMetric",
"(",
"sample",
"UDPMetric",
")",
"bool",
"{",
"ret",
":=",
"true",
"\n",
"ret",
"=",
"ret",
"&&",
"sample",
".",
"Name",
"!=",
"\"",
"\"",
"\n",
"ret",
"=",
"ret",
"&&",
"sample",
".",
"Value",
"!=",
"nil",
"\n",
"return",
"r... | // ValidMetric takes in an SSF sample and determines if it is valid or not. | [
"ValidMetric",
"takes",
"in",
"an",
"SSF",
"sample",
"and",
"determines",
"if",
"it",
"is",
"valid",
"or",
"not",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L211-L216 |
13,328 | stripe/veneur | samplers/parser.go | ParseMetricSSF | func ParseMetricSSF(metric *ssf.SSFSample) (UDPMetric, error) {
ret := UDPMetric{
SampleRate: 1.0,
}
h := fnv1a.Init32
h = fnv1a.AddString32(h, metric.Name)
ret.Name = metric.Name
switch metric.Metric {
case ssf.SSFSample_COUNTER:
ret.Type = "counter"
case ssf.SSFSample_GAUGE:
ret.Type = "gauge"
case ssf.SSFSample_HISTOGRAM:
ret.Type = "histogram"
case ssf.SSFSample_SET:
ret.Type = "set"
case ssf.SSFSample_STATUS:
ret.Type = "status"
default:
return UDPMetric{}, invalidMetricTypeError
}
h = fnv1a.AddString32(h, ret.Type)
switch metric.Metric {
case ssf.SSFSample_SET:
ret.Value = metric.Message
case ssf.SSFSample_STATUS:
ret.Value = metric.Status
default:
ret.Value = float64(metric.Value)
}
ret.SampleRate = metric.SampleRate
tempTags := make([]string, 0, len(metric.Tags))
for key, value := range metric.Tags {
if key == "veneurlocalonly" {
ret.Scope = LocalOnly
continue
}
if key == "veneurglobalonly" {
ret.Scope = GlobalOnly
continue
}
tempTags = append(tempTags, key+":"+value)
}
sort.Strings(tempTags)
ret.Tags = tempTags
ret.JoinedTags = strings.Join(tempTags, ",")
h = fnv1a.AddString32(h, ret.JoinedTags)
ret.Digest = h
return ret, nil
} | go | func ParseMetricSSF(metric *ssf.SSFSample) (UDPMetric, error) {
ret := UDPMetric{
SampleRate: 1.0,
}
h := fnv1a.Init32
h = fnv1a.AddString32(h, metric.Name)
ret.Name = metric.Name
switch metric.Metric {
case ssf.SSFSample_COUNTER:
ret.Type = "counter"
case ssf.SSFSample_GAUGE:
ret.Type = "gauge"
case ssf.SSFSample_HISTOGRAM:
ret.Type = "histogram"
case ssf.SSFSample_SET:
ret.Type = "set"
case ssf.SSFSample_STATUS:
ret.Type = "status"
default:
return UDPMetric{}, invalidMetricTypeError
}
h = fnv1a.AddString32(h, ret.Type)
switch metric.Metric {
case ssf.SSFSample_SET:
ret.Value = metric.Message
case ssf.SSFSample_STATUS:
ret.Value = metric.Status
default:
ret.Value = float64(metric.Value)
}
ret.SampleRate = metric.SampleRate
tempTags := make([]string, 0, len(metric.Tags))
for key, value := range metric.Tags {
if key == "veneurlocalonly" {
ret.Scope = LocalOnly
continue
}
if key == "veneurglobalonly" {
ret.Scope = GlobalOnly
continue
}
tempTags = append(tempTags, key+":"+value)
}
sort.Strings(tempTags)
ret.Tags = tempTags
ret.JoinedTags = strings.Join(tempTags, ",")
h = fnv1a.AddString32(h, ret.JoinedTags)
ret.Digest = h
return ret, nil
} | [
"func",
"ParseMetricSSF",
"(",
"metric",
"*",
"ssf",
".",
"SSFSample",
")",
"(",
"UDPMetric",
",",
"error",
")",
"{",
"ret",
":=",
"UDPMetric",
"{",
"SampleRate",
":",
"1.0",
",",
"}",
"\n",
"h",
":=",
"fnv1a",
".",
"Init32",
"\n",
"h",
"=",
"fnv1a",... | // ParseMetricSSF converts an incoming SSF packet to a Metric. | [
"ParseMetricSSF",
"converts",
"an",
"incoming",
"SSF",
"packet",
"to",
"a",
"Metric",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/parser.go#L239-L288 |
13,329 | stripe/veneur | proxysrv/options.go | WithForwardTimeout | func WithForwardTimeout(d time.Duration) Option {
return func(opts *options) {
opts.forwardTimeout = d
}
} | go | func WithForwardTimeout(d time.Duration) Option {
return func(opts *options) {
opts.forwardTimeout = d
}
} | [
"func",
"WithForwardTimeout",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"options",
")",
"{",
"opts",
".",
"forwardTimeout",
"=",
"d",
"\n",
"}",
"\n",
"}"
] | // WithForwardTimeout sets the time after which an individual RPC to a
// downstream Veneur times out | [
"WithForwardTimeout",
"sets",
"the",
"time",
"after",
"which",
"an",
"individual",
"RPC",
"to",
"a",
"downstream",
"Veneur",
"times",
"out"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/options.go#L12-L16 |
13,330 | stripe/veneur | proxysrv/options.go | WithLog | func WithLog(e *logrus.Entry) Option {
return func(opts *options) {
opts.log = e
}
} | go | func WithLog(e *logrus.Entry) Option {
return func(opts *options) {
opts.log = e
}
} | [
"func",
"WithLog",
"(",
"e",
"*",
"logrus",
".",
"Entry",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"options",
")",
"{",
"opts",
".",
"log",
"=",
"e",
"\n",
"}",
"\n",
"}"
] | // WithLog sets the logger entry used in the object. | [
"WithLog",
"sets",
"the",
"logger",
"entry",
"used",
"in",
"the",
"object",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/options.go#L19-L23 |
13,331 | stripe/veneur | proxysrv/options.go | WithStatsInterval | func WithStatsInterval(d time.Duration) Option {
return func(opts *options) {
opts.statsInterval = d
}
} | go | func WithStatsInterval(d time.Duration) Option {
return func(opts *options) {
opts.statsInterval = d
}
} | [
"func",
"WithStatsInterval",
"(",
"d",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"options",
")",
"{",
"opts",
".",
"statsInterval",
"=",
"d",
"\n",
"}",
"\n",
"}"
] | // WithStatsInterval sets the time interval at which diagnostic metrics about
// the server will be emitted. | [
"WithStatsInterval",
"sets",
"the",
"time",
"interval",
"at",
"which",
"diagnostic",
"metrics",
"about",
"the",
"server",
"will",
"be",
"emitted",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/options.go#L27-L31 |
13,332 | stripe/veneur | proxysrv/options.go | WithTraceClient | func WithTraceClient(c *trace.Client) Option {
return func(opts *options) {
opts.traceClient = c
}
} | go | func WithTraceClient(c *trace.Client) Option {
return func(opts *options) {
opts.traceClient = c
}
} | [
"func",
"WithTraceClient",
"(",
"c",
"*",
"trace",
".",
"Client",
")",
"Option",
"{",
"return",
"func",
"(",
"opts",
"*",
"options",
")",
"{",
"opts",
".",
"traceClient",
"=",
"c",
"\n",
"}",
"\n",
"}"
] | // WithTraceClient sets the trace client used by the server. | [
"WithTraceClient",
"sets",
"the",
"trace",
"client",
"used",
"by",
"the",
"server",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/options.go#L34-L38 |
13,333 | stripe/veneur | plugins/s3/csv.go | EncodeInterMetricCSV | func EncodeInterMetricCSV(d samplers.InterMetric, w *csv.Writer, partitionDate *time.Time, hostName string, interval int) error {
// TODO(aditya) some better error handling for this
// to guarantee that the result is proper JSON
tags := "{" + strings.Join(d.Tags, ",") + "}"
metricType := ""
metricValue := d.Value
switch d.Type {
case samplers.CounterMetric:
metricValue = d.Value / float64(interval)
metricType = "rate"
case samplers.GaugeMetric:
metricType = "gauge"
default:
return errors.New(fmt.Sprintf("Encountered an unknown metric type %s", d.Type.String()))
}
fields := [...]string{
// the order here doesn't actually matter
// as long as the keys are right
TsvName: d.Name,
TsvTags: tags,
TsvMetricType: metricType,
TsvInterval: strconv.Itoa(interval),
TsvVeneurHostname: hostName,
TsvValue: strconv.FormatFloat(metricValue, 'f', -1, 64),
TsvTimestamp: time.Unix(d.Timestamp, 0).UTC().Format(RedshiftDateFormat),
// TODO avoid edge case at midnight
TsvPartition: partitionDate.UTC().Format(PartitionDateFormat),
}
w.Write(fields[:])
return w.Error()
} | go | func EncodeInterMetricCSV(d samplers.InterMetric, w *csv.Writer, partitionDate *time.Time, hostName string, interval int) error {
// TODO(aditya) some better error handling for this
// to guarantee that the result is proper JSON
tags := "{" + strings.Join(d.Tags, ",") + "}"
metricType := ""
metricValue := d.Value
switch d.Type {
case samplers.CounterMetric:
metricValue = d.Value / float64(interval)
metricType = "rate"
case samplers.GaugeMetric:
metricType = "gauge"
default:
return errors.New(fmt.Sprintf("Encountered an unknown metric type %s", d.Type.String()))
}
fields := [...]string{
// the order here doesn't actually matter
// as long as the keys are right
TsvName: d.Name,
TsvTags: tags,
TsvMetricType: metricType,
TsvInterval: strconv.Itoa(interval),
TsvVeneurHostname: hostName,
TsvValue: strconv.FormatFloat(metricValue, 'f', -1, 64),
TsvTimestamp: time.Unix(d.Timestamp, 0).UTC().Format(RedshiftDateFormat),
// TODO avoid edge case at midnight
TsvPartition: partitionDate.UTC().Format(PartitionDateFormat),
}
w.Write(fields[:])
return w.Error()
} | [
"func",
"EncodeInterMetricCSV",
"(",
"d",
"samplers",
".",
"InterMetric",
",",
"w",
"*",
"csv",
".",
"Writer",
",",
"partitionDate",
"*",
"time",
".",
"Time",
",",
"hostName",
"string",
",",
"interval",
"int",
")",
"error",
"{",
"// TODO(aditya) some better er... | // EncodeInterMetricCSV generates a newline-terminated CSV row that describes
// the data represented by the InterMetric.
// The caller is responsible for setting w.Comma as the appropriate delimiter.
// For performance, encodeCSV does not flush after every call; the caller is
// expected to flush at the end of the operation cycle | [
"EncodeInterMetricCSV",
"generates",
"a",
"newline",
"-",
"terminated",
"CSV",
"row",
"that",
"describes",
"the",
"data",
"represented",
"by",
"the",
"InterMetric",
".",
"The",
"caller",
"is",
"responsible",
"for",
"setting",
"w",
".",
"Comma",
"as",
"the",
"a... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/plugins/s3/csv.go#L56-L92 |
13,334 | stripe/veneur | proxysrv/server.go | New | func New(destinations *consistent.Consistent, opts ...Option) (*Server, error) {
res := &Server{
Server: grpc.NewServer(),
opts: &options{
forwardTimeout: defaultForwardTimeout,
statsInterval: defaultReportStatsInterval,
},
conns: newClientConnMap(grpc.WithInsecure()),
activeProxyHandlers: new(int64),
}
for _, opt := range opts {
opt(res.opts)
}
if res.opts.log == nil {
log := logrus.New()
log.Out = ioutil.Discard
res.opts.log = logrus.NewEntry(log)
}
if err := res.SetDestinations(destinations); err != nil {
return nil, fmt.Errorf("failed to set the destinations: %v", err)
}
forwardrpc.RegisterForwardServer(res.Server, res)
return res, nil
} | go | func New(destinations *consistent.Consistent, opts ...Option) (*Server, error) {
res := &Server{
Server: grpc.NewServer(),
opts: &options{
forwardTimeout: defaultForwardTimeout,
statsInterval: defaultReportStatsInterval,
},
conns: newClientConnMap(grpc.WithInsecure()),
activeProxyHandlers: new(int64),
}
for _, opt := range opts {
opt(res.opts)
}
if res.opts.log == nil {
log := logrus.New()
log.Out = ioutil.Discard
res.opts.log = logrus.NewEntry(log)
}
if err := res.SetDestinations(destinations); err != nil {
return nil, fmt.Errorf("failed to set the destinations: %v", err)
}
forwardrpc.RegisterForwardServer(res.Server, res)
return res, nil
} | [
"func",
"New",
"(",
"destinations",
"*",
"consistent",
".",
"Consistent",
",",
"opts",
"...",
"Option",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"res",
":=",
"&",
"Server",
"{",
"Server",
":",
"grpc",
".",
"NewServer",
"(",
")",
",",
"opts",
... | // New creates a new Server with the provided destinations. The server returned
// is unstarted. | [
"New",
"creates",
"a",
"new",
"Server",
"with",
"the",
"provided",
"destinations",
".",
"The",
"server",
"returned",
"is",
"unstarted",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L67-L95 |
13,335 | stripe/veneur | proxysrv/server.go | SetDestinations | func (s *Server) SetDestinations(dests *consistent.Consistent) error {
s.updateMtx.Lock()
defer s.updateMtx.Unlock()
var current []string
if s.destinations != nil {
current = s.destinations.Members()
}
new := dests.Members()
// for every connection in the map that isn't in either the current or
// previous list of destinations, delete it
for _, k := range s.conns.Keys() {
if !strInSlice(k, current) && !strInSlice(k, new) {
s.conns.Delete(k)
}
}
// create a connection for each destination
for _, dest := range new {
if err := s.conns.Add(dest); err != nil {
return fmt.Errorf("failed to setup a connection for the "+
"destination '%s': %v", dest, err)
}
}
s.destinations = dests
return nil
} | go | func (s *Server) SetDestinations(dests *consistent.Consistent) error {
s.updateMtx.Lock()
defer s.updateMtx.Unlock()
var current []string
if s.destinations != nil {
current = s.destinations.Members()
}
new := dests.Members()
// for every connection in the map that isn't in either the current or
// previous list of destinations, delete it
for _, k := range s.conns.Keys() {
if !strInSlice(k, current) && !strInSlice(k, new) {
s.conns.Delete(k)
}
}
// create a connection for each destination
for _, dest := range new {
if err := s.conns.Add(dest); err != nil {
return fmt.Errorf("failed to setup a connection for the "+
"destination '%s': %v", dest, err)
}
}
s.destinations = dests
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"SetDestinations",
"(",
"dests",
"*",
"consistent",
".",
"Consistent",
")",
"error",
"{",
"s",
".",
"updateMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"updateMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"var"... | // SetDestinations updates the ring of hosts that are forwarded to by
// the server. If new hosts are being added, a gRPC connection is initialized
// for each.
//
// This also prunes the list of open connections. If a connection exists to
// a host that wasn't in either the current list or the last one, the
// connection is closed. | [
"SetDestinations",
"updates",
"the",
"ring",
"of",
"hosts",
"that",
"are",
"forwarded",
"to",
"by",
"the",
"server",
".",
"If",
"new",
"hosts",
"are",
"being",
"added",
"a",
"gRPC",
"connection",
"is",
"initialized",
"for",
"each",
".",
"This",
"also",
"pr... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L147-L175 |
13,336 | stripe/veneur | proxysrv/server.go | SendMetrics | func (s *Server) SendMetrics(ctx context.Context, mlist *forwardrpc.MetricList) (*empty.Empty, error) {
go func() {
// Track the number of active goroutines in a counter
atomic.AddInt64(s.activeProxyHandlers, 1)
_ = s.sendMetrics(context.Background(), mlist)
atomic.AddInt64(s.activeProxyHandlers, -1)
}()
return &empty.Empty{}, nil
} | go | func (s *Server) SendMetrics(ctx context.Context, mlist *forwardrpc.MetricList) (*empty.Empty, error) {
go func() {
// Track the number of active goroutines in a counter
atomic.AddInt64(s.activeProxyHandlers, 1)
_ = s.sendMetrics(context.Background(), mlist)
atomic.AddInt64(s.activeProxyHandlers, -1)
}()
return &empty.Empty{}, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"SendMetrics",
"(",
"ctx",
"context",
".",
"Context",
",",
"mlist",
"*",
"forwardrpc",
".",
"MetricList",
")",
"(",
"*",
"empty",
".",
"Empty",
",",
"error",
")",
"{",
"go",
"func",
"(",
")",
"{",
"// Track the n... | // SendMetrics spawns a new goroutine that forwards metrics to the destinations
// and exist immediately. | [
"SendMetrics",
"spawns",
"a",
"new",
"goroutine",
"that",
"forwards",
"metrics",
"to",
"the",
"destinations",
"and",
"exist",
"immediately",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L179-L187 |
13,337 | stripe/veneur | proxysrv/server.go | destForMetric | func (s *Server) destForMetric(m *metricpb.Metric) (string, error) {
key := samplers.NewMetricKeyFromMetric(m)
dest, err := s.destinations.Get(key.String())
if err != nil {
return "", fmt.Errorf("failed to hash the MetricKey '%s' to a "+
"destination: %v", key.String(), err)
}
return dest, nil
} | go | func (s *Server) destForMetric(m *metricpb.Metric) (string, error) {
key := samplers.NewMetricKeyFromMetric(m)
dest, err := s.destinations.Get(key.String())
if err != nil {
return "", fmt.Errorf("failed to hash the MetricKey '%s' to a "+
"destination: %v", key.String(), err)
}
return dest, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"destForMetric",
"(",
"m",
"*",
"metricpb",
".",
"Metric",
")",
"(",
"string",
",",
"error",
")",
"{",
"key",
":=",
"samplers",
".",
"NewMetricKeyFromMetric",
"(",
"m",
")",
"\n",
"dest",
",",
"err",
":=",
"s",
... | // destForMetric returns a destination for the input metric. | [
"destForMetric",
"returns",
"a",
"destination",
"for",
"the",
"input",
"metric",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L272-L281 |
13,338 | stripe/veneur | proxysrv/server.go | forward | func (s *Server) forward(ctx context.Context, dest string, ms []*metricpb.Metric) (err error) {
conn, ok := s.conns.Get(dest)
if !ok {
return fmt.Errorf("no connection was found for the host '%s'", dest)
}
c := forwardrpc.NewForwardClient(conn)
_, err = c.SendMetrics(ctx, &forwardrpc.MetricList{Metrics: ms})
if err != nil {
return fmt.Errorf("failed to send %d metrics over gRPC: %v",
len(ms), err)
}
_ = metrics.ReportBatch(s.opts.traceClient, ssf.RandomlySample(0.1,
ssf.Count("metrics_by_destination", float32(len(ms)),
map[string]string{"destination": dest, "protocol": "grpc"}),
))
return nil
} | go | func (s *Server) forward(ctx context.Context, dest string, ms []*metricpb.Metric) (err error) {
conn, ok := s.conns.Get(dest)
if !ok {
return fmt.Errorf("no connection was found for the host '%s'", dest)
}
c := forwardrpc.NewForwardClient(conn)
_, err = c.SendMetrics(ctx, &forwardrpc.MetricList{Metrics: ms})
if err != nil {
return fmt.Errorf("failed to send %d metrics over gRPC: %v",
len(ms), err)
}
_ = metrics.ReportBatch(s.opts.traceClient, ssf.RandomlySample(0.1,
ssf.Count("metrics_by_destination", float32(len(ms)),
map[string]string{"destination": dest, "protocol": "grpc"}),
))
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"forward",
"(",
"ctx",
"context",
".",
"Context",
",",
"dest",
"string",
",",
"ms",
"[",
"]",
"*",
"metricpb",
".",
"Metric",
")",
"(",
"err",
"error",
")",
"{",
"conn",
",",
"ok",
":=",
"s",
".",
"conns",
... | // forward sends a set of metrics to the destination address, and returns
// an error if necessary. | [
"forward",
"sends",
"a",
"set",
"of",
"metrics",
"to",
"the",
"destination",
"address",
"and",
"returns",
"an",
"error",
"if",
"necessary",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L285-L304 |
13,339 | stripe/veneur | proxysrv/server.go | reportStats | func (s *Server) reportStats() {
_ = metrics.ReportOne(s.opts.traceClient,
ssf.Gauge("proxy.active_goroutines", float32(atomic.LoadInt64(s.activeProxyHandlers)), globalProtocolTags))
} | go | func (s *Server) reportStats() {
_ = metrics.ReportOne(s.opts.traceClient,
ssf.Gauge("proxy.active_goroutines", float32(atomic.LoadInt64(s.activeProxyHandlers)), globalProtocolTags))
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"reportStats",
"(",
")",
"{",
"_",
"=",
"metrics",
".",
"ReportOne",
"(",
"s",
".",
"opts",
".",
"traceClient",
",",
"ssf",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float32",
"(",
"atomic",
".",
"LoadInt64",
"(",
... | // reportStats reports statistics about the server to the internal trace client | [
"reportStats",
"reports",
"statistics",
"about",
"the",
"server",
"to",
"the",
"internal",
"trace",
"client"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L307-L310 |
13,340 | stripe/veneur | proxysrv/server.go | Error | func (e forwardError) Error() string {
return fmt.Sprintf("%s (cause=%s, metrics=%d): %v", e.msg, e.cause,
e.numMetrics, e.err)
} | go | func (e forwardError) Error() string {
return fmt.Sprintf("%s (cause=%s, metrics=%d): %v", e.msg, e.cause,
e.numMetrics, e.err)
} | [
"func",
"(",
"e",
"forwardError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"msg",
",",
"e",
".",
"cause",
",",
"e",
".",
"numMetrics",
",",
"e",
".",
"err",
")",
"\n",
"}"
] | // Error returns a summary of the data in a forwardError. | [
"Error",
"returns",
"a",
"summary",
"of",
"the",
"data",
"in",
"a",
"forwardError",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L332-L335 |
13,341 | stripe/veneur | proxysrv/server.go | reportMetrics | func (e forwardError) reportMetrics(span *trace.Span) {
tags := map[string]string{
"cause": e.cause,
"protocol": "grpc",
}
span.Add(
ssf.Count("proxy.proxied_metrics_failed", float32(e.numMetrics), tags),
ssf.Count("proxy.forward_errors", 1, tags),
)
} | go | func (e forwardError) reportMetrics(span *trace.Span) {
tags := map[string]string{
"cause": e.cause,
"protocol": "grpc",
}
span.Add(
ssf.Count("proxy.proxied_metrics_failed", float32(e.numMetrics), tags),
ssf.Count("proxy.forward_errors", 1, tags),
)
} | [
"func",
"(",
"e",
"forwardError",
")",
"reportMetrics",
"(",
"span",
"*",
"trace",
".",
"Span",
")",
"{",
"tags",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"e",
".",
"cause",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
"\... | // reportMetrics adds various metrics to an input span. | [
"reportMetrics",
"adds",
"various",
"metrics",
"to",
"an",
"input",
"span",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L338-L347 |
13,342 | stripe/veneur | proxysrv/server.go | Error | func (errs forwardErrors) Error() string {
// Only print 10 errors
strsLen := len(errs)
if len(errs) > 10 {
strsLen = 10
}
// convert the errors into a slice of strings
strs := make([]string, strsLen)
for i, err := range errs[:len(strs)] {
strs[i] = err.Error()
}
// If there are errors that weren't printed, add a message to the end
str := strings.Join(strs, "\n * ")
if len(strs) < len(errs) {
str += fmt.Sprintf("\nand %d more...", len(errs)-len(strs))
}
return str
} | go | func (errs forwardErrors) Error() string {
// Only print 10 errors
strsLen := len(errs)
if len(errs) > 10 {
strsLen = 10
}
// convert the errors into a slice of strings
strs := make([]string, strsLen)
for i, err := range errs[:len(strs)] {
strs[i] = err.Error()
}
// If there are errors that weren't printed, add a message to the end
str := strings.Join(strs, "\n * ")
if len(strs) < len(errs) {
str += fmt.Sprintf("\nand %d more...", len(errs)-len(strs))
}
return str
} | [
"func",
"(",
"errs",
"forwardErrors",
")",
"Error",
"(",
")",
"string",
"{",
"// Only print 10 errors",
"strsLen",
":=",
"len",
"(",
"errs",
")",
"\n",
"if",
"len",
"(",
"errs",
")",
">",
"10",
"{",
"strsLen",
"=",
"10",
"\n",
"}",
"\n\n",
"// convert ... | // Error prints the first 10 errors. | [
"Error",
"prints",
"the",
"first",
"10",
"errors",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/proxysrv/server.go#L353-L373 |
13,343 | stripe/veneur | networking.go | StartStatsd | func StartStatsd(s *Server, a net.Addr, packetPool *sync.Pool) net.Addr {
switch addr := a.(type) {
case *net.UDPAddr:
return startStatsdUDP(s, addr, packetPool)
case *net.TCPAddr:
return startStatsdTCP(s, addr, packetPool)
case *net.UnixAddr:
_, b := startStatsdUnix(s, addr, packetPool)
return b
default:
panic(fmt.Sprintf("Can't listen on %v: only TCP, UDP and unixgram:// are supported", a))
}
} | go | func StartStatsd(s *Server, a net.Addr, packetPool *sync.Pool) net.Addr {
switch addr := a.(type) {
case *net.UDPAddr:
return startStatsdUDP(s, addr, packetPool)
case *net.TCPAddr:
return startStatsdTCP(s, addr, packetPool)
case *net.UnixAddr:
_, b := startStatsdUnix(s, addr, packetPool)
return b
default:
panic(fmt.Sprintf("Can't listen on %v: only TCP, UDP and unixgram:// are supported", a))
}
} | [
"func",
"StartStatsd",
"(",
"s",
"*",
"Server",
",",
"a",
"net",
".",
"Addr",
",",
"packetPool",
"*",
"sync",
".",
"Pool",
")",
"net",
".",
"Addr",
"{",
"switch",
"addr",
":=",
"a",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"UDPAddr",
... | // StartStatsd spawns a goroutine that listens for metrics in statsd
// format on the address a, and returns the concrete listening
// address. As this is a setup routine, if any error occurs, it
// panics. | [
"StartStatsd",
"spawns",
"a",
"goroutine",
"that",
"listens",
"for",
"metrics",
"in",
"statsd",
"format",
"on",
"the",
"address",
"a",
"and",
"returns",
"the",
"concrete",
"listening",
"address",
".",
"As",
"this",
"is",
"a",
"setup",
"routine",
"if",
"any",... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/networking.go#L18-L30 |
13,344 | stripe/veneur | networking.go | startProcessingOnUDP | func startProcessingOnUDP(s *Server, protocol string, addr *net.UDPAddr, pool *sync.Pool, proc udpProcessor) net.Addr {
reusePort := s.numReaders != 1
// If we're reusing the port, make sure we're listening on the
// exact same address always; this is mostly relevant for
// tests, where port is typically 0 and the initial ListenUDP
// call results in a contrete port.
if reusePort {
sock, err := NewSocket(addr, s.RcvbufBytes, reusePort)
if err != nil {
panic(fmt.Sprintf("couldn't listen on UDP socket %v: %v", addr, err))
}
defer sock.Close()
addr = sock.LocalAddr().(*net.UDPAddr)
}
addrChan := make(chan net.Addr, 1)
once := sync.Once{}
for i := 0; i < s.numReaders; i++ {
go func() {
defer func() {
ConsumePanic(s.Sentry, s.TraceClient, s.Hostname, recover())
}()
// each goroutine gets its own socket
// if the sockets support SO_REUSEPORT, then this will cause the
// kernel to distribute datagrams across them, for better read
// performance
sock, err := NewSocket(addr, s.RcvbufBytes, reusePort)
if err != nil {
// if any goroutine fails to create the socket, we can't really
// recover, so we just blow up
// this probably indicates a systemic issue, eg lack of
// SO_REUSEPORT support
panic(fmt.Sprintf("couldn't listen on UDP socket %v: %v", addr, err))
}
// Pass the address that we are listening on
// back to whoever spawned this goroutine so
// it can return that address.
once.Do(func() {
addrChan <- sock.LocalAddr()
log.WithFields(logrus.Fields{
"address": sock.LocalAddr(),
"protocol": protocol,
"listeners": s.numReaders,
}).Info("Listening on UDP address")
close(addrChan)
})
proc(sock, pool)
}()
}
return <-addrChan
} | go | func startProcessingOnUDP(s *Server, protocol string, addr *net.UDPAddr, pool *sync.Pool, proc udpProcessor) net.Addr {
reusePort := s.numReaders != 1
// If we're reusing the port, make sure we're listening on the
// exact same address always; this is mostly relevant for
// tests, where port is typically 0 and the initial ListenUDP
// call results in a contrete port.
if reusePort {
sock, err := NewSocket(addr, s.RcvbufBytes, reusePort)
if err != nil {
panic(fmt.Sprintf("couldn't listen on UDP socket %v: %v", addr, err))
}
defer sock.Close()
addr = sock.LocalAddr().(*net.UDPAddr)
}
addrChan := make(chan net.Addr, 1)
once := sync.Once{}
for i := 0; i < s.numReaders; i++ {
go func() {
defer func() {
ConsumePanic(s.Sentry, s.TraceClient, s.Hostname, recover())
}()
// each goroutine gets its own socket
// if the sockets support SO_REUSEPORT, then this will cause the
// kernel to distribute datagrams across them, for better read
// performance
sock, err := NewSocket(addr, s.RcvbufBytes, reusePort)
if err != nil {
// if any goroutine fails to create the socket, we can't really
// recover, so we just blow up
// this probably indicates a systemic issue, eg lack of
// SO_REUSEPORT support
panic(fmt.Sprintf("couldn't listen on UDP socket %v: %v", addr, err))
}
// Pass the address that we are listening on
// back to whoever spawned this goroutine so
// it can return that address.
once.Do(func() {
addrChan <- sock.LocalAddr()
log.WithFields(logrus.Fields{
"address": sock.LocalAddr(),
"protocol": protocol,
"listeners": s.numReaders,
}).Info("Listening on UDP address")
close(addrChan)
})
proc(sock, pool)
}()
}
return <-addrChan
} | [
"func",
"startProcessingOnUDP",
"(",
"s",
"*",
"Server",
",",
"protocol",
"string",
",",
"addr",
"*",
"net",
".",
"UDPAddr",
",",
"pool",
"*",
"sync",
".",
"Pool",
",",
"proc",
"udpProcessor",
")",
"net",
".",
"Addr",
"{",
"reusePort",
":=",
"s",
".",
... | // startProcessingOnUDP starts network num_readers listeners on the
// given address in one goroutine each, using the passed pool. When
// the listener is established, it starts the udpProcessor with the
// listener. | [
"startProcessingOnUDP",
"starts",
"network",
"num_readers",
"listeners",
"on",
"the",
"given",
"address",
"in",
"one",
"goroutine",
"each",
"using",
"the",
"passed",
"pool",
".",
"When",
"the",
"listener",
"is",
"established",
"it",
"starts",
"the",
"udpProcessor"... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/networking.go#L40-L90 |
13,345 | stripe/veneur | networking.go | startStatsdUnix | func startStatsdUnix(s *Server, addr *net.UnixAddr, packetPool *sync.Pool) (<-chan struct{}, net.Addr) {
done := make(chan struct{})
// ensure we are the only ones locking this socket:
lock := acquireLockForSocket(addr)
conn, err := net.ListenUnixgram(addr.Network(), addr)
if err != nil {
panic(fmt.Sprintf("Couldn't listen on UNIX socket %v: %v", addr, err))
}
// Make the socket connectable by everyone with access to the socket pathname:
err = os.Chmod(addr.String(), 0666)
if err != nil {
panic(fmt.Sprintf("Couldn't set permissions on %v: %v", addr, err))
}
go func() {
defer func() {
lock.Unlock()
close(done)
}()
for {
_, open := <-s.shutdown
// occurs when cleanly shutting down the server e.g. in tests; ignore errors
if !open {
conn.Close()
return
}
}
}()
for i := 0; i < s.numReaders; i++ {
go s.ReadStatsdDatagramSocket(conn, packetPool)
}
return done, addr
} | go | func startStatsdUnix(s *Server, addr *net.UnixAddr, packetPool *sync.Pool) (<-chan struct{}, net.Addr) {
done := make(chan struct{})
// ensure we are the only ones locking this socket:
lock := acquireLockForSocket(addr)
conn, err := net.ListenUnixgram(addr.Network(), addr)
if err != nil {
panic(fmt.Sprintf("Couldn't listen on UNIX socket %v: %v", addr, err))
}
// Make the socket connectable by everyone with access to the socket pathname:
err = os.Chmod(addr.String(), 0666)
if err != nil {
panic(fmt.Sprintf("Couldn't set permissions on %v: %v", addr, err))
}
go func() {
defer func() {
lock.Unlock()
close(done)
}()
for {
_, open := <-s.shutdown
// occurs when cleanly shutting down the server e.g. in tests; ignore errors
if !open {
conn.Close()
return
}
}
}()
for i := 0; i < s.numReaders; i++ {
go s.ReadStatsdDatagramSocket(conn, packetPool)
}
return done, addr
} | [
"func",
"startStatsdUnix",
"(",
"s",
"*",
"Server",
",",
"addr",
"*",
"net",
".",
"UnixAddr",
",",
"packetPool",
"*",
"sync",
".",
"Pool",
")",
"(",
"<-",
"chan",
"struct",
"{",
"}",
",",
"net",
".",
"Addr",
")",
"{",
"done",
":=",
"make",
"(",
"... | // startStatsdUnix starts listening for datagram statsd metric packets
// on a UNIX domain socket address. It does so until the
// server's shutdown socket is closed. startStatsdUnix returns a channel
// that is closed once the listening connection has terminated. | [
"startStatsdUnix",
"starts",
"listening",
"for",
"datagram",
"statsd",
"metric",
"packets",
"on",
"a",
"UNIX",
"domain",
"socket",
"address",
".",
"It",
"does",
"so",
"until",
"the",
"server",
"s",
"shutdown",
"socket",
"is",
"closed",
".",
"startStatsdUnix",
... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/networking.go#L143-L177 |
13,346 | stripe/veneur | networking.go | StartSSF | func StartSSF(s *Server, a net.Addr, tracePool *sync.Pool) net.Addr {
switch addr := a.(type) {
case *net.UDPAddr:
a = startSSFUDP(s, addr, tracePool)
case *net.UnixAddr:
_, a = startSSFUnix(s, addr)
default:
panic(fmt.Sprintf("Can't listen for SSF on %v: only udp:// & unix:// are supported", a))
}
log.WithFields(logrus.Fields{
"address": a.String(),
"network": a.Network(),
}).Info("Listening for SSF traces")
return a
} | go | func StartSSF(s *Server, a net.Addr, tracePool *sync.Pool) net.Addr {
switch addr := a.(type) {
case *net.UDPAddr:
a = startSSFUDP(s, addr, tracePool)
case *net.UnixAddr:
_, a = startSSFUnix(s, addr)
default:
panic(fmt.Sprintf("Can't listen for SSF on %v: only udp:// & unix:// are supported", a))
}
log.WithFields(logrus.Fields{
"address": a.String(),
"network": a.Network(),
}).Info("Listening for SSF traces")
return a
} | [
"func",
"StartSSF",
"(",
"s",
"*",
"Server",
",",
"a",
"net",
".",
"Addr",
",",
"tracePool",
"*",
"sync",
".",
"Pool",
")",
"net",
".",
"Addr",
"{",
"switch",
"addr",
":=",
"a",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"UDPAddr",
":... | // StartSSF starts listening for SSF on an address a, and returns the
// concrete address that the server is listening on. | [
"StartSSF",
"starts",
"listening",
"for",
"SSF",
"on",
"an",
"address",
"a",
"and",
"returns",
"the",
"concrete",
"address",
"that",
"the",
"server",
"is",
"listening",
"on",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/networking.go#L181-L195 |
13,347 | stripe/veneur | networking.go | startSSFUnix | func startSSFUnix(s *Server, addr *net.UnixAddr) (<-chan struct{}, net.Addr) {
done := make(chan struct{})
if addr.Network() != "unix" {
panic(fmt.Sprintf("Can't listen for SSF on %v: only udp:// and unix:// addresses are supported", addr))
}
// ensure we are the only ones locking this socket:
lock := acquireLockForSocket(addr)
listener, err := net.ListenUnix(addr.Network(), addr)
if err != nil {
panic(fmt.Sprintf("Couldn't listen on UNIX socket %v: %v", addr, err))
}
// Make the socket connectable by everyone with access to the socket pathname:
err = os.Chmod(addr.String(), 0666)
if err != nil {
panic(fmt.Sprintf("Couldn't set permissions on %v: %v", addr, err))
}
go func() {
conns := make(chan net.Conn)
go func() {
defer func() {
lock.Unlock()
close(done)
}()
for {
conn, err := listener.AcceptUnix()
if err != nil {
select {
case <-s.shutdown:
// occurs when cleanly shutting down the server e.g. in tests; ignore errors
log.WithError(err).Info("Ignoring Accept error while shutting down")
return
default:
log.WithError(err).Fatal("Unix accept failed")
}
}
conns <- conn
}
}()
for {
select {
case conn := <-conns:
go s.ReadSSFStreamSocket(conn)
case <-s.shutdown:
listener.Close()
return
}
}
}()
return done, listener.Addr()
} | go | func startSSFUnix(s *Server, addr *net.UnixAddr) (<-chan struct{}, net.Addr) {
done := make(chan struct{})
if addr.Network() != "unix" {
panic(fmt.Sprintf("Can't listen for SSF on %v: only udp:// and unix:// addresses are supported", addr))
}
// ensure we are the only ones locking this socket:
lock := acquireLockForSocket(addr)
listener, err := net.ListenUnix(addr.Network(), addr)
if err != nil {
panic(fmt.Sprintf("Couldn't listen on UNIX socket %v: %v", addr, err))
}
// Make the socket connectable by everyone with access to the socket pathname:
err = os.Chmod(addr.String(), 0666)
if err != nil {
panic(fmt.Sprintf("Couldn't set permissions on %v: %v", addr, err))
}
go func() {
conns := make(chan net.Conn)
go func() {
defer func() {
lock.Unlock()
close(done)
}()
for {
conn, err := listener.AcceptUnix()
if err != nil {
select {
case <-s.shutdown:
// occurs when cleanly shutting down the server e.g. in tests; ignore errors
log.WithError(err).Info("Ignoring Accept error while shutting down")
return
default:
log.WithError(err).Fatal("Unix accept failed")
}
}
conns <- conn
}
}()
for {
select {
case conn := <-conns:
go s.ReadSSFStreamSocket(conn)
case <-s.shutdown:
listener.Close()
return
}
}
}()
return done, listener.Addr()
} | [
"func",
"startSSFUnix",
"(",
"s",
"*",
"Server",
",",
"addr",
"*",
"net",
".",
"UnixAddr",
")",
"(",
"<-",
"chan",
"struct",
"{",
"}",
",",
"net",
".",
"Addr",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"if",
"a... | // startSSFUnix starts listening for connections that send framed SSF
// spans on a UNIX domain socket address. It does so until the
// server's shutdown socket is closed. startSSFUnix returns a channel
// that is closed once the listener has terminated. | [
"startSSFUnix",
"starts",
"listening",
"for",
"connections",
"that",
"send",
"framed",
"SSF",
"spans",
"on",
"a",
"UNIX",
"domain",
"socket",
"address",
".",
"It",
"does",
"so",
"until",
"the",
"server",
"s",
"shutdown",
"socket",
"is",
"closed",
".",
"start... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/networking.go#L205-L258 |
13,348 | stripe/veneur | networking.go | acquireLockForSocket | func acquireLockForSocket(addr *net.UnixAddr) *flock.Flock {
lockname := fmt.Sprintf("%s.lock", addr.String())
lock := flock.NewFlock(lockname)
locked, err := lock.TryLock()
if err != nil {
panic(fmt.Sprintf("Could not acquire the lock %q to listen on %v: %v", lockname, addr, err))
}
if !locked {
panic(fmt.Sprintf("Lock file %q for %v is in use by another process already", lockname, addr))
}
// We have the exclusive use of the socket, clear away any old sockets and listen:
_ = os.Remove(addr.String())
return lock
} | go | func acquireLockForSocket(addr *net.UnixAddr) *flock.Flock {
lockname := fmt.Sprintf("%s.lock", addr.String())
lock := flock.NewFlock(lockname)
locked, err := lock.TryLock()
if err != nil {
panic(fmt.Sprintf("Could not acquire the lock %q to listen on %v: %v", lockname, addr, err))
}
if !locked {
panic(fmt.Sprintf("Lock file %q for %v is in use by another process already", lockname, addr))
}
// We have the exclusive use of the socket, clear away any old sockets and listen:
_ = os.Remove(addr.String())
return lock
} | [
"func",
"acquireLockForSocket",
"(",
"addr",
"*",
"net",
".",
"UnixAddr",
")",
"*",
"flock",
".",
"Flock",
"{",
"lockname",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"addr",
".",
"String",
"(",
")",
")",
"\n",
"lock",
":=",
"flock",
".",
"... | // Acquires exclusive use lock for a given socket file and returns the lock
// Panic's if unable to acquire lock | [
"Acquires",
"exclusive",
"use",
"lock",
"for",
"a",
"given",
"socket",
"file",
"and",
"returns",
"the",
"lock",
"Panic",
"s",
"if",
"unable",
"to",
"acquire",
"lock"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/networking.go#L262-L275 |
13,349 | stripe/veneur | trace/opentracing.go | Clone | func (t textMapReaderWriter) Clone() textMapReaderWriter {
clone := textMapReaderWriter(map[string]string{})
t.CloneTo(clone)
return clone
} | go | func (t textMapReaderWriter) Clone() textMapReaderWriter {
clone := textMapReaderWriter(map[string]string{})
t.CloneTo(clone)
return clone
} | [
"func",
"(",
"t",
"textMapReaderWriter",
")",
"Clone",
"(",
")",
"textMapReaderWriter",
"{",
"clone",
":=",
"textMapReaderWriter",
"(",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
")",
"\n",
"t",
".",
"CloneTo",
"(",
"clone",
")",
"\n",
"return",
"clo... | // Clone creates a new textMapReaderWriter with the same
// key-value pairs | [
"Clone",
"creates",
"a",
"new",
"textMapReaderWriter",
"with",
"the",
"same",
"key",
"-",
"value",
"pairs"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L114-L118 |
13,350 | stripe/veneur | trace/opentracing.go | CloneTo | func (t textMapReaderWriter) CloneTo(w opentracing.TextMapWriter) {
t.ForeachKey(func(k, v string) error {
w.Set(k, v)
return nil
})
} | go | func (t textMapReaderWriter) CloneTo(w opentracing.TextMapWriter) {
t.ForeachKey(func(k, v string) error {
w.Set(k, v)
return nil
})
} | [
"func",
"(",
"t",
"textMapReaderWriter",
")",
"CloneTo",
"(",
"w",
"opentracing",
".",
"TextMapWriter",
")",
"{",
"t",
".",
"ForeachKey",
"(",
"func",
"(",
"k",
",",
"v",
"string",
")",
"error",
"{",
"w",
".",
"Set",
"(",
"k",
",",
"v",
")",
"\n",
... | // CloneTo clones the textMapReaderWriter into the provided TextMapWriter | [
"CloneTo",
"clones",
"the",
"textMapReaderWriter",
"into",
"the",
"provided",
"TextMapWriter"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L121-L126 |
13,351 | stripe/veneur | trace/opentracing.go | parseBaggageInt64 | func (c *spanContext) parseBaggageInt64(key string) int64 {
var val int64
c.ForeachBaggageItem(func(k, v string) bool {
if strings.ToLower(k) == strings.ToLower(key) {
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
// TODO handle err
return true
}
val = i
return false
}
return true
})
return val
} | go | func (c *spanContext) parseBaggageInt64(key string) int64 {
var val int64
c.ForeachBaggageItem(func(k, v string) bool {
if strings.ToLower(k) == strings.ToLower(key) {
i, err := strconv.ParseInt(v, 10, 64)
if err != nil {
// TODO handle err
return true
}
val = i
return false
}
return true
})
return val
} | [
"func",
"(",
"c",
"*",
"spanContext",
")",
"parseBaggageInt64",
"(",
"key",
"string",
")",
"int64",
"{",
"var",
"val",
"int64",
"\n",
"c",
".",
"ForeachBaggageItem",
"(",
"func",
"(",
"k",
",",
"v",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"... | // parseBaggageInt64 searches for the target key in the BaggageItems
// and parses it as an int64. It treats keys as case-insensitive. | [
"parseBaggageInt64",
"searches",
"for",
"the",
"target",
"key",
"in",
"the",
"BaggageItems",
"and",
"parses",
"it",
"as",
"an",
"int64",
".",
"It",
"treats",
"keys",
"as",
"case",
"-",
"insensitive",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L171-L186 |
13,352 | stripe/veneur | trace/opentracing.go | Resource | func (c *spanContext) Resource() string {
var resource string
c.ForeachBaggageItem(func(k, v string) bool {
if strings.ToLower(k) == ResourceKey {
resource = v
return false
}
return true
})
return resource
} | go | func (c *spanContext) Resource() string {
var resource string
c.ForeachBaggageItem(func(k, v string) bool {
if strings.ToLower(k) == ResourceKey {
resource = v
return false
}
return true
})
return resource
} | [
"func",
"(",
"c",
"*",
"spanContext",
")",
"Resource",
"(",
")",
"string",
"{",
"var",
"resource",
"string",
"\n",
"c",
".",
"ForeachBaggageItem",
"(",
"func",
"(",
"k",
",",
"v",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"k",... | // Resource returns the resource assocaited with the spanContext | [
"Resource",
"returns",
"the",
"resource",
"assocaited",
"with",
"the",
"spanContext"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L189-L199 |
13,353 | stripe/veneur | trace/opentracing.go | ClientFinish | func (s *Span) ClientFinish(cl *Client) {
// This should never happen,
// but calling defer span.Finish() should always be
// a safe operation.
if s == nil {
return
}
s.ClientFinishWithOptions(cl, opentracing.FinishOptions{
FinishTime: time.Now(),
LogRecords: nil,
BulkLogData: nil,
})
} | go | func (s *Span) ClientFinish(cl *Client) {
// This should never happen,
// but calling defer span.Finish() should always be
// a safe operation.
if s == nil {
return
}
s.ClientFinishWithOptions(cl, opentracing.FinishOptions{
FinishTime: time.Now(),
LogRecords: nil,
BulkLogData: nil,
})
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"ClientFinish",
"(",
"cl",
"*",
"Client",
")",
"{",
"// This should never happen,",
"// but calling defer span.Finish() should always be",
"// a safe operation.",
"if",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"s",
".",... | // ClientFinish ends a trace and records it with the given Client. | [
"ClientFinish",
"ends",
"a",
"trace",
"and",
"records",
"it",
"with",
"the",
"given",
"Client",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L219-L231 |
13,354 | stripe/veneur | trace/opentracing.go | FinishWithOptions | func (s *Span) FinishWithOptions(opts opentracing.FinishOptions) {
s.ClientFinishWithOptions(DefaultClient, opts)
} | go | func (s *Span) FinishWithOptions(opts opentracing.FinishOptions) {
s.ClientFinishWithOptions(DefaultClient, opts)
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"FinishWithOptions",
"(",
"opts",
"opentracing",
".",
"FinishOptions",
")",
"{",
"s",
".",
"ClientFinishWithOptions",
"(",
"DefaultClient",
",",
"opts",
")",
"\n",
"}"
] | // FinishWithOptions finishes the span, but with explicit
// control over timestamps and log data.
// The BulkLogData field is deprecated and ignored. | [
"FinishWithOptions",
"finishes",
"the",
"span",
"but",
"with",
"explicit",
"control",
"over",
"timestamps",
"and",
"log",
"data",
".",
"The",
"BulkLogData",
"field",
"is",
"deprecated",
"and",
"ignored",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L236-L238 |
13,355 | stripe/veneur | trace/opentracing.go | ClientFinishWithOptions | func (s *Span) ClientFinishWithOptions(cl *Client, opts opentracing.FinishOptions) {
// This should never happen,
// but calling defer span.FinishWithOptions() should always be
// a safe operation.
if s == nil {
return
}
// TODO remove the name tag from the slice of tags
s.recordErr = s.ClientRecord(cl, s.Name, s.Tags)
} | go | func (s *Span) ClientFinishWithOptions(cl *Client, opts opentracing.FinishOptions) {
// This should never happen,
// but calling defer span.FinishWithOptions() should always be
// a safe operation.
if s == nil {
return
}
// TODO remove the name tag from the slice of tags
s.recordErr = s.ClientRecord(cl, s.Name, s.Tags)
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"ClientFinishWithOptions",
"(",
"cl",
"*",
"Client",
",",
"opts",
"opentracing",
".",
"FinishOptions",
")",
"{",
"// This should never happen,",
"// but calling defer span.FinishWithOptions() should always be",
"// a safe operation.",
"if... | // ClientFinishWithOptions finishes the span and records it on the
// given client, but with explicit control over timestamps and log
// data. The BulkLogData field is deprecated and ignored. | [
"ClientFinishWithOptions",
"finishes",
"the",
"span",
"and",
"records",
"it",
"on",
"the",
"given",
"client",
"but",
"with",
"explicit",
"control",
"over",
"timestamps",
"and",
"log",
"data",
".",
"The",
"BulkLogData",
"field",
"is",
"deprecated",
"and",
"ignore... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L243-L254 |
13,356 | stripe/veneur | trace/opentracing.go | SetOperationName | func (s *Span) SetOperationName(name string) opentracing.Span {
s.Trace.Resource = name
return s
} | go | func (s *Span) SetOperationName(name string) opentracing.Span {
s.Trace.Resource = name
return s
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"SetOperationName",
"(",
"name",
"string",
")",
"opentracing",
".",
"Span",
"{",
"s",
".",
"Trace",
".",
"Resource",
"=",
"name",
"\n",
"return",
"s",
"\n",
"}"
] | // SetOperationName sets the name of the operation being performed
// in this span. | [
"SetOperationName",
"sets",
"the",
"name",
"of",
"the",
"operation",
"being",
"performed",
"in",
"this",
"span",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L278-L281 |
13,357 | stripe/veneur | trace/opentracing.go | SetTag | func (s *Span) SetTag(key string, value interface{}) opentracing.Span {
if s.Tags == nil {
s.Tags = map[string]string{}
}
var val string
// TODO mutex
switch v := value.(type) {
case string:
val = v
case fmt.Stringer:
val = v.String()
default:
// TODO maybe just ban non-strings?
val = fmt.Sprintf("%#v", value)
}
s.Tags[key] = val
return s
} | go | func (s *Span) SetTag(key string, value interface{}) opentracing.Span {
if s.Tags == nil {
s.Tags = map[string]string{}
}
var val string
// TODO mutex
switch v := value.(type) {
case string:
val = v
case fmt.Stringer:
val = v.String()
default:
// TODO maybe just ban non-strings?
val = fmt.Sprintf("%#v", value)
}
s.Tags[key] = val
return s
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"SetTag",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"opentracing",
".",
"Span",
"{",
"if",
"s",
".",
"Tags",
"==",
"nil",
"{",
"s",
".",
"Tags",
"=",
"map",
"[",
"string",
"]",
"string",
... | // SetTag sets the tags on the underlying span | [
"SetTag",
"sets",
"the",
"tags",
"on",
"the",
"underlying",
"span"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L284-L302 |
13,358 | stripe/veneur | trace/opentracing.go | Attach | func (s *Span) Attach(ctx context.Context) context.Context {
return opentracing.ContextWithSpan(ctx, s)
} | go | func (s *Span) Attach(ctx context.Context) context.Context {
return opentracing.ContextWithSpan(ctx, s)
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"Attach",
"(",
"ctx",
"context",
".",
"Context",
")",
"context",
".",
"Context",
"{",
"return",
"opentracing",
".",
"ContextWithSpan",
"(",
"ctx",
",",
"s",
")",
"\n",
"}"
] | // Attach attaches the span to the context.
// It delegates to opentracing.ContextWithSpan | [
"Attach",
"attaches",
"the",
"span",
"to",
"the",
"context",
".",
"It",
"delegates",
"to",
"opentracing",
".",
"ContextWithSpan"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L306-L308 |
13,359 | stripe/veneur | trace/opentracing.go | LogFields | func (s *Span) LogFields(fields ...opentracinglog.Field) {
// TODO mutex this
s.logLines = append(s.logLines, fields...)
} | go | func (s *Span) LogFields(fields ...opentracinglog.Field) {
// TODO mutex this
s.logLines = append(s.logLines, fields...)
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"LogFields",
"(",
"fields",
"...",
"opentracinglog",
".",
"Field",
")",
"{",
"// TODO mutex this",
"s",
".",
"logLines",
"=",
"append",
"(",
"s",
".",
"logLines",
",",
"fields",
"...",
")",
"\n",
"}"
] | // LogFields sets log fields on the underlying span.
// Currently these are ignored, but they can be fun to set anyway! | [
"LogFields",
"sets",
"log",
"fields",
"on",
"the",
"underlying",
"span",
".",
"Currently",
"these",
"are",
"ignored",
"but",
"they",
"can",
"be",
"fun",
"to",
"set",
"anyway!"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L312-L315 |
13,360 | stripe/veneur | trace/opentracing.go | SetBaggageItem | func (s *Span) SetBaggageItem(restrictedKey, value string) opentracing.Span {
s.contextAsParent().baggageItems[restrictedKey] = value
return s
} | go | func (s *Span) SetBaggageItem(restrictedKey, value string) opentracing.Span {
s.contextAsParent().baggageItems[restrictedKey] = value
return s
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"SetBaggageItem",
"(",
"restrictedKey",
",",
"value",
"string",
")",
"opentracing",
".",
"Span",
"{",
"s",
".",
"contextAsParent",
"(",
")",
".",
"baggageItems",
"[",
"restrictedKey",
"]",
"=",
"value",
"\n",
"return",
... | // SetBaggageItem sets the value of a baggage in the span. | [
"SetBaggageItem",
"sets",
"the",
"value",
"of",
"a",
"baggage",
"in",
"the",
"span",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L324-L327 |
13,361 | stripe/veneur | trace/opentracing.go | BaggageItem | func (s *Span) BaggageItem(restrictedKey string) string {
return s.contextAsParent().baggageItems[restrictedKey]
} | go | func (s *Span) BaggageItem(restrictedKey string) string {
return s.contextAsParent().baggageItems[restrictedKey]
} | [
"func",
"(",
"s",
"*",
"Span",
")",
"BaggageItem",
"(",
"restrictedKey",
"string",
")",
"string",
"{",
"return",
"s",
".",
"contextAsParent",
"(",
")",
".",
"baggageItems",
"[",
"restrictedKey",
"]",
"\n",
"}"
] | // BaggageItem fetches the value of a baggage item in the span. | [
"BaggageItem",
"fetches",
"the",
"value",
"of",
"a",
"baggage",
"item",
"in",
"the",
"span",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L330-L332 |
13,362 | stripe/veneur | trace/opentracing.go | customSpanStart | func customSpanStart(t time.Time) opentracing.StartSpanOption {
return &spanOption{
apply: func(sso *opentracing.StartSpanOptions) {
sso.StartTime = t
},
}
} | go | func customSpanStart(t time.Time) opentracing.StartSpanOption {
return &spanOption{
apply: func(sso *opentracing.StartSpanOptions) {
sso.StartTime = t
},
}
} | [
"func",
"customSpanStart",
"(",
"t",
"time",
".",
"Time",
")",
"opentracing",
".",
"StartSpanOption",
"{",
"return",
"&",
"spanOption",
"{",
"apply",
":",
"func",
"(",
"sso",
"*",
"opentracing",
".",
"StartSpanOptions",
")",
"{",
"sso",
".",
"StartTime",
"... | // customSpanStart returns a StartSpanOption that can be passed to
// StartSpan, and which will set the created Span's StartTime to the specified
// value. | [
"customSpanStart",
"returns",
"a",
"StartSpanOption",
"that",
"can",
"be",
"passed",
"to",
"StartSpan",
"and",
"which",
"will",
"set",
"the",
"created",
"Span",
"s",
"StartTime",
"to",
"the",
"specified",
"value",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L369-L375 |
13,363 | stripe/veneur | trace/opentracing.go | InjectRequest | func (tracer Tracer) InjectRequest(t *Trace, req *http.Request) error {
return tracer.InjectHeader(t, req.Header)
} | go | func (tracer Tracer) InjectRequest(t *Trace, req *http.Request) error {
return tracer.InjectHeader(t, req.Header)
} | [
"func",
"(",
"tracer",
"Tracer",
")",
"InjectRequest",
"(",
"t",
"*",
"Trace",
",",
"req",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"return",
"tracer",
".",
"InjectHeader",
"(",
"t",
",",
"req",
".",
"Header",
")",
"\n",
"}"
] | // InjectRequest injects a trace into an HTTP request header.
// It is a convenience function for Inject. | [
"InjectRequest",
"injects",
"a",
"trace",
"into",
"an",
"HTTP",
"request",
"header",
".",
"It",
"is",
"a",
"convenience",
"function",
"for",
"Inject",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L486-L488 |
13,364 | stripe/veneur | trace/opentracing.go | InjectHeader | func (tracer Tracer) InjectHeader(t *Trace, h http.Header) error {
carrier := opentracing.HTTPHeadersCarrier(h)
return tracer.Inject(t.context(), opentracing.HTTPHeaders, carrier)
} | go | func (tracer Tracer) InjectHeader(t *Trace, h http.Header) error {
carrier := opentracing.HTTPHeadersCarrier(h)
return tracer.Inject(t.context(), opentracing.HTTPHeaders, carrier)
} | [
"func",
"(",
"tracer",
"Tracer",
")",
"InjectHeader",
"(",
"t",
"*",
"Trace",
",",
"h",
"http",
".",
"Header",
")",
"error",
"{",
"carrier",
":=",
"opentracing",
".",
"HTTPHeadersCarrier",
"(",
"h",
")",
"\n",
"return",
"tracer",
".",
"Inject",
"(",
"t... | // InjectHeader injects a trace into an HTTP header.
// It is a convenience function for Inject. | [
"InjectHeader",
"injects",
"a",
"trace",
"into",
"an",
"HTTP",
"header",
".",
"It",
"is",
"a",
"convenience",
"function",
"for",
"Inject",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L492-L495 |
13,365 | stripe/veneur | trace/opentracing.go | ExtractRequestChild | func (tracer Tracer) ExtractRequestChild(resource string, req *http.Request, name string) (*Span, error) {
carrier := opentracing.HTTPHeadersCarrier(req.Header)
parentSpan, err := tracer.Extract(opentracing.HTTPHeaders, carrier)
if err != nil {
return nil, err
}
parent := parentSpan.(*spanContext)
t := StartChildSpan(&Trace{
SpanID: parent.SpanID(),
TraceID: parent.TraceID(),
ParentID: parent.ParentID(),
Resource: resource,
})
t.Name = name
return &Span{
tracer: tracer,
Trace: t,
}, nil
} | go | func (tracer Tracer) ExtractRequestChild(resource string, req *http.Request, name string) (*Span, error) {
carrier := opentracing.HTTPHeadersCarrier(req.Header)
parentSpan, err := tracer.Extract(opentracing.HTTPHeaders, carrier)
if err != nil {
return nil, err
}
parent := parentSpan.(*spanContext)
t := StartChildSpan(&Trace{
SpanID: parent.SpanID(),
TraceID: parent.TraceID(),
ParentID: parent.ParentID(),
Resource: resource,
})
t.Name = name
return &Span{
tracer: tracer,
Trace: t,
}, nil
} | [
"func",
"(",
"tracer",
"Tracer",
")",
"ExtractRequestChild",
"(",
"resource",
"string",
",",
"req",
"*",
"http",
".",
"Request",
",",
"name",
"string",
")",
"(",
"*",
"Span",
",",
"error",
")",
"{",
"carrier",
":=",
"opentracing",
".",
"HTTPHeadersCarrier"... | // ExtractRequestChild extracts a span from an HTTP request
// and creates and returns a new child of that span | [
"ExtractRequestChild",
"extracts",
"a",
"span",
"from",
"an",
"HTTP",
"request",
"and",
"creates",
"and",
"returns",
"a",
"new",
"child",
"of",
"that",
"span"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/opentracing.go#L499-L520 |
13,366 | stripe/veneur | plugins/s3/s3.go | EncodeInterMetricsCSV | func EncodeInterMetricsCSV(metrics []samplers.InterMetric, delimiter rune, includeHeaders bool, hostname string, interval int) (io.ReadSeeker, error) {
b := &bytes.Buffer{}
gzw := gzip.NewWriter(b)
w := csv.NewWriter(gzw)
w.Comma = delimiter
if includeHeaders {
// Write the headers first
headers := [...]string{
// the order here doesn't actually matter
// as long as the keys are right
TsvName: TsvName.String(),
TsvTags: TsvTags.String(),
TsvMetricType: TsvMetricType.String(),
TsvInterval: TsvInterval.String(),
TsvVeneurHostname: TsvVeneurHostname.String(),
TsvValue: TsvValue.String(),
TsvTimestamp: TsvTimestamp.String(),
TsvPartition: TsvPartition.String(),
}
w.Write(headers[:])
}
// TODO avoid edge case at midnight
partitionDate := time.Now()
for _, metric := range metrics {
EncodeInterMetricCSV(metric, w, &partitionDate, hostname, interval)
}
w.Flush()
gzw.Close()
return bytes.NewReader(b.Bytes()), w.Error()
} | go | func EncodeInterMetricsCSV(metrics []samplers.InterMetric, delimiter rune, includeHeaders bool, hostname string, interval int) (io.ReadSeeker, error) {
b := &bytes.Buffer{}
gzw := gzip.NewWriter(b)
w := csv.NewWriter(gzw)
w.Comma = delimiter
if includeHeaders {
// Write the headers first
headers := [...]string{
// the order here doesn't actually matter
// as long as the keys are right
TsvName: TsvName.String(),
TsvTags: TsvTags.String(),
TsvMetricType: TsvMetricType.String(),
TsvInterval: TsvInterval.String(),
TsvVeneurHostname: TsvVeneurHostname.String(),
TsvValue: TsvValue.String(),
TsvTimestamp: TsvTimestamp.String(),
TsvPartition: TsvPartition.String(),
}
w.Write(headers[:])
}
// TODO avoid edge case at midnight
partitionDate := time.Now()
for _, metric := range metrics {
EncodeInterMetricCSV(metric, w, &partitionDate, hostname, interval)
}
w.Flush()
gzw.Close()
return bytes.NewReader(b.Bytes()), w.Error()
} | [
"func",
"EncodeInterMetricsCSV",
"(",
"metrics",
"[",
"]",
"samplers",
".",
"InterMetric",
",",
"delimiter",
"rune",
",",
"includeHeaders",
"bool",
",",
"hostname",
"string",
",",
"interval",
"int",
")",
"(",
"io",
".",
"ReadSeeker",
",",
"error",
")",
"{",
... | // EncodeInterMetricsCSV returns a reader containing the gzipped CSV representation of the
// InterMetric data, one row per InterMetric.
// the AWS sdk requires seekable input, so we return a ReadSeeker here | [
"EncodeInterMetricsCSV",
"returns",
"a",
"reader",
"containing",
"the",
"gzipped",
"CSV",
"representation",
"of",
"the",
"InterMetric",
"data",
"one",
"row",
"per",
"InterMetric",
".",
"the",
"AWS",
"sdk",
"requires",
"seekable",
"input",
"so",
"we",
"return",
"... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/plugins/s3/s3.go#L102-L135 |
13,367 | stripe/veneur | samplers/split_bytes.go | NewSplitBytes | func NewSplitBytes(buf []byte, delim byte) *SplitBytes {
return &SplitBytes{
buf: buf,
delim: delim,
}
} | go | func NewSplitBytes(buf []byte, delim byte) *SplitBytes {
return &SplitBytes{
buf: buf,
delim: delim,
}
} | [
"func",
"NewSplitBytes",
"(",
"buf",
"[",
"]",
"byte",
",",
"delim",
"byte",
")",
"*",
"SplitBytes",
"{",
"return",
"&",
"SplitBytes",
"{",
"buf",
":",
"buf",
",",
"delim",
":",
"delim",
",",
"}",
"\n",
"}"
] | // NewSplitBytes initializes a SplitBytes struct with the provided buffer and delimiter. | [
"NewSplitBytes",
"initializes",
"a",
"SplitBytes",
"struct",
"with",
"the",
"provided",
"buffer",
"and",
"delimiter",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/split_bytes.go#L24-L29 |
13,368 | stripe/veneur | samplers/split_bytes.go | Next | func (sb *SplitBytes) Next() bool {
if sb.lastChunk {
// we do not check the length here, this ensures that we return the
// last chunk in the sequence (even if it's empty)
return false
}
next := bytes.IndexByte(sb.buf, sb.delim)
if next == -1 {
// no newline, consume the entire buffer
sb.currentChunk = sb.buf
sb.buf = nil
sb.lastChunk = true
} else {
sb.currentChunk = sb.buf[:next]
sb.buf = sb.buf[next+1:]
}
return true
} | go | func (sb *SplitBytes) Next() bool {
if sb.lastChunk {
// we do not check the length here, this ensures that we return the
// last chunk in the sequence (even if it's empty)
return false
}
next := bytes.IndexByte(sb.buf, sb.delim)
if next == -1 {
// no newline, consume the entire buffer
sb.currentChunk = sb.buf
sb.buf = nil
sb.lastChunk = true
} else {
sb.currentChunk = sb.buf[:next]
sb.buf = sb.buf[next+1:]
}
return true
} | [
"func",
"(",
"sb",
"*",
"SplitBytes",
")",
"Next",
"(",
")",
"bool",
"{",
"if",
"sb",
".",
"lastChunk",
"{",
"// we do not check the length here, this ensures that we return the",
"// last chunk in the sequence (even if it's empty)",
"return",
"false",
"\n",
"}",
"\n\n",
... | // Next advances SplitBytes to the next chunk, returning true if a new chunk
// actually exists and false otherwise. | [
"Next",
"advances",
"SplitBytes",
"to",
"the",
"next",
"chunk",
"returning",
"true",
"if",
"a",
"new",
"chunk",
"actually",
"exists",
"and",
"false",
"otherwise",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/samplers/split_bytes.go#L33-L51 |
13,369 | stripe/veneur | sinks/grpsink/grpsink.go | Start | func (gs *GRPCSpanSink) Start(cl *trace.Client) error {
gs.traceClient = cl
// Run a background goroutine to do a little bit of connection state
// tracking.
go func() {
for {
// This call will block on a channel receive until the gRPC connection
// state changes. When it does, flip the marker over to allow another
// error to be logged from Ingest().
gs.grpcConn.WaitForStateChange(ocontext.Background(), gs.grpcConn.GetState())
atomic.StoreUint32(&gs.loggedSinceTransition, 0)
}
}()
return nil
} | go | func (gs *GRPCSpanSink) Start(cl *trace.Client) error {
gs.traceClient = cl
// Run a background goroutine to do a little bit of connection state
// tracking.
go func() {
for {
// This call will block on a channel receive until the gRPC connection
// state changes. When it does, flip the marker over to allow another
// error to be logged from Ingest().
gs.grpcConn.WaitForStateChange(ocontext.Background(), gs.grpcConn.GetState())
atomic.StoreUint32(&gs.loggedSinceTransition, 0)
}
}()
return nil
} | [
"func",
"(",
"gs",
"*",
"GRPCSpanSink",
")",
"Start",
"(",
"cl",
"*",
"trace",
".",
"Client",
")",
"error",
"{",
"gs",
".",
"traceClient",
"=",
"cl",
"\n\n",
"// Run a background goroutine to do a little bit of connection state",
"// tracking.",
"go",
"func",
"(",... | // Start performs final preparations on the sink before it is
// ready to begin ingesting spans. | [
"Start",
"performs",
"final",
"preparations",
"on",
"the",
"sink",
"before",
"it",
"is",
"ready",
"to",
"begin",
"ingesting",
"spans",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/grpsink/grpsink.go#L77-L92 |
13,370 | stripe/veneur | sinks/grpsink/grpsink.go | Ingest | func (gs *GRPCSpanSink) Ingest(ssfSpan *ssf.SSFSpan) error {
if err := protocol.ValidateTrace(ssfSpan); err != nil {
return err
}
ctx := metadata.AppendToOutgoingContext(ocontext.Background(), "x-veneur-trace-id", strconv.FormatInt(ssfSpan.TraceId, 16))
_, err := gs.ssc.SendSpan(ctx, ssfSpan)
if err != nil {
atomic.AddUint32(&gs.dropCount, 1)
// gRPC guarantees that an error returned from an RPC call will be of
// type status.Status. In the unexpected event that they're not, this
// call creates a dummy type, so there's no risk of panic.
serr := status.Convert(err)
state := gs.grpcConn.GetState()
// Log all errors that occur in Ready state - that's weird. Otherwise,
// Log only one error per underlying connection state transition. This
// should be a reasonable heuristic to get an indicator that problems
// are occurring, without resulting in massive log spew while
// connections are under duress.
if state == connectivity.Ready || atomic.CompareAndSwapUint32(&gs.loggedSinceTransition, 0, 1) {
gs.log.WithFields(logrus.Fields{
logrus.ErrorKey: err,
"target": gs.target,
"name": gs.name,
"chanstate": state.String(),
"code": serr.Code(),
"details": serr.Details(),
"message": serr.Message(),
}).Error("Error sending span to gRPC sink target")
}
} else {
atomic.AddUint32(&gs.sentCount, 1)
}
return err
} | go | func (gs *GRPCSpanSink) Ingest(ssfSpan *ssf.SSFSpan) error {
if err := protocol.ValidateTrace(ssfSpan); err != nil {
return err
}
ctx := metadata.AppendToOutgoingContext(ocontext.Background(), "x-veneur-trace-id", strconv.FormatInt(ssfSpan.TraceId, 16))
_, err := gs.ssc.SendSpan(ctx, ssfSpan)
if err != nil {
atomic.AddUint32(&gs.dropCount, 1)
// gRPC guarantees that an error returned from an RPC call will be of
// type status.Status. In the unexpected event that they're not, this
// call creates a dummy type, so there's no risk of panic.
serr := status.Convert(err)
state := gs.grpcConn.GetState()
// Log all errors that occur in Ready state - that's weird. Otherwise,
// Log only one error per underlying connection state transition. This
// should be a reasonable heuristic to get an indicator that problems
// are occurring, without resulting in massive log spew while
// connections are under duress.
if state == connectivity.Ready || atomic.CompareAndSwapUint32(&gs.loggedSinceTransition, 0, 1) {
gs.log.WithFields(logrus.Fields{
logrus.ErrorKey: err,
"target": gs.target,
"name": gs.name,
"chanstate": state.String(),
"code": serr.Code(),
"details": serr.Details(),
"message": serr.Message(),
}).Error("Error sending span to gRPC sink target")
}
} else {
atomic.AddUint32(&gs.sentCount, 1)
}
return err
} | [
"func",
"(",
"gs",
"*",
"GRPCSpanSink",
")",
"Ingest",
"(",
"ssfSpan",
"*",
"ssf",
".",
"SSFSpan",
")",
"error",
"{",
"if",
"err",
":=",
"protocol",
".",
"ValidateTrace",
"(",
"ssfSpan",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
... | // Ingest takes in a span and streams it over gRPC to the connected server. | [
"Ingest",
"takes",
"in",
"a",
"span",
"and",
"streams",
"it",
"over",
"gRPC",
"to",
"the",
"connected",
"server",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/grpsink/grpsink.go#L101-L139 |
13,371 | stripe/veneur | sinks/splunk/protocol.go | newRequest | func (c *hecClient) newRequest() *hecRequest {
req := &hecRequest{url: c.url(c.idGen.String()), authHeader: c.authHeader()}
req.r, req.w = io.Pipe()
return req
} | go | func (c *hecClient) newRequest() *hecRequest {
req := &hecRequest{url: c.url(c.idGen.String()), authHeader: c.authHeader()}
req.r, req.w = io.Pipe()
return req
} | [
"func",
"(",
"c",
"*",
"hecClient",
")",
"newRequest",
"(",
")",
"*",
"hecRequest",
"{",
"req",
":=",
"&",
"hecRequest",
"{",
"url",
":",
"c",
".",
"url",
"(",
"c",
".",
"idGen",
".",
"String",
"(",
")",
")",
",",
"authHeader",
":",
"c",
".",
"... | // newRequest creates a new streaming HEC raw request and returns the
// writer to it. The request is submitted when the writer is closed. | [
"newRequest",
"creates",
"a",
"new",
"streaming",
"HEC",
"raw",
"request",
"and",
"returns",
"the",
"writer",
"to",
"it",
".",
"The",
"request",
"is",
"submitted",
"when",
"the",
"writer",
"is",
"closed",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/splunk/protocol.go#L45-L49 |
13,372 | stripe/veneur | http/http.go | newHTTPClientTracer | func newHTTPClientTracer(ctx context.Context, tc *trace.Client, prefix string) *httpClientTracer {
span, _ := trace.StartSpanFromContext(ctx, "http.start")
return &httpClientTracer{
prefix: prefix,
traceClient: tc,
mutex: &sync.Mutex{},
ctx: ctx,
currentSpan: span,
}
} | go | func newHTTPClientTracer(ctx context.Context, tc *trace.Client, prefix string) *httpClientTracer {
span, _ := trace.StartSpanFromContext(ctx, "http.start")
return &httpClientTracer{
prefix: prefix,
traceClient: tc,
mutex: &sync.Mutex{},
ctx: ctx,
currentSpan: span,
}
} | [
"func",
"newHTTPClientTracer",
"(",
"ctx",
"context",
".",
"Context",
",",
"tc",
"*",
"trace",
".",
"Client",
",",
"prefix",
"string",
")",
"*",
"httpClientTracer",
"{",
"span",
",",
"_",
":=",
"trace",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"\"",
... | // newHTTPClientTracer makes a new HTTPClientTracer with new span created from
// the context. | [
"newHTTPClientTracer",
"makes",
"a",
"new",
"HTTPClientTracer",
"with",
"new",
"span",
"created",
"from",
"the",
"context",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/http/http.go#L36-L45 |
13,373 | stripe/veneur | http/http.go | getClientTrace | func (hct *httpClientTracer) getClientTrace() *httptrace.ClientTrace {
return &httptrace.ClientTrace{
GotConn: hct.gotConn,
DNSStart: hct.dnsStart,
GotFirstResponseByte: hct.gotFirstResponseByte,
ConnectStart: hct.connectStart,
WroteHeaders: hct.wroteHeaders,
WroteRequest: hct.wroteRequest,
}
} | go | func (hct *httpClientTracer) getClientTrace() *httptrace.ClientTrace {
return &httptrace.ClientTrace{
GotConn: hct.gotConn,
DNSStart: hct.dnsStart,
GotFirstResponseByte: hct.gotFirstResponseByte,
ConnectStart: hct.connectStart,
WroteHeaders: hct.wroteHeaders,
WroteRequest: hct.wroteRequest,
}
} | [
"func",
"(",
"hct",
"*",
"httpClientTracer",
")",
"getClientTrace",
"(",
")",
"*",
"httptrace",
".",
"ClientTrace",
"{",
"return",
"&",
"httptrace",
".",
"ClientTrace",
"{",
"GotConn",
":",
"hct",
".",
"gotConn",
",",
"DNSStart",
":",
"hct",
".",
"dnsStart... | // getClientTrace is a convenience to return a filled-in `ClientTrace`. | [
"getClientTrace",
"is",
"a",
"convenience",
"to",
"return",
"a",
"filled",
"-",
"in",
"ClientTrace",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/http/http.go#L48-L57 |
13,374 | stripe/veneur | http/http.go | startSpan | func (hct *httpClientTracer) startSpan(name string) *trace.Span {
hct.mutex.Lock()
defer hct.mutex.Unlock()
newSpan, _ := trace.StartSpanFromContext(hct.ctx, name)
hct.currentSpan.ClientFinish(hct.traceClient)
hct.currentSpan = newSpan
return newSpan
} | go | func (hct *httpClientTracer) startSpan(name string) *trace.Span {
hct.mutex.Lock()
defer hct.mutex.Unlock()
newSpan, _ := trace.StartSpanFromContext(hct.ctx, name)
hct.currentSpan.ClientFinish(hct.traceClient)
hct.currentSpan = newSpan
return newSpan
} | [
"func",
"(",
"hct",
"*",
"httpClientTracer",
")",
"startSpan",
"(",
"name",
"string",
")",
"*",
"trace",
".",
"Span",
"{",
"hct",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"hct",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"newSpan",
","... | // startSpan is a convenience that replaces the current span in our
// tracer and flushes the outgoing one. | [
"startSpan",
"is",
"a",
"convenience",
"that",
"replaces",
"the",
"current",
"span",
"in",
"our",
"tracer",
"and",
"flushes",
"the",
"outgoing",
"one",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/http/http.go#L61-L69 |
13,375 | stripe/veneur | http/http.go | finishSpan | func (hct *httpClientTracer) finishSpan() {
hct.mutex.Lock()
defer hct.mutex.Unlock()
hct.currentSpan.ClientFinish(hct.traceClient)
} | go | func (hct *httpClientTracer) finishSpan() {
hct.mutex.Lock()
defer hct.mutex.Unlock()
hct.currentSpan.ClientFinish(hct.traceClient)
} | [
"func",
"(",
"hct",
"*",
"httpClientTracer",
")",
"finishSpan",
"(",
")",
"{",
"hct",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"hct",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"hct",
".",
"currentSpan",
".",
"ClientFinish",
"(",
"hct",
... | // finishSpan is called to ensure we're done tracing | [
"finishSpan",
"is",
"called",
"to",
"ensure",
"we",
"re",
"done",
"tracing"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/http/http.go#L109-L113 |
13,376 | stripe/veneur | sinks/xray/xray.go | NewXRaySpanSink | func NewXRaySpanSink(daemonAddr string, sampleRatePercentage int, commonTags map[string]string, annotationTags []string, log *logrus.Logger) (*XRaySpanSink, error) {
log.WithFields(logrus.Fields{
"Address": daemonAddr,
}).Info("Creating X-Ray client")
var sampleThreshold uint32
if sampleRatePercentage < 0 {
log.WithField("sampleRatePercentage", sampleRatePercentage).Warn("Sample rate < 0 is invalid, defaulting to 0")
sampleRatePercentage = 0
}
if sampleRatePercentage > 100 {
log.WithField("sampleRatePercentage", sampleRatePercentage).Warn("Sample rate > 100 is invalid, defaulting to 100")
sampleRatePercentage = 100
}
// Set the sample threshold to (sample rate) * (maximum value of uint32), so that
// we can store it as a uint32 instead of a float64 and compare apples-to-apples
// with the output of our hashing algorithm.
sampleThreshold = uint32(sampleRatePercentage * math.MaxUint32 / 100)
// Build a regex for cleaning names based on valid characters from:
// https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-fields
reg, err := regexp.Compile(`[^a-zA-Z0-9_\.\:\/\%\&#=+\-\@\s\\]+`)
if err != nil {
return nil, err
}
annotationTagsMap := map[string]struct{}{}
for _, key := range annotationTags {
annotationTagsMap[key] = struct{}{}
}
return &XRaySpanSink{
daemonAddr: daemonAddr,
sampleThreshold: sampleThreshold,
commonTags: commonTags,
log: log,
nameRegex: reg,
annotationTags: annotationTagsMap,
}, nil
} | go | func NewXRaySpanSink(daemonAddr string, sampleRatePercentage int, commonTags map[string]string, annotationTags []string, log *logrus.Logger) (*XRaySpanSink, error) {
log.WithFields(logrus.Fields{
"Address": daemonAddr,
}).Info("Creating X-Ray client")
var sampleThreshold uint32
if sampleRatePercentage < 0 {
log.WithField("sampleRatePercentage", sampleRatePercentage).Warn("Sample rate < 0 is invalid, defaulting to 0")
sampleRatePercentage = 0
}
if sampleRatePercentage > 100 {
log.WithField("sampleRatePercentage", sampleRatePercentage).Warn("Sample rate > 100 is invalid, defaulting to 100")
sampleRatePercentage = 100
}
// Set the sample threshold to (sample rate) * (maximum value of uint32), so that
// we can store it as a uint32 instead of a float64 and compare apples-to-apples
// with the output of our hashing algorithm.
sampleThreshold = uint32(sampleRatePercentage * math.MaxUint32 / 100)
// Build a regex for cleaning names based on valid characters from:
// https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-fields
reg, err := regexp.Compile(`[^a-zA-Z0-9_\.\:\/\%\&#=+\-\@\s\\]+`)
if err != nil {
return nil, err
}
annotationTagsMap := map[string]struct{}{}
for _, key := range annotationTags {
annotationTagsMap[key] = struct{}{}
}
return &XRaySpanSink{
daemonAddr: daemonAddr,
sampleThreshold: sampleThreshold,
commonTags: commonTags,
log: log,
nameRegex: reg,
annotationTags: annotationTagsMap,
}, nil
} | [
"func",
"NewXRaySpanSink",
"(",
"daemonAddr",
"string",
",",
"sampleRatePercentage",
"int",
",",
"commonTags",
"map",
"[",
"string",
"]",
"string",
",",
"annotationTags",
"[",
"]",
"string",
",",
"log",
"*",
"logrus",
".",
"Logger",
")",
"(",
"*",
"XRaySpanS... | // NewXRaySpanSink creates a new instance of a XRaySpanSink. | [
"NewXRaySpanSink",
"creates",
"a",
"new",
"instance",
"of",
"a",
"XRaySpanSink",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/xray/xray.go#L80-L121 |
13,377 | stripe/veneur | sinks/xray/xray.go | Start | func (x *XRaySpanSink) Start(cl *trace.Client) error {
x.traceClient = cl
xrayDaemon, err := net.ResolveUDPAddr("udp", x.daemonAddr)
if err != nil {
return err
}
conn, err := net.DialUDP("udp", nil, xrayDaemon)
if err != nil {
return err
}
x.conn = conn
return nil
} | go | func (x *XRaySpanSink) Start(cl *trace.Client) error {
x.traceClient = cl
xrayDaemon, err := net.ResolveUDPAddr("udp", x.daemonAddr)
if err != nil {
return err
}
conn, err := net.DialUDP("udp", nil, xrayDaemon)
if err != nil {
return err
}
x.conn = conn
return nil
} | [
"func",
"(",
"x",
"*",
"XRaySpanSink",
")",
"Start",
"(",
"cl",
"*",
"trace",
".",
"Client",
")",
"error",
"{",
"x",
".",
"traceClient",
"=",
"cl",
"\n\n",
"xrayDaemon",
",",
"err",
":=",
"net",
".",
"ResolveUDPAddr",
"(",
"\"",
"\"",
",",
"x",
"."... | // Start the sink | [
"Start",
"the",
"sink"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/xray/xray.go#L124-L138 |
13,378 | stripe/veneur | sinks/xray/xray.go | Flush | func (x *XRaySpanSink) Flush() {
x.log.WithFields(logrus.Fields{
"flushed_spans": atomic.LoadInt64(&x.spansHandled),
"dropped_spans": atomic.LoadInt64(&x.spansDropped),
}).Debug("Checkpointing flushed spans for X-Ray")
metrics.ReportBatch(x.traceClient, []*ssf.SSFSample{
ssf.Count(sinks.MetricKeyTotalSpansFlushed, float32(atomic.SwapInt64(&x.spansHandled, 0)), map[string]string{"sink": x.Name()}),
ssf.Count(sinks.MetricKeyTotalSpansDropped, float32(atomic.SwapInt64(&x.spansDropped, 0)), map[string]string{"sink": x.Name()}),
})
} | go | func (x *XRaySpanSink) Flush() {
x.log.WithFields(logrus.Fields{
"flushed_spans": atomic.LoadInt64(&x.spansHandled),
"dropped_spans": atomic.LoadInt64(&x.spansDropped),
}).Debug("Checkpointing flushed spans for X-Ray")
metrics.ReportBatch(x.traceClient, []*ssf.SSFSample{
ssf.Count(sinks.MetricKeyTotalSpansFlushed, float32(atomic.SwapInt64(&x.spansHandled, 0)), map[string]string{"sink": x.Name()}),
ssf.Count(sinks.MetricKeyTotalSpansDropped, float32(atomic.SwapInt64(&x.spansDropped, 0)), map[string]string{"sink": x.Name()}),
})
} | [
"func",
"(",
"x",
"*",
"XRaySpanSink",
")",
"Flush",
"(",
")",
"{",
"x",
".",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"atomic",
".",
"LoadInt64",
"(",
"&",
"x",
".",
"spansHandled",
")",
",",
"\"",
"\"",
":",... | // Flush doesn't need to do anything, so we emit metrics
// instead. | [
"Flush",
"doesn",
"t",
"need",
"to",
"do",
"anything",
"so",
"we",
"emit",
"metrics",
"instead",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/xray/xray.go#L235-L244 |
13,379 | stripe/veneur | trace/metrics/client.go | Report | func Report(cl *trace.Client, samples *ssf.Samples) error {
return ReportBatch(cl, samples.Batch)
} | go | func Report(cl *trace.Client, samples *ssf.Samples) error {
return ReportBatch(cl, samples.Batch)
} | [
"func",
"Report",
"(",
"cl",
"*",
"trace",
".",
"Client",
",",
"samples",
"*",
"ssf",
".",
"Samples",
")",
"error",
"{",
"return",
"ReportBatch",
"(",
"cl",
",",
"samples",
".",
"Batch",
")",
"\n",
"}"
] | // Report sends one-off metric samples encapsulated in a Samples
// structure to a trace client without waiting for a reply. If the
// batch of metrics is empty, an error NoMetrics is returned. | [
"Report",
"sends",
"one",
"-",
"off",
"metric",
"samples",
"encapsulated",
"in",
"a",
"Samples",
"structure",
"to",
"a",
"trace",
"client",
"without",
"waiting",
"for",
"a",
"reply",
".",
"If",
"the",
"batch",
"of",
"metrics",
"is",
"empty",
"an",
"error",... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/metrics/client.go#L21-L23 |
13,380 | stripe/veneur | trace/metrics/client.go | ReportBatch | func ReportBatch(cl *trace.Client, samples []*ssf.SSFSample) error {
return ReportAsync(cl, samples, nil)
} | go | func ReportBatch(cl *trace.Client, samples []*ssf.SSFSample) error {
return ReportAsync(cl, samples, nil)
} | [
"func",
"ReportBatch",
"(",
"cl",
"*",
"trace",
".",
"Client",
",",
"samples",
"[",
"]",
"*",
"ssf",
".",
"SSFSample",
")",
"error",
"{",
"return",
"ReportAsync",
"(",
"cl",
",",
"samples",
",",
"nil",
")",
"\n",
"}"
] | // ReportBatch sends a batch of one-off metrics to a trace client without
// waiting for a reply. If the batch of metrics is empty, an error
// NoMetrics is returned. | [
"ReportBatch",
"sends",
"a",
"batch",
"of",
"one",
"-",
"off",
"metrics",
"to",
"a",
"trace",
"client",
"without",
"waiting",
"for",
"a",
"reply",
".",
"If",
"the",
"batch",
"of",
"metrics",
"is",
"empty",
"an",
"error",
"NoMetrics",
"is",
"returned",
".... | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/metrics/client.go#L28-L30 |
13,381 | stripe/veneur | trace/metrics/client.go | ReportOne | func ReportOne(cl *trace.Client, metric *ssf.SSFSample) error {
return ReportAsync(cl, []*ssf.SSFSample{metric}, nil)
} | go | func ReportOne(cl *trace.Client, metric *ssf.SSFSample) error {
return ReportAsync(cl, []*ssf.SSFSample{metric}, nil)
} | [
"func",
"ReportOne",
"(",
"cl",
"*",
"trace",
".",
"Client",
",",
"metric",
"*",
"ssf",
".",
"SSFSample",
")",
"error",
"{",
"return",
"ReportAsync",
"(",
"cl",
",",
"[",
"]",
"*",
"ssf",
".",
"SSFSample",
"{",
"metric",
"}",
",",
"nil",
")",
"\n",... | // ReportOne sends a single metric to a veneur using a trace client
// without waiting for a reply. | [
"ReportOne",
"sends",
"a",
"single",
"metric",
"to",
"a",
"veneur",
"using",
"a",
"trace",
"client",
"without",
"waiting",
"for",
"a",
"reply",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/metrics/client.go#L48-L50 |
13,382 | stripe/veneur | trace/trace.go | finish | func (t *Trace) finish() {
if t.End.IsZero() {
t.End = time.Now()
}
} | go | func (t *Trace) finish() {
if t.End.IsZero() {
t.End = time.Now()
}
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"finish",
"(",
")",
"{",
"if",
"t",
".",
"End",
".",
"IsZero",
"(",
")",
"{",
"t",
".",
"End",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Set the end timestamp and finalize Span state | [
"Set",
"the",
"end",
"timestamp",
"and",
"finalize",
"Span",
"state"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L98-L102 |
13,383 | stripe/veneur | trace/trace.go | Duration | func (t *Trace) Duration() time.Duration {
if t.End.IsZero() {
return -1
}
return t.End.Sub(t.Start)
} | go | func (t *Trace) Duration() time.Duration {
if t.End.IsZero() {
return -1
}
return t.End.Sub(t.Start)
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"Duration",
"(",
")",
"time",
".",
"Duration",
"{",
"if",
"t",
".",
"End",
".",
"IsZero",
"(",
")",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"t",
".",
"End",
".",
"Sub",
"(",
"t",
".",
"Start",
... | // Duration is a convenience function for
// the difference between the Start and End timestamps.
// It assumes the span has already ended. | [
"Duration",
"is",
"a",
"convenience",
"function",
"for",
"the",
"difference",
"between",
"the",
"Start",
"and",
"End",
"timestamps",
".",
"It",
"assumes",
"the",
"span",
"has",
"already",
"ended",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L132-L137 |
13,384 | stripe/veneur | trace/trace.go | ProtoMarshalTo | func (t *Trace) ProtoMarshalTo(w io.Writer) error {
packet, err := proto.Marshal(t.SSFSpan())
if err != nil {
return err
}
_, err = w.Write(packet)
return err
} | go | func (t *Trace) ProtoMarshalTo(w io.Writer) error {
packet, err := proto.Marshal(t.SSFSpan())
if err != nil {
return err
}
_, err = w.Write(packet)
return err
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"ProtoMarshalTo",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"packet",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"t",
".",
"SSFSpan",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // ProtoMarshalTo writes the Trace as a protocol buffer
// in text format to the specified writer. | [
"ProtoMarshalTo",
"writes",
"the",
"Trace",
"as",
"a",
"protocol",
"buffer",
"in",
"text",
"format",
"to",
"the",
"specified",
"writer",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L170-L177 |
13,385 | stripe/veneur | trace/trace.go | Record | func (t *Trace) Record(name string, tags map[string]string) error {
return t.ClientRecord(DefaultClient, name, tags)
} | go | func (t *Trace) Record(name string, tags map[string]string) error {
return t.ClientRecord(DefaultClient, name, tags)
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"Record",
"(",
"name",
"string",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"return",
"t",
".",
"ClientRecord",
"(",
"DefaultClient",
",",
"name",
",",
"tags",
")",
"\n",
"}"
] | // Record sends a trace to a veneur instance using the DefaultClient . | [
"Record",
"sends",
"a",
"trace",
"to",
"a",
"veneur",
"instance",
"using",
"the",
"DefaultClient",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L180-L182 |
13,386 | stripe/veneur | trace/trace.go | ClientRecord | func (t *Trace) ClientRecord(cl *Client, name string, tags map[string]string) error {
if t.Tags == nil {
t.Tags = map[string]string{}
}
t.finish()
for k, v := range tags {
t.Tags[k] = v
}
if name == "" {
name = t.Name
}
span := t.SSFSpan()
span.Name = name
return Record(cl, span, t.Sent)
} | go | func (t *Trace) ClientRecord(cl *Client, name string, tags map[string]string) error {
if t.Tags == nil {
t.Tags = map[string]string{}
}
t.finish()
for k, v := range tags {
t.Tags[k] = v
}
if name == "" {
name = t.Name
}
span := t.SSFSpan()
span.Name = name
return Record(cl, span, t.Sent)
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"ClientRecord",
"(",
"cl",
"*",
"Client",
",",
"name",
"string",
",",
"tags",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"if",
"t",
".",
"Tags",
"==",
"nil",
"{",
"t",
".",
"Tags",
"=",
"map",
"... | // ClientRecord uses the given client to send a trace to a veneur
// instance. | [
"ClientRecord",
"uses",
"the",
"given",
"client",
"to",
"send",
"a",
"trace",
"to",
"a",
"veneur",
"instance",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L186-L204 |
13,387 | stripe/veneur | trace/trace.go | Attach | func (t *Trace) Attach(c context.Context) context.Context {
return context.WithValue(c, traceKey, t)
} | go | func (t *Trace) Attach(c context.Context) context.Context {
return context.WithValue(c, traceKey, t)
} | [
"func",
"(",
"t",
"*",
"Trace",
")",
"Attach",
"(",
"c",
"context",
".",
"Context",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"c",
",",
"traceKey",
",",
"t",
")",
"\n",
"}"
] | // Attach attaches the current trace to the context
// and returns a copy of the context with that trace
// stored under the key "trace". | [
"Attach",
"attaches",
"the",
"current",
"trace",
"to",
"the",
"context",
"and",
"returns",
"a",
"copy",
"of",
"the",
"context",
"with",
"that",
"trace",
"stored",
"under",
"the",
"key",
"trace",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L227-L229 |
13,388 | stripe/veneur | trace/trace.go | StartTrace | func StartTrace(resource string) *Trace {
traceID := proto.Int64(rand.Int63())
t := &Trace{
TraceID: *traceID,
SpanID: *traceID,
ParentID: 0,
Resource: resource,
Tags: map[string]string{},
}
t.Start = time.Now()
return t
} | go | func StartTrace(resource string) *Trace {
traceID := proto.Int64(rand.Int63())
t := &Trace{
TraceID: *traceID,
SpanID: *traceID,
ParentID: 0,
Resource: resource,
Tags: map[string]string{},
}
t.Start = time.Now()
return t
} | [
"func",
"StartTrace",
"(",
"resource",
"string",
")",
"*",
"Trace",
"{",
"traceID",
":=",
"proto",
".",
"Int64",
"(",
"rand",
".",
"Int63",
"(",
")",
")",
"\n\n",
"t",
":=",
"&",
"Trace",
"{",
"TraceID",
":",
"*",
"traceID",
",",
"SpanID",
":",
"*"... | // StartTrace is called by to create the root-level span
// for a trace | [
"StartTrace",
"is",
"called",
"by",
"to",
"create",
"the",
"root",
"-",
"level",
"span",
"for",
"a",
"trace"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L328-L341 |
13,389 | stripe/veneur | trace/trace.go | StartChildSpan | func StartChildSpan(parent *Trace) *Trace {
spanID := proto.Int64(rand.Int63())
span := &Trace{
SpanID: *spanID,
}
span.SetParent(parent)
span.Start = time.Now()
return span
} | go | func StartChildSpan(parent *Trace) *Trace {
spanID := proto.Int64(rand.Int63())
span := &Trace{
SpanID: *spanID,
}
span.SetParent(parent)
span.Start = time.Now()
return span
} | [
"func",
"StartChildSpan",
"(",
"parent",
"*",
"Trace",
")",
"*",
"Trace",
"{",
"spanID",
":=",
"proto",
".",
"Int64",
"(",
"rand",
".",
"Int63",
"(",
")",
")",
"\n",
"span",
":=",
"&",
"Trace",
"{",
"SpanID",
":",
"*",
"spanID",
",",
"}",
"\n\n",
... | // StartChildSpan creates a new Span with the specified parent | [
"StartChildSpan",
"creates",
"a",
"new",
"Span",
"with",
"the",
"specified",
"parent"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/trace/trace.go#L344-L354 |
13,390 | stripe/veneur | sinks/kafka/kafka.go | NewKafkaMetricSink | func NewKafkaMetricSink(logger *logrus.Logger, cl *trace.Client, brokers string, checkTopic string, eventTopic string, metricTopic string, ackRequirement string, partitioner string, retries int, bufferBytes int, bufferMessages int, bufferDuration string) (*KafkaMetricSink, error) {
if logger == nil {
logger = &logrus.Logger{Out: ioutil.Discard}
}
if checkTopic == "" && eventTopic == "" && metricTopic == "" {
return nil, errors.New("Unable to start Kafka sink with no valid topic names")
}
ll := logger.WithField("metric_sink", "kafka")
var finalBufferDuration time.Duration
if bufferDuration != "" {
var err error
finalBufferDuration, err = time.ParseDuration(bufferDuration)
if err != nil {
return nil, err
}
}
config, _ := newProducerConfig(ll, ackRequirement, partitioner, retries, bufferBytes, bufferMessages, finalBufferDuration)
ll.WithFields(logrus.Fields{
"brokers": brokers,
"check_topic": checkTopic,
"event_topic": eventTopic,
"metric_topic": metricTopic,
"partitioner": partitioner,
"ack_requirement": ackRequirement,
"max_retries": retries,
"buffer_bytes": bufferBytes,
"buffer_messages": bufferMessages,
"buffer_duration": bufferDuration,
}).Info("Created Kafka metric sink")
return &KafkaMetricSink{
logger: ll,
checkTopic: checkTopic,
eventTopic: eventTopic,
metricTopic: metricTopic,
brokers: brokers,
config: config,
traceClient: cl,
}, nil
} | go | func NewKafkaMetricSink(logger *logrus.Logger, cl *trace.Client, brokers string, checkTopic string, eventTopic string, metricTopic string, ackRequirement string, partitioner string, retries int, bufferBytes int, bufferMessages int, bufferDuration string) (*KafkaMetricSink, error) {
if logger == nil {
logger = &logrus.Logger{Out: ioutil.Discard}
}
if checkTopic == "" && eventTopic == "" && metricTopic == "" {
return nil, errors.New("Unable to start Kafka sink with no valid topic names")
}
ll := logger.WithField("metric_sink", "kafka")
var finalBufferDuration time.Duration
if bufferDuration != "" {
var err error
finalBufferDuration, err = time.ParseDuration(bufferDuration)
if err != nil {
return nil, err
}
}
config, _ := newProducerConfig(ll, ackRequirement, partitioner, retries, bufferBytes, bufferMessages, finalBufferDuration)
ll.WithFields(logrus.Fields{
"brokers": brokers,
"check_topic": checkTopic,
"event_topic": eventTopic,
"metric_topic": metricTopic,
"partitioner": partitioner,
"ack_requirement": ackRequirement,
"max_retries": retries,
"buffer_bytes": bufferBytes,
"buffer_messages": bufferMessages,
"buffer_duration": bufferDuration,
}).Info("Created Kafka metric sink")
return &KafkaMetricSink{
logger: ll,
checkTopic: checkTopic,
eventTopic: eventTopic,
metricTopic: metricTopic,
brokers: brokers,
config: config,
traceClient: cl,
}, nil
} | [
"func",
"NewKafkaMetricSink",
"(",
"logger",
"*",
"logrus",
".",
"Logger",
",",
"cl",
"*",
"trace",
".",
"Client",
",",
"brokers",
"string",
",",
"checkTopic",
"string",
",",
"eventTopic",
"string",
",",
"metricTopic",
"string",
",",
"ackRequirement",
"string"... | // NewKafkaMetricSink creates a new Kafka Plugin. | [
"NewKafkaMetricSink",
"creates",
"a",
"new",
"Kafka",
"Plugin",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/kafka/kafka.go#L63-L107 |
13,391 | stripe/veneur | sinks/kafka/kafka.go | newConfiguredProducer | func newConfiguredProducer(logger *logrus.Entry, brokerString string, config *sarama.Config) (sarama.AsyncProducer, error) {
brokerList := strings.Split(brokerString, ",")
if len(brokerList) < 1 {
logger.WithField("addrs", brokerString).Error("No brokers?")
return nil, errors.New("No brokers in broker list")
}
logger.WithField("addrs", brokerList).Info("Connecting to Kafka")
producer, err := sarama.NewAsyncProducer(brokerList, config)
if err != nil {
logger.Error("Error Connecting to Kafka. client error: ", err)
}
return producer, nil
} | go | func newConfiguredProducer(logger *logrus.Entry, brokerString string, config *sarama.Config) (sarama.AsyncProducer, error) {
brokerList := strings.Split(brokerString, ",")
if len(brokerList) < 1 {
logger.WithField("addrs", brokerString).Error("No brokers?")
return nil, errors.New("No brokers in broker list")
}
logger.WithField("addrs", brokerList).Info("Connecting to Kafka")
producer, err := sarama.NewAsyncProducer(brokerList, config)
if err != nil {
logger.Error("Error Connecting to Kafka. client error: ", err)
}
return producer, nil
} | [
"func",
"newConfiguredProducer",
"(",
"logger",
"*",
"logrus",
".",
"Entry",
",",
"brokerString",
"string",
",",
"config",
"*",
"sarama",
".",
"Config",
")",
"(",
"sarama",
".",
"AsyncProducer",
",",
"error",
")",
"{",
"brokerList",
":=",
"strings",
".",
"... | // newConfiguredProducer returns a configured Sarama SyncProducer | [
"newConfiguredProducer",
"returns",
"a",
"configured",
"Sarama",
"SyncProducer"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/kafka/kafka.go#L155-L171 |
13,392 | stripe/veneur | sinks/kafka/kafka.go | Flush | func (k *KafkaMetricSink) Flush(ctx context.Context, interMetrics []samplers.InterMetric) error {
samples := &ssf.Samples{}
defer metrics.Report(k.traceClient, samples)
if len(interMetrics) == 0 {
k.logger.Info("Nothing to flush, skipping.")
return nil
}
successes := int64(0)
for _, metric := range interMetrics {
if !sinks.IsAcceptableMetric(metric, k) {
continue
}
k.logger.Debug("Emitting Metric: ", metric.Name)
j, err := json.Marshal(metric)
if err != nil {
k.logger.Error("Error marshalling metric: ", metric.Name)
samples.Add(ssf.Count("kafka.marshal.error_total", 1, nil))
return err
}
k.producer.Input() <- &sarama.ProducerMessage{
Topic: k.metricTopic,
Value: sarama.StringEncoder(j),
}
successes++
}
samples.Add(ssf.Count(sinks.MetricKeyTotalMetricsFlushed, float32(successes), map[string]string{"sink": k.Name()}))
return nil
} | go | func (k *KafkaMetricSink) Flush(ctx context.Context, interMetrics []samplers.InterMetric) error {
samples := &ssf.Samples{}
defer metrics.Report(k.traceClient, samples)
if len(interMetrics) == 0 {
k.logger.Info("Nothing to flush, skipping.")
return nil
}
successes := int64(0)
for _, metric := range interMetrics {
if !sinks.IsAcceptableMetric(metric, k) {
continue
}
k.logger.Debug("Emitting Metric: ", metric.Name)
j, err := json.Marshal(metric)
if err != nil {
k.logger.Error("Error marshalling metric: ", metric.Name)
samples.Add(ssf.Count("kafka.marshal.error_total", 1, nil))
return err
}
k.producer.Input() <- &sarama.ProducerMessage{
Topic: k.metricTopic,
Value: sarama.StringEncoder(j),
}
successes++
}
samples.Add(ssf.Count(sinks.MetricKeyTotalMetricsFlushed, float32(successes), map[string]string{"sink": k.Name()}))
return nil
} | [
"func",
"(",
"k",
"*",
"KafkaMetricSink",
")",
"Flush",
"(",
"ctx",
"context",
".",
"Context",
",",
"interMetrics",
"[",
"]",
"samplers",
".",
"InterMetric",
")",
"error",
"{",
"samples",
":=",
"&",
"ssf",
".",
"Samples",
"{",
"}",
"\n",
"defer",
"metr... | // Flush sends a slice of metrics to Kafka | [
"Flush",
"sends",
"a",
"slice",
"of",
"metrics",
"to",
"Kafka"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/kafka/kafka.go#L189-L220 |
13,393 | stripe/veneur | sinks/kafka/kafka.go | NewKafkaSpanSink | func NewKafkaSpanSink(logger *logrus.Logger, cl *trace.Client, brokers string, topic string, partitioner string, ackRequirement string, retries int, bufferBytes int, bufferMessages int, bufferDuration string, serializationFormat string, sampleTag string, sampleRatePercentage int) (*KafkaSpanSink, error) {
if logger == nil {
logger = &logrus.Logger{Out: ioutil.Discard}
}
if topic == "" {
return nil, errors.New("Cannot start Kafka span sink with no span topic")
}
ll := logger.WithField("span_sink", "kafka")
serializer := serializationFormat
if serializer != "json" && serializer != "protobuf" {
ll.WithField("serializer", serializer).Warn("Unknown serializer, defaulting to protobuf")
serializer = "protobuf"
}
var sampleThreshold uint32
if sampleRatePercentage <= 0 || sampleRatePercentage > 100 {
return nil, errors.New("Span sample rate percentage must be greater than 0%% and less than or equal to 100%%")
}
// Set the sample threshold to (sample rate) * (maximum value of uint32), so that
// we can store it as a uint32 instead of a float64 and compare apples-to-apples
// with the output of our hashing algorithm.
sampleThreshold = uint32(sampleRatePercentage * math.MaxUint32 / 100)
var finalBufferDuration time.Duration
if bufferDuration != "" {
var err error
finalBufferDuration, err = time.ParseDuration(bufferDuration)
if err != nil {
return nil, err
}
}
config, _ := newProducerConfig(ll, ackRequirement, partitioner, retries, bufferBytes, bufferMessages, finalBufferDuration)
ll.WithFields(logrus.Fields{
"brokers": brokers,
"topic": topic,
"partitioner": partitioner,
"ack_requirement": ackRequirement,
"max_retries": retries,
"buffer_bytes": bufferBytes,
"buffer_messages": bufferMessages,
"buffer_duration": bufferDuration,
}).Info("Started Kafka span sink")
return &KafkaSpanSink{
logger: ll,
topic: topic,
brokers: brokers,
config: config,
serializer: serializer,
sampleTag: sampleTag,
sampleThreshold: sampleThreshold,
}, nil
} | go | func NewKafkaSpanSink(logger *logrus.Logger, cl *trace.Client, brokers string, topic string, partitioner string, ackRequirement string, retries int, bufferBytes int, bufferMessages int, bufferDuration string, serializationFormat string, sampleTag string, sampleRatePercentage int) (*KafkaSpanSink, error) {
if logger == nil {
logger = &logrus.Logger{Out: ioutil.Discard}
}
if topic == "" {
return nil, errors.New("Cannot start Kafka span sink with no span topic")
}
ll := logger.WithField("span_sink", "kafka")
serializer := serializationFormat
if serializer != "json" && serializer != "protobuf" {
ll.WithField("serializer", serializer).Warn("Unknown serializer, defaulting to protobuf")
serializer = "protobuf"
}
var sampleThreshold uint32
if sampleRatePercentage <= 0 || sampleRatePercentage > 100 {
return nil, errors.New("Span sample rate percentage must be greater than 0%% and less than or equal to 100%%")
}
// Set the sample threshold to (sample rate) * (maximum value of uint32), so that
// we can store it as a uint32 instead of a float64 and compare apples-to-apples
// with the output of our hashing algorithm.
sampleThreshold = uint32(sampleRatePercentage * math.MaxUint32 / 100)
var finalBufferDuration time.Duration
if bufferDuration != "" {
var err error
finalBufferDuration, err = time.ParseDuration(bufferDuration)
if err != nil {
return nil, err
}
}
config, _ := newProducerConfig(ll, ackRequirement, partitioner, retries, bufferBytes, bufferMessages, finalBufferDuration)
ll.WithFields(logrus.Fields{
"brokers": brokers,
"topic": topic,
"partitioner": partitioner,
"ack_requirement": ackRequirement,
"max_retries": retries,
"buffer_bytes": bufferBytes,
"buffer_messages": bufferMessages,
"buffer_duration": bufferDuration,
}).Info("Started Kafka span sink")
return &KafkaSpanSink{
logger: ll,
topic: topic,
brokers: brokers,
config: config,
serializer: serializer,
sampleTag: sampleTag,
sampleThreshold: sampleThreshold,
}, nil
} | [
"func",
"NewKafkaSpanSink",
"(",
"logger",
"*",
"logrus",
".",
"Logger",
",",
"cl",
"*",
"trace",
".",
"Client",
",",
"brokers",
"string",
",",
"topic",
"string",
",",
"partitioner",
"string",
",",
"ackRequirement",
"string",
",",
"retries",
"int",
",",
"b... | // NewKafkaSpanSink creates a new Kafka Plugin. | [
"NewKafkaSpanSink",
"creates",
"a",
"new",
"Kafka",
"Plugin",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/kafka/kafka.go#L228-L286 |
13,394 | stripe/veneur | sinks/kafka/kafka.go | Flush | func (k *KafkaSpanSink) Flush() {
// TODO We have no stuff in here for detecting failed writes from the async
// producer. We should add that.
k.logger.WithFields(logrus.Fields{
"flushed_spans": atomic.LoadInt64(&k.spansFlushed),
}).Debug("Checkpointing flushed spans for Kafka")
metrics.ReportOne(k.traceClient, ssf.Count(sinks.MetricKeyTotalSpansFlushed, float32(atomic.LoadInt64(&k.spansFlushed)), map[string]string{"sink": k.Name()}))
atomic.SwapInt64(&k.spansFlushed, 0)
} | go | func (k *KafkaSpanSink) Flush() {
// TODO We have no stuff in here for detecting failed writes from the async
// producer. We should add that.
k.logger.WithFields(logrus.Fields{
"flushed_spans": atomic.LoadInt64(&k.spansFlushed),
}).Debug("Checkpointing flushed spans for Kafka")
metrics.ReportOne(k.traceClient, ssf.Count(sinks.MetricKeyTotalSpansFlushed, float32(atomic.LoadInt64(&k.spansFlushed)), map[string]string{"sink": k.Name()}))
atomic.SwapInt64(&k.spansFlushed, 0)
} | [
"func",
"(",
"k",
"*",
"KafkaSpanSink",
")",
"Flush",
"(",
")",
"{",
"// TODO We have no stuff in here for detecting failed writes from the async",
"// producer. We should add that.",
"k",
".",
"logger",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
... | // Flush emits metrics, since the spans have already been ingested and are
// sending async. | [
"Flush",
"emits",
"metrics",
"since",
"the",
"spans",
"have",
"already",
"been",
"ingested",
"and",
"are",
"sending",
"async",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/sinks/kafka/kafka.go#L390-L398 |
13,395 | stripe/veneur | importsrv/server.go | New | func New(metricOuts []MetricIngester, opts ...Option) *Server {
res := &Server{
Server: grpc.NewServer(),
metricOuts: metricOuts,
opts: &options{},
}
for _, opt := range opts {
opt(res.opts)
}
if res.opts.traceClient == nil {
res.opts.traceClient = trace.DefaultClient
}
forwardrpc.RegisterForwardServer(res.Server, res)
return res
} | go | func New(metricOuts []MetricIngester, opts ...Option) *Server {
res := &Server{
Server: grpc.NewServer(),
metricOuts: metricOuts,
opts: &options{},
}
for _, opt := range opts {
opt(res.opts)
}
if res.opts.traceClient == nil {
res.opts.traceClient = trace.DefaultClient
}
forwardrpc.RegisterForwardServer(res.Server, res)
return res
} | [
"func",
"New",
"(",
"metricOuts",
"[",
"]",
"MetricIngester",
",",
"opts",
"...",
"Option",
")",
"*",
"Server",
"{",
"res",
":=",
"&",
"Server",
"{",
"Server",
":",
"grpc",
".",
"NewServer",
"(",
")",
",",
"metricOuts",
":",
"metricOuts",
",",
"opts",
... | // New creates an unstarted Server with the input MetricIngester's to send
// output to. | [
"New",
"creates",
"an",
"unstarted",
"Server",
"with",
"the",
"input",
"MetricIngester",
"s",
"to",
"send",
"output",
"to",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/importsrv/server.go#L53-L71 |
13,396 | stripe/veneur | worker.go | NewWorkerMetrics | func NewWorkerMetrics() WorkerMetrics {
return WorkerMetrics{
counters: map[samplers.MetricKey]*samplers.Counter{},
globalCounters: map[samplers.MetricKey]*samplers.Counter{},
globalGauges: map[samplers.MetricKey]*samplers.Gauge{},
globalHistograms: map[samplers.MetricKey]*samplers.Histo{},
globalTimers: map[samplers.MetricKey]*samplers.Histo{},
gauges: map[samplers.MetricKey]*samplers.Gauge{},
histograms: map[samplers.MetricKey]*samplers.Histo{},
sets: map[samplers.MetricKey]*samplers.Set{},
timers: map[samplers.MetricKey]*samplers.Histo{},
localHistograms: map[samplers.MetricKey]*samplers.Histo{},
localSets: map[samplers.MetricKey]*samplers.Set{},
localTimers: map[samplers.MetricKey]*samplers.Histo{},
localStatusChecks: map[samplers.MetricKey]*samplers.StatusCheck{},
}
} | go | func NewWorkerMetrics() WorkerMetrics {
return WorkerMetrics{
counters: map[samplers.MetricKey]*samplers.Counter{},
globalCounters: map[samplers.MetricKey]*samplers.Counter{},
globalGauges: map[samplers.MetricKey]*samplers.Gauge{},
globalHistograms: map[samplers.MetricKey]*samplers.Histo{},
globalTimers: map[samplers.MetricKey]*samplers.Histo{},
gauges: map[samplers.MetricKey]*samplers.Gauge{},
histograms: map[samplers.MetricKey]*samplers.Histo{},
sets: map[samplers.MetricKey]*samplers.Set{},
timers: map[samplers.MetricKey]*samplers.Histo{},
localHistograms: map[samplers.MetricKey]*samplers.Histo{},
localSets: map[samplers.MetricKey]*samplers.Set{},
localTimers: map[samplers.MetricKey]*samplers.Histo{},
localStatusChecks: map[samplers.MetricKey]*samplers.StatusCheck{},
}
} | [
"func",
"NewWorkerMetrics",
"(",
")",
"WorkerMetrics",
"{",
"return",
"WorkerMetrics",
"{",
"counters",
":",
"map",
"[",
"samplers",
".",
"MetricKey",
"]",
"*",
"samplers",
".",
"Counter",
"{",
"}",
",",
"globalCounters",
":",
"map",
"[",
"samplers",
".",
... | // NewWorkerMetrics initializes a WorkerMetrics struct | [
"NewWorkerMetrics",
"initializes",
"a",
"WorkerMetrics",
"struct"
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/worker.go#L81-L97 |
13,397 | stripe/veneur | worker.go | appendExportedMetric | func (wm WorkerMetrics) appendExportedMetric(res []*metricpb.Metric, exp metricExporter, mType metricpb.Type, cl *trace.Client, scope samplers.MetricScope) []*metricpb.Metric {
m, err := exp.Metric()
m.Scope = scope.ToPB()
if err != nil {
log.WithFields(logrus.Fields{
logrus.ErrorKey: err,
"type": mType,
"name": exp.GetName(),
}).Error("Could not export metric")
metrics.ReportOne(cl,
ssf.Count("worker_metrics.export_metric.errors", 1, map[string]string{
"type": mType.String(),
}),
)
return res
}
m.Type = mType
return append(res, m)
} | go | func (wm WorkerMetrics) appendExportedMetric(res []*metricpb.Metric, exp metricExporter, mType metricpb.Type, cl *trace.Client, scope samplers.MetricScope) []*metricpb.Metric {
m, err := exp.Metric()
m.Scope = scope.ToPB()
if err != nil {
log.WithFields(logrus.Fields{
logrus.ErrorKey: err,
"type": mType,
"name": exp.GetName(),
}).Error("Could not export metric")
metrics.ReportOne(cl,
ssf.Count("worker_metrics.export_metric.errors", 1, map[string]string{
"type": mType.String(),
}),
)
return res
}
m.Type = mType
return append(res, m)
} | [
"func",
"(",
"wm",
"WorkerMetrics",
")",
"appendExportedMetric",
"(",
"res",
"[",
"]",
"*",
"metricpb",
".",
"Metric",
",",
"exp",
"metricExporter",
",",
"mType",
"metricpb",
".",
"Type",
",",
"cl",
"*",
"trace",
".",
"Client",
",",
"scope",
"samplers",
... | // appendExportedMetric appends the exported version of the input metric, with
// the inputted type. If the export fails, the original slice is returned
// and an error is logged. | [
"appendExportedMetric",
"appends",
"the",
"exported",
"version",
"of",
"the",
"input",
"metric",
"with",
"the",
"inputted",
"type",
".",
"If",
"the",
"export",
"fails",
"the",
"original",
"slice",
"is",
"returned",
"and",
"an",
"error",
"is",
"logged",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/worker.go#L214-L233 |
13,398 | stripe/veneur | worker.go | NewWorker | func NewWorker(id int, cl *trace.Client, logger *logrus.Logger, stats *statsd.Client) *Worker {
return &Worker{
id: id,
PacketChan: make(chan samplers.UDPMetric, 32),
ImportChan: make(chan []samplers.JSONMetric, 32),
ImportMetricChan: make(chan []*metricpb.Metric, 32),
QuitChan: make(chan struct{}),
processed: 0,
imported: 0,
mutex: &sync.Mutex{},
traceClient: cl,
logger: logger,
wm: NewWorkerMetrics(),
stats: stats,
}
} | go | func NewWorker(id int, cl *trace.Client, logger *logrus.Logger, stats *statsd.Client) *Worker {
return &Worker{
id: id,
PacketChan: make(chan samplers.UDPMetric, 32),
ImportChan: make(chan []samplers.JSONMetric, 32),
ImportMetricChan: make(chan []*metricpb.Metric, 32),
QuitChan: make(chan struct{}),
processed: 0,
imported: 0,
mutex: &sync.Mutex{},
traceClient: cl,
logger: logger,
wm: NewWorkerMetrics(),
stats: stats,
}
} | [
"func",
"NewWorker",
"(",
"id",
"int",
",",
"cl",
"*",
"trace",
".",
"Client",
",",
"logger",
"*",
"logrus",
".",
"Logger",
",",
"stats",
"*",
"statsd",
".",
"Client",
")",
"*",
"Worker",
"{",
"return",
"&",
"Worker",
"{",
"id",
":",
"id",
",",
"... | // NewWorker creates, and returns a new Worker object. | [
"NewWorker",
"creates",
"and",
"returns",
"a",
"new",
"Worker",
"object",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/worker.go#L236-L251 |
13,399 | stripe/veneur | worker.go | MetricsProcessedCount | func (w *Worker) MetricsProcessedCount() int64 {
w.mutex.Lock()
defer w.mutex.Unlock()
return w.processed
} | go | func (w *Worker) MetricsProcessedCount() int64 {
w.mutex.Lock()
defer w.mutex.Unlock()
return w.processed
} | [
"func",
"(",
"w",
"*",
"Worker",
")",
"MetricsProcessedCount",
"(",
")",
"int64",
"{",
"w",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"w",
".",
"processed",
"\n",
"}"
] | // MetricsProcessedCount is a convenince method for testing
// that allows us to fetch the Worker's processed count
// in a non-racey way. | [
"MetricsProcessedCount",
"is",
"a",
"convenince",
"method",
"for",
"testing",
"that",
"allows",
"us",
"to",
"fetch",
"the",
"Worker",
"s",
"processed",
"count",
"in",
"a",
"non",
"-",
"racey",
"way",
"."
] | 748a3593cd11cfb4543fbe3a3a3b1614a393e3a7 | https://github.com/stripe/veneur/blob/748a3593cd11cfb4543fbe3a3a3b1614a393e3a7/worker.go#L279-L283 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.