Best Gauge code snippet using gauge.InSpan
parser_test.go
Source:parser_test.go
1package veneur2import (3 "fmt"4 "sort"5 "testing"6 "time"7 "github.com/gogo/protobuf/proto"8 "github.com/segmentio/fasthash/fnv1a"9 "github.com/stretchr/testify/assert"10 "github.com/stretchr/testify/require"11 "github.com/stripe/veneur/v14/protocol"12 "github.com/stripe/veneur/v14/protocol/dogstatsd"13 "github.com/stripe/veneur/v14/samplers"14 "github.com/stripe/veneur/v14/ssf"15)16func freshSSFMetric() *ssf.SSFSample {17 return &ssf.SSFSample{18 Metric: 0,19 Name: "test.ssf_metric",20 Value: 5,21 Message: "test_msg",22 Status: 0,23 SampleRate: 1,24 Tags: map[string]string{25 "tag1": "value1",26 "tag2": "value2",27 },28 }29}30func TestValidMetric(t *testing.T) {31 metric := freshSSFMetric()32 parser := samplers.Parser{}33 m, _ := parser.ParseMetricSSF(metric)34 assert.True(t, samplers.ValidMetric(m))35 metric.Name = ""36 m, _ = parser.ParseMetricSSF(metric)37 assert.False(t, samplers.ValidMetric(m))38 metric.SampleRate = 039 m, _ = parser.ParseMetricSSF(metric)40 assert.False(t, samplers.ValidMetric(m))41}42func TestValidTrace(t *testing.T) {43 trace := &ssf.SSFSpan{}44 assert.False(t, protocol.ValidTrace(trace))45 trace.Id = 146 trace.TraceId = 147 trace.Name = "foo"48 trace.StartTimestamp = 149 trace.EndTimestamp = 550 assert.True(t, protocol.ValidTrace(trace))51}52func TestParseSSFUnmarshal(t *testing.T) {53 test := []byte{'0'}54 sample, err := protocol.ParseSSF(test)55 assert.Nil(t, sample)56 assert.NotNil(t, err)57 assert.Error(t, err)58}59func TestParseSSFEmpty(t *testing.T) {60 trace := &ssf.SSFSpan{}61 buff, err := proto.Marshal(trace)62 assert.Nil(t, err)63 _, err = protocol.ParseSSF(buff)64 assert.NoError(t, err)65}66func TestParseSSFValidTraceInvalidMetric(t *testing.T) {67 trace := &ssf.SSFSpan{}68 trace.Id = 169 trace.TraceId = 170 trace.Name = "foo"71 trace.StartTimestamp = 172 trace.EndTimestamp = 573 buff, err := proto.Marshal(trace)74 assert.Nil(t, err)75 span, err := protocol.ParseSSF(buff)76 assert.Nil(t, err)77 if assert.NotNil(t, span) {78 assert.NoError(t, protocol.ValidateTrace(span))79 assert.NotNil(t, span)80 assert.NotNil(t, span.Tags)81 metrics, err := (&samplers.Parser{}).ConvertMetrics(span)82 assert.NoError(t, err)83 assert.Empty(t, metrics)84 }85}86func TestParseSSFInvalidTraceValidMetric(t *testing.T) {87 metric := freshSSFMetric()88 trace := &ssf.SSFSpan{}89 trace.Tags = map[string]string{90 "foo": "bar",91 }92 trace.Metrics = make([]*ssf.SSFSample, 0)93 trace.Metrics = append(trace.Metrics, metric)94 buff, err := proto.Marshal(trace)95 assert.Nil(t, err)96 span, err := protocol.ParseSSF(buff)97 assert.NoError(t, err)98 if assert.NotNil(t, span) {99 metrics, err := (&samplers.Parser{}).ConvertMetrics(span)100 assert.NoError(t, err)101 if assert.Equal(t, 1, len(metrics)) {102 m := metrics[0]103 assert.Equal(t, metric.Name, m.Name, "Name")104 assert.Equal(t, float64(metric.Value), m.Value, "Value")105 assert.Equal(t, "counter", m.Type, "Type")106 assert.NotContains(t, "foo:bar", m.Tags, "Should not pick up tag from parent span")107 }108 err = protocol.ValidateTrace(span)109 _, isInvalid := err.(*protocol.InvalidTrace)110 assert.True(t, isInvalid)111 assert.NotNil(t, span)112 }113}114func TestParseSSFValid(t *testing.T) {115 metric := freshSSFMetric()116 trace := &ssf.SSFSpan{}117 trace.Id = 1118 trace.TraceId = 1119 trace.StartTimestamp = 1120 trace.EndTimestamp = 5121 trace.Tags = map[string]string{}122 trace.Tags["foo"] = "bar"123 trace.Metrics = make([]*ssf.SSFSample, 0)124 trace.Metrics = append(trace.Metrics, metric)125 buff, err := proto.Marshal(trace)126 assert.Nil(t, err)127 msg, err := protocol.ParseSSF(buff)128 assert.NoError(t, err)129 if assert.NotNil(t, msg) {130 noTags := samplers.NewParser([]string{})131 yesTags := samplers.NewParser([]string{"implicit"})132 metrics, err := noTags.ConvertMetrics(msg)133 assert.NoError(t, err)134 if assert.Equal(t, 1, len(metrics)) {135 m := metrics[0]136 assert.Equal(t, metric.Name, m.Name, "Name")137 assert.Equal(t, float64(metric.Value), m.Value, "Value")138 assert.Equal(t, "counter", m.Type, "Type")139 assert.NotContains(t, m.Tags, "foo", "Metric should not inherit tags from its parent span")140 assert.NotContains(t, m.Tags, "implicit")141 }142 metrics, err = yesTags.ConvertMetrics(msg)143 assert.NoError(t, err)144 if assert.Equal(t, 1, len(metrics)) {145 m := metrics[0]146 assert.Equal(t, metric.Name, m.Name, "Name")147 assert.Equal(t, float64(metric.Value), m.Value, "Value")148 assert.Equal(t, "counter", m.Type, "Type")149 assert.NotContains(t, m.Tags, "foo", "Metric should not inherit tags from its parent span")150 assert.Contains(t, m.Tags, "implicit")151 }152 }153}154func TestParseSSFIndicatorSpan(t *testing.T) {155 duration := 5 * time.Second156 start := time.Now()157 end := start.Add(duration)158 span := &ssf.SSFSpan{}159 span.Id = 1160 span.TraceId = 5161 span.Name = "foo"162 span.StartTimestamp = start.UnixNano()163 span.EndTimestamp = end.UnixNano()164 span.Indicator = true165 span.Service = "bar-srv"166 span.Tags = map[string]string{167 "this-tag": "definitely gets ignored",168 "this-other-tag": "also gets dropped",169 }170 span.Metrics = make([]*ssf.SSFSample, 0)171 buff, err := proto.Marshal(span)172 assert.Nil(t, err)173 inSpan, err := protocol.ParseSSF(buff)174 assert.NoError(t, err)175 require.NotNil(t, inSpan)176 require.NoError(t, protocol.ValidateTrace(span))177 noTags := samplers.NewParser([]string{})178 yesTags := samplers.NewParser([]string{"implicit"})179 metrics, err := noTags.ConvertIndicatorMetrics(inSpan, "timer_name", "")180 assert.NoError(t, err)181 if assert.Equal(t, 1, len(metrics)) {182 m := metrics[0]183 assert.Equal(t, "timer_name", m.Name)184 assert.Equal(t, "histogram", m.Type)185 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001)186 if assert.Equal(t, 2, len(m.Tags)) {187 var tags sort.StringSlice = m.Tags188 sort.Sort(tags)189 assert.Equal(t, sort.StringSlice{190 "error:false",191 fmt.Sprintf("service:%s", span.Service),192 }, tags)193 }194 assert.NotContains(t, m.Tags, "implicit")195 }196 metrics, err = yesTags.ConvertIndicatorMetrics(inSpan, "timer_name", "")197 assert.NoError(t, err)198 if assert.Equal(t, 1, len(metrics)) {199 m := metrics[0]200 assert.Equal(t, "timer_name", m.Name)201 assert.Equal(t, "histogram", m.Type)202 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001)203 if assert.Equal(t, 3, len(m.Tags)) {204 var tags sort.StringSlice = m.Tags205 sort.Sort(tags)206 assert.Equal(t, sort.StringSlice{207 "error:false",208 "implicit",209 fmt.Sprintf("service:%s", span.Service),210 }, tags)211 }212 }213}214func TestParseSSFIndicatorSpanWithError(t *testing.T) {215 duration := 5 * time.Second216 start := time.Now()217 end := start.Add(duration)218 span := &ssf.SSFSpan{}219 span.Id = 1220 span.TraceId = 5221 span.Name = "foo"222 span.StartTimestamp = start.UnixNano()223 span.EndTimestamp = end.UnixNano()224 span.Indicator = true225 span.Service = "bar-srv"226 span.Tags = map[string]string{227 "this-tag": "definitely gets ignored",228 "this-other-tag": "also gets dropped",229 }230 span.Metrics = make([]*ssf.SSFSample, 0)231 span.Error = true232 buff, err := proto.Marshal(span)233 assert.Nil(t, err)234 inSpan, err := protocol.ParseSSF(buff)235 assert.NoError(t, err)236 require.NotNil(t, span)237 require.NoError(t, protocol.ValidateTrace(span))238 noTags := samplers.NewParser([]string{})239 yesTags := samplers.NewParser([]string{"implicit"})240 metrics, err := noTags.ConvertIndicatorMetrics(inSpan, "timer_name", "")241 assert.NoError(t, err)242 if assert.Equal(t, 1, len(metrics)) {243 m := metrics[0]244 assert.Equal(t, "timer_name", m.Name)245 assert.Equal(t, "histogram", m.Type)246 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001,247 "Duration seems incorrect: %f vs. %d", m.Value, duration/time.Nanosecond)248 if assert.Equal(t, 2, len(m.Tags)) {249 var tags sort.StringSlice = m.Tags250 sort.Sort(tags)251 assert.Equal(t, sort.StringSlice{252 "error:true",253 fmt.Sprintf("service:%s", span.Service),254 }, tags)255 }256 }257 metrics, err = yesTags.ConvertIndicatorMetrics(inSpan, "timer_name", "")258 assert.NoError(t, err)259 if assert.Equal(t, 1, len(metrics)) {260 m := metrics[0]261 assert.Equal(t, "timer_name", m.Name)262 assert.Equal(t, "histogram", m.Type)263 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001,264 "Duration seems incorrect: %f vs. %d", m.Value, duration/time.Nanosecond)265 if assert.Equal(t, 3, len(m.Tags)) {266 var tags sort.StringSlice = m.Tags267 sort.Sort(tags)268 assert.Equal(t, sort.StringSlice{269 "error:true",270 "implicit",271 fmt.Sprintf("service:%s", span.Service),272 }, tags)273 }274 }275}276func TestParseSSFIndicatorObjective(t *testing.T) {277 duration := 5 * time.Second278 start := time.Now()279 end := start.Add(duration)280 span := &ssf.SSFSpan{}281 span.Id = 1282 span.TraceId = 5283 span.Name = "foo"284 span.StartTimestamp = start.UnixNano()285 span.EndTimestamp = end.UnixNano()286 span.Indicator = true287 span.Service = "bar-srv"288 span.Tags = map[string]string{289 "this-tag": "definitely gets ignored",290 "this-other-tag": "also gets dropped",291 }292 span.Metrics = make([]*ssf.SSFSample, 0)293 buff, err := proto.Marshal(span)294 assert.Nil(t, err)295 inSpan, err := protocol.ParseSSF(buff)296 assert.NoError(t, err)297 require.NotNil(t, inSpan)298 require.NoError(t, protocol.ValidateTrace(span))299 noTags := samplers.NewParser([]string{})300 yesTags := samplers.NewParser([]string{"implicit"})301 metrics, err := noTags.ConvertIndicatorMetrics(inSpan, "", "timer_name")302 assert.NoError(t, err)303 if assert.Equal(t, 1, len(metrics)) {304 m := metrics[0]305 assert.Equal(t, "timer_name", m.Name)306 assert.Equal(t, "histogram", m.Type)307 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001)308 if assert.Equal(t, 3, len(m.Tags)) {309 var tags sort.StringSlice = m.Tags310 sort.Sort(tags)311 assert.Equal(t, sort.StringSlice{312 "error:false",313 "objective:foo",314 fmt.Sprintf("service:%s", span.Service),315 }, tags)316 }317 }318 metrics, err = yesTags.ConvertIndicatorMetrics(inSpan, "", "timer_name")319 assert.NoError(t, err)320 if assert.Equal(t, 1, len(metrics)) {321 m := metrics[0]322 assert.Equal(t, "timer_name", m.Name)323 assert.Equal(t, "histogram", m.Type)324 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001)325 if assert.Equal(t, 4, len(m.Tags)) {326 var tags sort.StringSlice = m.Tags327 sort.Sort(tags)328 assert.Equal(t, sort.StringSlice{329 "error:false",330 "implicit",331 "objective:foo",332 fmt.Sprintf("service:%s", span.Service),333 }, tags)334 }335 }336}337func TestParseSSFIndicatorObjectiveTag(t *testing.T) {338 duration := 5 * time.Second339 start := time.Now()340 end := start.Add(duration)341 span := &ssf.SSFSpan{}342 span.Id = 1343 span.TraceId = 5344 span.Name = "foo"345 span.StartTimestamp = start.UnixNano()346 span.EndTimestamp = end.UnixNano()347 span.Indicator = true348 span.Service = "bar-srv"349 span.Tags = map[string]string{350 "this-tag": "definitely gets ignored",351 "this-other-tag": "also gets dropped",352 "ssf_objective": "bar",353 }354 span.Metrics = make([]*ssf.SSFSample, 0)355 buff, err := proto.Marshal(span)356 assert.Nil(t, err)357 inSpan, err := protocol.ParseSSF(buff)358 assert.NoError(t, err)359 require.NotNil(t, inSpan)360 require.NoError(t, protocol.ValidateTrace(span))361 noTags := samplers.NewParser([]string{})362 yesTags := samplers.NewParser([]string{"implicit"})363 metrics, err := noTags.ConvertIndicatorMetrics(inSpan, "", "timer_name")364 assert.NoError(t, err)365 if assert.Equal(t, 1, len(metrics)) {366 m := metrics[0]367 assert.Equal(t, "timer_name", m.Name)368 assert.Equal(t, "histogram", m.Type)369 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001)370 if assert.Equal(t, 3, len(m.Tags)) {371 var tags sort.StringSlice = m.Tags372 sort.Sort(tags)373 assert.Equal(t, sort.StringSlice{374 "error:false",375 "objective:bar",376 fmt.Sprintf("service:%s", span.Service),377 }, tags)378 }379 }380 metrics, err = yesTags.ConvertIndicatorMetrics(inSpan, "", "timer_name")381 assert.NoError(t, err)382 if assert.Equal(t, 1, len(metrics)) {383 m := metrics[0]384 assert.Equal(t, "timer_name", m.Name)385 assert.Equal(t, "histogram", m.Type)386 assert.InEpsilon(t, float32(duration/time.Nanosecond), m.Value, 0.001)387 if assert.Equal(t, 4, len(m.Tags)) {388 var tags sort.StringSlice = m.Tags389 sort.Sort(tags)390 assert.Equal(t, sort.StringSlice{391 "error:false",392 "implicit",393 "objective:bar",394 fmt.Sprintf("service:%s", span.Service),395 }, tags)396 }397 }398}399func TestParseSSFIndicatorSpanNotNamed(t *testing.T) {400 duration := 5 * time.Second401 start := time.Now()402 end := start.Add(duration)403 span := &ssf.SSFSpan{}404 span.Id = 1405 span.TraceId = 5406 span.Name = "foo"407 span.StartTimestamp = start.UnixNano()408 span.EndTimestamp = end.UnixNano()409 span.Indicator = true410 span.Service = "bar-srv"411 span.Tags = map[string]string{412 "this-tag": "definitely gets ignored",413 "this-other-tag": "also gets dropped",414 }415 span.Metrics = make([]*ssf.SSFSample, 0)416 buff, err := proto.Marshal(span)417 assert.Nil(t, err)418 inSpan, err := protocol.ParseSSF(buff)419 assert.NoError(t, err)420 require.NotNil(t, inSpan)421 require.NoError(t, protocol.ValidateTrace(inSpan))422 metrics, err := (&samplers.Parser{}).ConvertIndicatorMetrics(inSpan, "", "")423 assert.NoError(t, err)424 assert.Equal(t, 0, len(metrics))425}426func TestParseSSFNonIndicatorSpan(t *testing.T) {427 duration := 5 * time.Second428 start := time.Now()429 end := start.Add(duration)430 span := &ssf.SSFSpan{}431 span.Id = 1432 span.TraceId = 5433 span.Name = "no-timer"434 span.StartTimestamp = start.UnixNano()435 span.EndTimestamp = end.UnixNano()436 span.Indicator = false437 span.Service = "bar-srv"438 span.Tags = map[string]string{439 "this-tag": "definitely gets ignored",440 "this-other-tag": "also gets dropped",441 }442 span.Metrics = make([]*ssf.SSFSample, 0)443 buff, err := proto.Marshal(span)444 assert.Nil(t, err)445 inSpan, err := protocol.ParseSSF(buff)446 require.NotNil(t, inSpan)447 require.NoError(t, err)448 require.NoError(t, protocol.ValidateTrace(inSpan))449 metrics, err := (&samplers.Parser{}).ConvertIndicatorMetrics(inSpan, "timer_name", "objective_name")450 assert.NoError(t, err)451 assert.Equal(t, 0, len(metrics))452}453func TestParseSSFBadMetric(t *testing.T) {454 metric := freshSSFMetric()455 metric.Metric = 5456 trace := &ssf.SSFSpan{}457 trace.Metrics = make([]*ssf.SSFSample, 0)458 trace.Metrics = append(trace.Metrics, metric)459 buff, err := proto.Marshal(trace)460 assert.Nil(t, err)461 span, err := protocol.ParseSSF(buff)462 assert.NoError(t, err)463 if assert.NotNil(t, span) {464 metrics, err := (&samplers.Parser{}).ConvertMetrics(span)465 assert.Error(t, err)466 assert.Equal(t, 0, len(metrics))467 invalid, ok := err.(samplers.InvalidMetrics)468 if assert.True(t, ok, "Error type incorrect: %v", err) {469 assert.Equal(t, 1, len(invalid.Samples()))470 }471 }472}473func TestParserSSF(t *testing.T) {474 standardMetric := freshSSFMetric()475 m, _ := (&samplers.Parser{}).ParseMetricSSF(standardMetric)476 assert.NotNil(t, m, "Got nil metric!")477 assert.Equal(t, standardMetric.Name, m.Name, "Name")478 assert.Equal(t, float64(standardMetric.Value), m.Value, "Value")479 assert.Equal(t, "counter", m.Type, "Type")480}481func TestParserSSFGauge(t *testing.T) {482 standardMetric := freshSSFMetric()483 standardMetric.Metric = ssf.SSFSample_GAUGE484 m, _ := (&samplers.Parser{}).ParseMetricSSF(standardMetric)485 assert.NotNil(t, m, "Got nil metric!")486 assert.Equal(t, standardMetric.Name, m.Name, "Name")487 assert.Equal(t, float64(standardMetric.Value), m.Value, "Value")488 assert.Equal(t, "gauge", m.Type, "Type")489}490func TestParserSSFSet(t *testing.T) {491 standardMetric := freshSSFMetric()492 standardMetric.Metric = ssf.SSFSample_SET493 m, _ := (&samplers.Parser{}).ParseMetricSSF(standardMetric)494 assert.NotNil(t, m, "Got nil metric!")495 assert.Equal(t, standardMetric.Name, m.Name, "Name")496 assert.Equal(t, standardMetric.Message, m.Value, "Value")497 assert.Equal(t, "set", m.Type, "Type")498}499func TestParserSSFWithTags(t *testing.T) {500 standardMetric := freshSSFMetric()501 noTags := samplers.NewParser([]string{})502 yesTags := samplers.NewParser([]string{"implicit"})503 m, _ := noTags.ParseMetricSSF(standardMetric)504 assert.NotNil(t, m, "Got nil metric!")505 assert.Equal(t, standardMetric.Name, m.Name, "Name")506 assert.Equal(t, float64(standardMetric.Value), m.Value, "Value")507 assert.Equal(t, "counter", m.Type, "Type")508 assert.Equal(t, 2, len(m.Tags), "# of Tags")509 m, _ = yesTags.ParseMetricSSF(standardMetric)510 assert.Equal(t, 3, len(m.Tags), "# of Tags")511}512func TestParserSSFWithSampleRate(t *testing.T) {513 standardMetric := freshSSFMetric()514 standardMetric.SampleRate = 0.1515 m, _ := (&samplers.Parser{}).ParseMetricSSF(standardMetric)516 assert.NotNil(t, m, "Got nil metric!")517 assert.Equal(t, standardMetric.Name, m.Name, "Name")518 assert.Equal(t, float64(standardMetric.Value), m.Value, "Value")519 assert.Equal(t, "counter", m.Type, "Type")520 assert.Equal(t, float32(0.1), m.SampleRate, "Sample Rate")521}522func TestParserSSFWithSampleRateAndTags(t *testing.T) {523 standardMetric := freshSSFMetric()524 standardMetric.SampleRate = 0.1525 noTags := samplers.NewParser([]string{})526 yesTags := samplers.NewParser([]string{"implicit"})527 m, _ := noTags.ParseMetricSSF(standardMetric)528 assert.NotNil(t, m, "Got nil metric!")529 assert.Equal(t, standardMetric.Name, m.Name, "Name")530 assert.Equal(t, float64(standardMetric.Value), m.Value, "Value")531 assert.Equal(t, "counter", m.Type, "Type")532 assert.Equal(t, float32(0.1), m.SampleRate, "Sample Rate")533 assert.Len(t, m.Tags, 2, "Tags")534 m, _ = yesTags.ParseMetricSSF(standardMetric)535 assert.Len(t, m.Tags, 3, "Tags")536}537func TestParserSSFWithStatusCheck(t *testing.T) {538 standardMetric := freshSSFMetric()539 standardMetric.Metric = ssf.SSFSample_STATUS540 standardMetric.Status = ssf.SSFSample_UNKNOWN541 noTags := samplers.NewParser([]string{})542 yesTags := samplers.NewParser([]string{"implicit"})543 m, _ := noTags.ParseMetricSSF(standardMetric)544 assert.NotNil(t, m, "Got nil metric!")545 assert.Equal(t, standardMetric.Name, m.Name, "Name")546 assert.Equal(t, ssf.SSFSample_UNKNOWN, m.Value, "Value")547 assert.Equal(t, "status", m.Type, "Type")548 assert.Len(t, m.Tags, 2, "Tags")549 m, _ = yesTags.ParseMetricSSF(standardMetric)550 assert.Len(t, m.Tags, 3, "Tags")551}552func TestParser(t *testing.T) {553 noTags := samplers.NewParser([]string{})554 yesTags := samplers.NewParser([]string{"implicit"})555 m, _ := noTags.ParseMetric([]byte("a.b.c:1|c"))556 assert.NotNil(t, m, "Got nil metric!")557 assert.Equal(t, "a.b.c", m.Name, "Name")558 assert.Equal(t, float64(1), m.Value, "Value")559 assert.Equal(t, "counter", m.Type, "Type")560 assert.Equal(t, 0, len(m.Tags), "# of tags")561 m, _ = yesTags.ParseMetric([]byte("a.b.c:1|c"))562 assert.Equal(t, 1, len(m.Tags), "# of tags")563}564func TestParserGauge(t *testing.T) {565 noTags := samplers.NewParser([]string{})566 yesTags := samplers.NewParser([]string{"implicit"})567 m, _ := noTags.ParseMetric([]byte("a.b.c:1|g"))568 assert.NotNil(t, m, "Got nil metric!")569 assert.Equal(t, "a.b.c", m.Name, "Name")570 assert.Equal(t, float64(1), m.Value, "Value")571 assert.Equal(t, "gauge", m.Type, "Type")572 assert.Equal(t, 0, len(m.Tags), "# of tags")573 m, _ = yesTags.ParseMetric([]byte("a.b.c:1|g"))574 assert.Equal(t, 1, len(m.Tags), "# of tags")575}576func TestParserHistogram(t *testing.T) {577 noTags := samplers.NewParser([]string{})578 yesTags := samplers.NewParser([]string{"implicit"})579 m, _ := noTags.ParseMetric([]byte("a.b.c:1|h"))580 assert.NotNil(t, m, "Got nil metric!")581 assert.Equal(t, "a.b.c", m.Name, "Name")582 assert.Equal(t, float64(1), m.Value, "Value")583 assert.Equal(t, "histogram", m.Type, "Type")584 assert.Equal(t, 0, len(m.Tags), "# of tags")585 m, _ = yesTags.ParseMetric([]byte("a.b.c:1|h"))586 assert.Equal(t, 1, len(m.Tags), "# of tags")587}588func TestParserHistogramFloat(t *testing.T) {589 noTags := samplers.NewParser([]string{})590 yesTags := samplers.NewParser([]string{"implicit"})591 m, _ := noTags.ParseMetric([]byte("a.b.c:1.234|h"))592 assert.NotNil(t, m, "Got nil metric!")593 assert.Equal(t, "a.b.c", m.Name, "Name")594 assert.Equal(t, float64(1.234), m.Value, "Value")595 assert.Equal(t, "histogram", m.Type, "Type")596 assert.Equal(t, 0, len(m.Tags), "# of tags")597 m, _ = yesTags.ParseMetric([]byte("a.b.c:1.234|h"))598 assert.Equal(t, 1, len(m.Tags), "# of tags")599}600func TestParserTimer(t *testing.T) {601 noTags := samplers.NewParser([]string{})602 yesTags := samplers.NewParser([]string{"implicit"})603 m, _ := noTags.ParseMetric([]byte("a.b.c:1|ms"))604 assert.NotNil(t, m, "Got nil metric!")605 assert.Equal(t, "a.b.c", m.Name, "Name")606 assert.Equal(t, float64(1), m.Value, "Value")607 assert.Equal(t, "timer", m.Type, "Type")608 assert.Equal(t, 0, len(m.Tags), "# of tags")609 m, _ = yesTags.ParseMetric([]byte("a.b.c:1|ms"))610 assert.Equal(t, 1, len(m.Tags), "# of tags")611}612func TestParserDistribution(t *testing.T) {613 noTags := samplers.NewParser([]string{})614 yesTags := samplers.NewParser([]string{"implicit"})615 m, _ := noTags.ParseMetric([]byte("a.b.c:0.1716441474854946|d|#filter:flatulent"))616 assert.NotNil(t, m, "Got nil metric!")617 assert.Equal(t, "a.b.c", m.Name, "Name")618 assert.Equal(t, float64(0.1716441474854946), m.Value, "Value")619 assert.Equal(t, "histogram", m.Type, "Type")620 assert.Equal(t, 1, len(m.Tags), "# of tags")621 m, _ = yesTags.ParseMetric([]byte("a.b.c:0.1716441474854946|d|#filter:flatulent"))622 assert.Equal(t, 2, len(m.Tags), "# of tags")623}624func TestParserTimerFloat(t *testing.T) {625 noTags := samplers.NewParser([]string{})626 yesTags := samplers.NewParser([]string{"implicit"})627 m, _ := noTags.ParseMetric([]byte("a.b.c:1.234|ms"))628 assert.NotNil(t, m, "Got nil metric!")629 assert.Equal(t, "a.b.c", m.Name, "Name")630 assert.Equal(t, float64(1.234), m.Value, "Value")631 assert.Equal(t, "timer", m.Type, "Type")632 assert.Equal(t, 0, len(m.Tags), "# of tags")633 m, _ = yesTags.ParseMetric([]byte("a.b.c:1.234|ms"))634 assert.Equal(t, 1, len(m.Tags), "# of tags")635}636func TestParserSet(t *testing.T) {637 noTags := samplers.NewParser([]string{})638 yesTags := samplers.NewParser([]string{"implicit"})639 m, _ := noTags.ParseMetric([]byte("a.b.c:foo|s"))640 assert.NotNil(t, m, "Got nil metric!")641 assert.Equal(t, "a.b.c", m.Name, "Name")642 assert.Equal(t, "foo", m.Value, "Value")643 assert.Equal(t, "set", m.Type, "Type")644 assert.Equal(t, 0, len(m.Tags), "# of tags")645 m, _ = yesTags.ParseMetric([]byte("a.b.c:foo|s"))646 assert.Equal(t, 1, len(m.Tags), "# of tags")647}648func TestParserWithTags(t *testing.T) {649 noTags := samplers.NewParser([]string{})650 yesTags := samplers.NewParser([]string{"implicit"})651 m, _ := noTags.ParseMetric([]byte("a.b.c:1|c|#foo:bar,baz:gorch"))652 assert.NotNil(t, m, "Got nil metric!")653 assert.Equal(t, "a.b.c", m.Name, "Name")654 assert.Equal(t, float64(1), m.Value, "Value")655 assert.Equal(t, "counter", m.Type, "Type")656 assert.EqualValues(t, []string{"baz:gorch", "foo:bar"}, m.Tags, "Expected Tags")657 y, _ := yesTags.ParseMetric([]byte("a.b.c:1|c|#foo:bar,baz:gorch"))658 assert.EqualValues(t, []string{"baz:gorch", "foo:bar", "implicit"}, y.Tags, "Expected Tags")659 // ensure that tag order doesn't matter: it must produce the same digest660 m2, _ := noTags.ParseMetric([]byte("a.b.c:1|c|#baz:gorch,foo:bar"))661 assert.EqualValues(t, []string{"baz:gorch", "foo:bar"}, m2.Tags, "Expected Tags")662 assert.Equal(t, m.Digest, m2.Digest, "Digest must not depend on tag order")663 assert.Equal(t, m.MetricKey, m2.MetricKey, "MetricKey must not depend on tag order")664 y2, _ := yesTags.ParseMetric([]byte("a.b.c:1|c|#baz:gorch,foo:bar"))665 assert.EqualValues(t, []string{"baz:gorch", "foo:bar", "implicit"}, y2.Tags, "Expected Tags")666 assert.Equal(t, y.Digest, y2.Digest, "Digest must not depend on tag order")667 assert.Equal(t, y.MetricKey, y2.MetricKey, "MetricKey must not depend on tag order")668 // treated as an empty tag669 m, err := noTags.ParseMetric([]byte("a.b.c:1|c|#"))670 assert.Equal(t, nil, err, "not an error")671 assert.EqualValues(t, []string{""}, m.Tags, "expected empty tag")672 m, err = yesTags.ParseMetric([]byte("a.b.c:1|c|#"))673 assert.Equal(t, nil, err, "not an error")674 assert.EqualValues(t, []string{"", "implicit"}, m.Tags, "expected empty tag")675 _, valueError := noTags.ParseMetric([]byte("a.b.c:fart|c"))676 assert.NotNil(t, valueError, "No errors when parsing")677 assert.Contains(t, valueError.Error(), "Invalid number", "Invalid number error missing")678}679func TestParserWithSampleRate(t *testing.T) {680 noTags := samplers.NewParser([]string{})681 yesTags := samplers.NewParser([]string{"implicit"})682 m, _ := noTags.ParseMetric([]byte("a.b.c:1|c|@0.1"))683 assert.NotNil(t, m, "Got nil metric!")684 assert.Equal(t, "a.b.c", m.Name, "Name")685 assert.Equal(t, float64(1), m.Value, "Value")686 assert.Equal(t, "counter", m.Type, "Type")687 assert.Equal(t, float32(0.1), m.SampleRate, "Sample Rate")688 assert.Equal(t, 0, len(m.Tags), "# of tags")689 m, _ = yesTags.ParseMetric([]byte("a.b.c:1|c|@0.1"))690 assert.Equal(t, 1, len(m.Tags), "# of tags")691 _, valueError := (&samplers.Parser{}).ParseMetric([]byte("a.b.c:fart|c"))692 assert.NotNil(t, valueError, "No errors when parsing")693 assert.Contains(t, valueError.Error(), "Invalid number", "Invalid number error missing")694 _, valueError = (&samplers.Parser{}).ParseMetric([]byte("a.b.c:1|g|@0.1"))695 assert.NoError(t, valueError, "Got errors when parsing")696}697func TestParserWithSampleRateAndTags(t *testing.T) {698 noTags := samplers.NewParser([]string{})699 yesTags := samplers.NewParser([]string{"implicit"})700 m, _ := noTags.ParseMetric([]byte("a.b.c:1|c|@0.1|#foo:bar,baz:gorch"))701 assert.NotNil(t, m, "Got nil metric!")702 assert.Equal(t, "a.b.c", m.Name, "Name")703 assert.Equal(t, float64(1), m.Value, "Value")704 assert.Equal(t, "counter", m.Type, "Type")705 assert.Equal(t, float32(0.1), m.SampleRate, "Sample Rate")706 assert.Len(t, m.Tags, 2, "Tags")707 m, _ = yesTags.ParseMetric([]byte("a.b.c:1|c|@0.1|#foo:bar,baz:gorch"))708 assert.Len(t, m.Tags, 3, "Tags")709 _, valueError := (&samplers.Parser{}).ParseMetric([]byte("a.b.c:fart|c"))710 assert.NotNil(t, valueError, "No errors when parsing")711 assert.Contains(t, valueError.Error(), "Invalid number", "Invalid number error missing")712}713func TestInvalidPackets(t *testing.T) {714 table := map[string]string{715 "foo": "1 colon",716 "foo:1": "1 pipe",717 "foo:1||": "metric type",718 "foo:|c|": "metric value",719 "this_is_a_bad_metric:nan|g|#shell": "metric value",720 "this_is_a_bad_metric:NaN|g|#shell": "metric value",721 "this_is_a_bad_metric:-inf|g|#shell": "metric value",722 "this_is_a_bad_metric:+inf|g|#shell": "metric value",723 "foo:1|foo|": "Invalid type",724 "foo:1|c||": "pipes",725 "foo:1|c|foo": "unknown section",726 "foo:1|c|@-0.1": ">0",727 "foo:1|c|@1.1": "<=1",728 "foo:1|c|@0.5|@0.2": "multiple sample rates",729 "foo:1|c|#foo|#bar": "multiple tag sections",730 }731 for packet, errContent := range table {732 _, err := (&samplers.Parser{}).ParseMetric([]byte(packet))733 assert.NotNil(t, err, "Should have gotten error parsing %q", packet)734 assert.Contains(t, err.Error(), errContent, "Error should have contained text")735 }736}737func TestLocalOnlyEscape(t *testing.T) {738 m, err := (&samplers.Parser{}).ParseMetric([]byte("a.b.c:1|h|#veneurlocalonly,tag2:quacks"))739 assert.NoError(t, err, "should have no error parsing")740 assert.Equal(t, samplers.LocalOnly, m.Scope, "should have gotten local only metric")741 assert.NotContains(t, m.Tags, "veneurlocalonly", "veneurlocalonly should not actually be a tag")742 assert.Contains(t, m.Tags, "tag2:quacks", "tag2 should be preserved in the list of tags after removing magic tags")743}744func TestGlobalOnlyEscape(t *testing.T) {745 m, err := (&samplers.Parser{}).ParseMetric([]byte("a.b.c:1|h|#veneurglobalonly,tag2:quacks"))746 assert.NoError(t, err, "should have no error parsing")747 assert.Equal(t, samplers.GlobalOnly, m.Scope, "should have gotten local only metric")748 assert.NotContains(t, m.Tags, "veneurglobalonly", "veneurlocalonly should not actually be a tag")749 assert.Contains(t, m.Tags, "tag2:quacks", "tag2 should be preserved in the list of tags after removing magic tags")750}751func TestEvents(t *testing.T) {752 noTags := samplers.NewParser([]string{})753 yesTags := samplers.NewParser([]string{"implicit"})754 evt, err := noTags.ParseEvent([]byte("_e{3,3}:foo|bar|k:foos|s:test|t:success|p:low|#foo:bar,baz:qux|d:1136239445|h:example.com"))755 assert.NoError(t, err, "should have parsed correctly")756 assert.EqualValues(t, &ssf.SSFSample{757 Name: "foo",758 Message: "bar",759 Timestamp: 1136239445,760 Tags: map[string]string{761 dogstatsd.EventIdentifierKey: "",762 dogstatsd.EventAggregationKeyTagKey: "foos",763 dogstatsd.EventSourceTypeTagKey: "test",764 dogstatsd.EventAlertTypeTagKey: "success",765 dogstatsd.EventPriorityTagKey: "low",766 dogstatsd.EventHostnameTagKey: "example.com",767 "foo": "bar",768 "baz": "qux",769 },770 }, evt, "should have parsed event")771 evt, err = yesTags.ParseEvent([]byte("_e{3,3}:foo|bar|k:foos|s:test|t:success|p:low|#foo:bar,baz:qux|d:1136239445|h:example.com"))772 assert.NoError(t, err, "should have parsed correctly")773 assert.Equal(t, map[string]string{774 dogstatsd.EventIdentifierKey: "",775 dogstatsd.EventAggregationKeyTagKey: "foos",776 dogstatsd.EventSourceTypeTagKey: "test",777 dogstatsd.EventAlertTypeTagKey: "success",778 dogstatsd.EventPriorityTagKey: "low",779 dogstatsd.EventHostnameTagKey: "example.com",780 "foo": "bar",781 "baz": "qux",782 "implicit": "",783 }, evt.Tags)784 table := map[string]string{785 "_e{4,3}:foo|bar": "title length",786 "_e{3,4}:foo|bar": "text length",787 "_e{3,3}:foo|bar|d:abc": "date",788 "_e{3,3}:foo|bar|p:baz": "priority",789 "_e{3,3}:foo|bar|t:baz": "alert",790 "_e{3,3}:foo|bar|t:info|t:info": "multiple alert",791 "_e{3,3}:foo|bar||": "pipe",792 "_e{3,0}:foo||": "text length",793 "_e{3,3}:foo": "text",794 "_e{3,3}": "colon",795 }796 for packet, errContent := range table {797 _, err := (&samplers.Parser{}).ParseEvent([]byte(packet))798 assert.NotNil(t, err, "Should have gotten error parsing %q", packet)799 assert.Contains(t, err.Error(), errContent, "Error should have contained text")800 }801}802func TestServiceChecks(t *testing.T) {803 noTags := samplers.NewParser([]string{})804 yesTags := samplers.NewParser([]string{"implicit"})805 svcCheck, err := noTags.ParseServiceCheck([]byte("_sc|foo.bar|0|#foo:bar,qux:dor|d:1136239445|h:example.com"))806 assert.NoError(t, err, "should have parsed correctly")807 expected := &samplers.UDPMetric{808 MetricKey: samplers.MetricKey{809 Name: "foo.bar",810 Type: "status",811 JoinedTags: "foo:bar,qux:dor",812 },813 SampleRate: 1.0,814 Value: ssf.SSFSample_OK,815 Timestamp: 1136239445,816 HostName: "example.com",817 Tags: []string{818 "foo:bar",819 "qux:dor",820 },821 }822 h := fnv1a.Init32823 h = fnv1a.AddString32(h, expected.Name)824 h = fnv1a.AddString32(h, expected.Type)825 h = fnv1a.AddString32(h, expected.JoinedTags)826 expected.Digest = h827 assert.EqualValues(t, expected, svcCheck, "should have parsed event")828 svcCheck, err = yesTags.ParseServiceCheck([]byte("_sc|foo.bar|0|#foo:bar,qux:dor|d:1136239445|h:example.com"))829 assert.NoError(t, err, "should have parsed correctly")830 expected = &samplers.UDPMetric{831 MetricKey: samplers.MetricKey{832 Name: "foo.bar",833 Type: "status",834 JoinedTags: "foo:bar,implicit,qux:dor",835 },836 SampleRate: 1.0,837 Value: ssf.SSFSample_OK,838 Timestamp: 1136239445,839 HostName: "example.com",840 Tags: []string{841 "foo:bar",842 "implicit",843 "qux:dor",844 },845 }846 h = fnv1a.Init32847 h = fnv1a.AddString32(h, expected.Name)848 h = fnv1a.AddString32(h, expected.Type)849 h = fnv1a.AddString32(h, expected.JoinedTags)850 expected.Digest = h851 assert.EqualValues(t, expected, svcCheck, "should have parsed event")852 table := map[string]string{853 "foo.bar|0": "_sc",854 "_sc|foo.bar": "status",855 "_sc|foo.bar|5": "status",856 "_sc|foo.bar|0||": "pipe",857 "_sc|foo.bar|0|d:abc": "date",858 }859 for packet, errContent := range table {860 _, err := (&samplers.Parser{}).ParseServiceCheck([]byte(packet))861 assert.NotNil(t, err, "Should have gotten error parsing %q", packet)862 assert.Contains(t, err.Error(), errContent, "Error should have contained text")863 }864}865func TestEventMessageUnescape(t *testing.T) {866 packet := []byte("_e{3,15}:foo|foo\\nbar\\nbaz\\n")867 evt, err := (&samplers.Parser{}).ParseEvent(packet)868 assert.NoError(t, err, "Should have parsed correctly")869 assert.Equal(t, "foo\nbar\nbaz\n", evt.Message, "Should contain newline")870}871func TestServiceCheckMessageUnescape(t *testing.T) {872 packet := []byte("_sc|foo|0|m:foo\\nbar\\nbaz\\n")873 svcheck, err := (&samplers.Parser{}).ParseServiceCheck(packet)874 assert.NoError(t, err, "Should have parsed correctly")875 assert.Equal(t, "foo\nbar\nbaz\n", svcheck.Message, "Should contain newline")876}877func TestServiceCheckMessageStatus(t *testing.T) {878 packet := []byte("_sc|foo|1|m:foo")879 svcheck, err := (&samplers.Parser{}).ParseServiceCheck(packet)880 assert.NoError(t, err, "Should have parsed correctly")881 assert.Equal(t, "foo", svcheck.Message, "Should contain newline")882 assert.Equal(t, ssf.SSFSample_WARNING, svcheck.Value, "Should parse status correctly")883}884func TestConsecutiveParseSSF(t *testing.T) {885 span := &ssf.SSFSpan{886 Id: 12345678,887 TraceId: 1,888 StartTimestamp: 123,889 EndTimestamp: 124,890 Tags: map[string]string{891 "foo": "bar",892 },893 }894 buff1, err := proto.Marshal(span)895 assert.Nil(t, err)896 otherSpan := &ssf.SSFSpan{897 Id: 12345679,898 TraceId: 2,899 StartTimestamp: 125,900 EndTimestamp: 126,901 }902 buff2, err := proto.Marshal(otherSpan)903 assert.Nil(t, err)904 // Because ParseSSF reuses buffers via a Pool when parsing we905 // want to ensure that subsequent calls properly reset and906 // don't bleed into each other, so "parse" each and check.907 span1, err := protocol.ParseSSF(buff1)908 assert.Nil(t, err)909 span2, err := protocol.ParseSSF(buff2)910 assert.Nil(t, err)911 assert.Equal(t, int64(12345678), span1.Id)912 assert.Equal(t, "bar", span1.Tags["foo"], "Tagful span has no tags!")913 assert.Equal(t, int64(12345679), span2.Id)914 assert.Equal(t, "", span2.Tags["foo"], "Tagless span has tags!")915}916func BenchmarkParseSSF(b *testing.B) {917 span := &ssf.SSFSpan{}918 buff, err := proto.Marshal(span)919 assert.Nil(b, err)920 for n := 0; n < b.N; n++ {921 protocol.ParseSSF(buff)922 }923}924var benchResult uint32925func BenchmarkParseMetric(b *testing.B) {926 var total uint32927 metricName := "a.b.c"928 metricValues := []struct {929 name string930 metricValue string931 metricType string932 }{933 {"IntCount", "1", "c"},934 {"FloatHistogram", "4.5", "h"},935 }936 explicitTags := []struct {937 name string938 metricTags string939 }{940 {"ZeroTags", ""},941 {"OneTag", "baz:gorch"},942 {"TwoTags", "foo:bar,baz:gorch"},943 }944 implicitTags := []struct {945 name string946 metricTags []string947 }{948 {"NoImplicit", []string{}},949 {"OneImplicit", []string{"six:6"}},950 {"TwoImplicit", []string{"three:three", "six:6", "nine:9", "ten:10", "eleven:11", "twelve:12"}},951 }952 for _, mv := range metricValues {953 for _, it := range implicitTags {954 for _, et := range explicitTags {955 var statsd string956 if et.metricTags == "" {957 statsd = fmt.Sprintf("%s:%s|%s", metricName, mv.metricValue, mv.metricType)958 } else {959 statsd = fmt.Sprintf("%s:%s|%s#%s", metricName, mv.metricValue, mv.metricType, et.metricTags)960 }961 benchName := fmt.Sprintf("%s%s%s", mv.name, it.name, et.name)962 metricBytes := []byte(statsd)963 parser := samplers.NewParser(it.metricTags)964 b.Run(benchName, func(b *testing.B) {965 for n := 0; n < b.N; n++ {966 m, err := parser.ParseMetric(metricBytes)967 if err != nil {968 b.Fatal(err)969 }970 total += m.Digest971 }972 })973 }974 }975 }976 // Attempt to avoid compiler optimizations? Is this relevant?977 benchResult = total978}...
scenario.go
Source:scenario.go
...50func (scenario *Scenario) AddComment(comment *Comment) {51 scenario.Comments = append(scenario.Comments, comment)52 scenario.AddItem(comment)53}54func (scenario *Scenario) InSpan(lineNumber int) bool {55 return scenario.Span.isInRange(lineNumber)56}57func (scenario *Scenario) renameSteps(oldStep Step, newStep Step, orderMap map[int]int) bool {58 isRefactored := false59 isConcept := false60 for _, step := range scenario.Steps {61 isRefactored = step.Rename(oldStep, newStep, isRefactored, orderMap, &isConcept)62 }63 return isRefactored64}65func (scenario *Scenario) AddItem(itemToAdd Item) {66 if scenario.Items == nil {67 scenario.Items = make([]Item, 0)68 }...
InSpan
Using AI Code Generation
1import (2var (3 gauge = promauto.NewGauge(prometheus.GaugeOpts{4 })5func main() {6 fmt.Println("Hello, playground")7 go func() {8 for {9 gauge.Inc()10 time.Sleep(1 * time.Second)11 }12 }()13 http.Handle("/metrics", promhttp.Handler())14 log.Fatal(http.ListenAndServe(":2112", nil))15}
InSpan
Using AI Code Generation
1import (2var (3 myGauge = promauto.NewGauge(prometheus.GaugeOpts{4 })5func main() {6 http.Handle("/metrics", promhttp.Handler())7 go func() {8 for {9 myGauge.Inc()10 time.Sleep(2 * time.Second)11 }12 }()13 http.ListenAndServe(":8080", nil)14}15import (16var (17 myGauge = promauto.NewGauge(prometheus.GaugeOpts{18 })19func main() {20 http.Handle("/metrics", promhttp.Handler())21 go func() {22 for {23 myGauge.Set(10)24 time.Sleep(2 * time.Second)25 }26 }()27 http.ListenAndServe(":8080", nil)28}29import (30var (31 myGauge = promauto.NewGauge(prometheus.GaugeOpts{32 })33func main() {34 http.Handle("/metrics", promhttp.Handler())35 go func() {36 for {37 myGauge.Add(10)38 time.Sleep(2 * time.Second)39 }40 }()41 http.ListenAndServe(":8080", nil)42}43import (
InSpan
Using AI Code Generation
1import (2func main() {3 cfg := &config.Configuration{4 Sampler: &config.SamplerConfig{5 },6 Reporter: &config.ReporterConfig{7 },8 }9 tracer, closer, err := cfg.NewTracer(10 config.Logger(jaeger.StdLogger),11 config.Metrics(metrics.NullFactory),12 if err != nil {13 fmt.Printf("Could not initialize jaeger tracer: %s14", err.Error())15 }16 defer closer.Close()17 span := tracer.StartSpan("parent")18 gauge := metrics.Gauge(metrics.Options{Name: "testGauge"})19 timer := metrics.Timer(metrics.Options{Name: "testTimer"})20 counter := metrics.Counter(metrics.Options{Name: "testCounter"})21 histogram := metrics.Histogram(metrics.Options{Name: "testHistogram"})22 metric := metrics.Metric(metrics.Options{Name: "testMetric"})23 metric1 := metrics.Metric(metrics.Options{Name: "testMetric1"})24 metric2 := metrics.Metric(metrics.Options{Name: "testMetric2"})25 metric3 := metrics.Metric(metrics.Options{Name: "testMetric3"})26 metric4 := metrics.Metric(metrics.Options{Name: "testMetric4"})27 metric5 := metrics.Metric(metrics.Options{Name: "testMetric5"})28 metric6 := metrics.Metric(metrics.Options{Name: "testMetric6"})29 metric7 := metrics.Metric(metrics.Options{Name: "testMetric7"})30 metric8 := metrics.Metric(metrics.Options{Name: "testMetric8"})
InSpan
Using AI Code Generation
1import (2func main() {3 gauge := prometheus.NewGauge(prometheus.GaugeOpts{4 })5 gauge.Set(5)6}7cannot use gauge (type prometheus.Gauge) as type prometheus.Gauge in argument to gauge.InSpan8Your name to display (optional):9Your name to display (optional):10import (11func main() {12 gauge := prometheus.NewGauge(prometheus.GaugeOpts{13 })14 gauge.Set(5)15}16Your name to display (optional):
InSpan
Using AI Code Generation
1import (2func main() {3 scope := metricstest.NewFactory(0)4 gauge := scope.Gauge("gauge", nil)5 gauge.Update(5)6 fmt.Println(gauge.InSpan(2, 4))7 fmt.Println(gauge.InSpan(6, 8))8 time.Sleep(5 * time.Second)9}10import (11func main() {12 scope := metricstest.NewFactory(0)13 gauge := scope.Gauge("gauge", nil)14 gauge.Update(5)15 fmt.Println(gauge.InSpan(2, 4))16 fmt.Println(gauge.InSpan(6, 8))17 time.Sleep(5 * time.Second)18 fmt.Println(gauge.InSpan(2, 4))19 fmt.Println(gauge.InSpan(6, 8))20}21import (22func main() {23 scope := metricstest.NewFactory(0)24 gauge := scope.Gauge("gauge", nil)25 gauge.Update(5)26 fmt.Println(gauge.InSpan(2, 4))27 fmt.Println(gauge.InSpan(6, 8))28 time.Sleep(5 * time.Second)29 gauge.Update(5)30 fmt.Println(gauge.InSpan(2, 4))31 fmt.Println(gauge.InSpan(6, 8))32}
InSpan
Using AI Code Generation
1import (2func main() {3 var g = prometheus.NewGauge(prometheus.GaugeOpts{4 })5 g.Set(10)6 fmt.Println(g.InSpan(5, 15))7}8import (9func main() {10 var g = prometheus.NewGauge(prometheus.GaugeOpts{11 })12 g.Add(10)13 fmt.Println(g.InSpan(5, 15))14}15import (16func main() {17 var g = prometheus.NewGauge(prometheus.GaugeOpts{18 })19 g.SetToCurrentTime()20 fmt.Println(g.InSpan(5, 15))21}22import (23func main() {24 var g = prometheus.NewGauge(prometheus.GaugeOpts{25 })26 g.Set(10)27 fmt.Println(g.InSpan(5, 15))28}29import (30func main() {
InSpan
Using AI Code Generation
1import (2func main() {3 scope, closer := tally.NewRootScope(tally.ScopeOptions{4 Tags: map[string]string{"host": "test"},5 CachedReporter: tally.NewInMemoryStatsReporter(),6 }, 1*time.Second)7 defer closer.Close()8 scope.Counter("counter").Inc(1)9 scope.Timer("timer").Record(time.Second)10 scope.Gauge("gauge").Update(42)11 scope.Gauge("gauge").Update(43)12 scope.Gauge("gauge").Update(44)13 scope.Gauge("gauge").Update(45)14 scope.Gauge("gauge").Update(46)15 scope.Gauge("gauge").Update(47)16 scope.Gauge("gauge").Update(48)17 scope.Gauge("gauge").Update(49)18 scope.Gauge("gauge").Update(50)19 scope.Gauge("gauge").Update(51)20 scope.Gauge("gauge").Update(52)21 scope.Gauge("gauge").Update(53)22 scope.Gauge("gauge").Update(54)23 scope.Gauge("gauge").Update(55)24 scope.Gauge("gauge").Update(56)25 scope.Gauge("gauge").Update(57)26 scope.Gauge("gauge").Update(58)27 scope.Gauge("gauge").Update(59)28 scope.Gauge("gauge").Update(60)29 scope.Gauge("gauge").Update(61)30 scope.Gauge("gauge").Update(62)31 scope.Gauge("gauge").Update(63)32 scope.Gauge("gauge").Update(64)33 scope.Gauge("gauge").Update(65)34 scope.Gauge("gauge").Update(66)35 scope.Gauge("gauge").Update(67)36 scope.Gauge("gauge").Update(68)37 scope.Gauge("gauge").Update(69)38 scope.Gauge("gauge").Update(70)39 scope.Gauge("gauge").Update(71)40 scope.Gauge("gauge").Update(72)41 scope.Gauge("gauge").Update(73)42 scope.Gauge("gauge").Update(74)43 scope.Gauge("gauge").Update(75)44 scope.Gauge("gauge").Update(76)45 scope.Gauge("gauge
InSpan
Using AI Code Generation
1import (2func main() {3 g := NewGauge(0, 100)4}5import (6func main() {7 g := NewGauge(0, 100)8}9import (10func main() {11 g := NewGauge(0, 100)12}13import (14func main() {15 g := NewGauge(0, 100)16}17import (18func main() {19 g := NewGauge(0, 100)20}21import (22func main() {23 g := NewGauge(0, 100)24}25import (26func main() {27 g := NewGauge(0, 100)28}
InSpan
Using AI Code Generation
1import (2func main() {3 tracer, closer := jaeger.NewTracer(4 jaeger.NewConstSampler(true),5 jaeger.NewNullReporter(),6 defer closer.Close()7 span := tracer.StartSpan("example")8 defer span.Finish()9 fmt.Println(span.Context().(jaeger.SpanContext).TraceID().InSpan(1))10}11import (12func main() {13 tracer, closer := jaeger.NewTracer(14 jaeger.NewConstSampler(true),15 jaeger.NewNullReporter(),16 defer closer.Close()17 span := tracer.StartSpan("example")18 defer span.Finish()19 fmt.Println(span.Context().(jaeger.SpanContext).TraceID().InSpan(1))20}21import (22func main() {23 tracer, closer := jaeger.NewTracer(24 jaeger.NewConstSampler(true),25 jaeger.NewNullReporter(),26 defer closer.Close()27 span := tracer.StartSpan("example")28 defer span.Finish()29 fmt.Println(span.Context
InSpan
Using AI Code Generation
1import (2func main() {3 g := gauge.NewGauge("test", "test", []string{"test"})4 g.Set(10)5 if g.InSpan(5, 15) {6 fmt.Println("InSpan")7 } else {8 fmt.Println("Not in span")9 }10}11import (12func main() {13 g := gauge.NewGauge("test", "test", []string{"test"})14 g.Set(10)15 if g.InSpan(5, 15) {16 fmt.Println("InSpan")17 } else {18 fmt.Println("Not in span")19 }20}21import (22func main() {23 g := gauge.NewGauge("test", "test", []string{"test"})24 g.Set(10)25 if g.InSpan(5, 15) {26 fmt.Println("InSpan")27 } else {28 fmt.Println("Not in span")29 }30}31import (32func main() {33 g := gauge.NewGauge("test", "test", []string{"test"})34 g.Set(10)35 if g.InSpan(5, 15) {36 fmt.Println("InSpan")37 } else {38 fmt.Println("Not in span")39 }40}41import (42func main() {43 g := gauge.NewGauge("test", "test", []string{"test"})44 g.Set(10)45 if g.InSpan(5, 15) {46 fmt.Println("InSpan")47 } else {48 fmt.Println("Not in span")49 }50}51import (52func main() {53 g := gauge.NewGauge("test", "test",
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!