MCPcopy Create free account
hub / github.com/bitly/statsdaemon / parseLine

Function parseLine

statsdaemon.go:441–526  ·  view source on GitHub ↗
(line []byte)

Source from the content-addressed store, hash-verified

439}
440
441func parseLine(line []byte) *Packet {
442 split := bytes.SplitN(line, []byte{'|'}, 3)
443 if len(split) < 2 {
444 logParseFail(line)
445 return nil
446 }
447
448 keyval := split[0]
449 typeCode := string(split[1])
450
451 sampling := float32(1)
452 if typeCode == "c" || typeCode == "ms" {
453 if len(split) == 3 && len(split[2]) > 0 && split[2][0] == '@' {
454 f64, err := strconv.ParseFloat(string(split[2][1:]), 32)
455 if err != nil {
456 log.Printf(
457 "ERROR: failed to ParseFloat %s - %s",
458 string(split[2][1:]),
459 err,
460 )
461 return nil
462 }
463 sampling = float32(f64)
464 }
465 }
466
467 split = bytes.SplitN(keyval, []byte{':'}, 2)
468 if len(split) < 2 {
469 logParseFail(line)
470 return nil
471 }
472 name := split[0]
473 val := split[1]
474 if len(val) == 0 {
475 logParseFail(line)
476 return nil
477 }
478
479 var (
480 err error
481 floatval float64
482 strval string
483 )
484
485 switch typeCode {
486 case "c":
487 floatval, err = strconv.ParseFloat(string(val), 64)
488 if err != nil {
489 log.Printf("ERROR: failed to ParseFloat %s - %s", string(val), err)
490 return nil
491 }
492 case "g":
493 var s string
494
495 if val[0] == '+' || val[0] == '-' {
496 strval = string(val[0])
497 s = string(val[1:])
498 } else {

Callers 14

NextMethod · 0.85
TestParseLineGaugeFunction · 0.85
TestParseLineCountFunction · 0.85
TestParseLineTimerFunction · 0.85
TestParseLineSetFunction · 0.85
TestParseLineMiscFunction · 0.85
BenchmarkParseLineGaugeFunction · 0.85
BenchmarkParseLineTimerFunction · 0.85
BenchmarkParseLineSetFunction · 0.85

Calls 2

logParseFailFunction · 0.85
sanitizeBucketFunction · 0.85

Tested by 13

TestParseLineGaugeFunction · 0.68
TestParseLineCountFunction · 0.68
TestParseLineTimerFunction · 0.68
TestParseLineSetFunction · 0.68
TestParseLineMiscFunction · 0.68
BenchmarkParseLineGaugeFunction · 0.68
BenchmarkParseLineTimerFunction · 0.68
BenchmarkParseLineSetFunction · 0.68