How to use Description method of statsd Package

Best K6 code snippet using statsd.Description

statsd_parser_test.go

Source:statsd_parser_test.go Github

copy

Full Screen

...431 for n, k := range labelKeys {432 kvs = append(kvs, attribute.String(k, labelValue[n]))433 }434 return statsDMetric{435 description: statsDMetricDescription{436 name: name,437 metricType: metricType,438 attrs: attribute.NewSetWithSortable(kvs, &sortable),439 },440 asFloat: asFloat,441 addition: addition,442 unit: "",443 sampleRate: sampleRate,444 }445 }446 return statsDMetric{447 description: statsDMetricDescription{448 name: name,449 metricType: metricType,450 },451 asFloat: asFloat,452 addition: addition,453 unit: "",454 sampleRate: sampleRate,455 }456}457func testDescription(name string, metricType MetricType, keys []string, values []string) statsDMetricDescription {458 var kvs []attribute.KeyValue459 var sortable attribute.Sortable460 for n, k := range keys {461 kvs = append(kvs, attribute.String(k, values[n]))462 }463 return statsDMetricDescription{464 name: name,465 metricType: metricType,466 attrs: attribute.NewSetWithSortable(kvs, &sortable),467 }468}469func TestStatsDParser_Aggregate(t *testing.T) {470 timeNowFunc = func() time.Time {471 return time.Unix(711, 0)472 }473 tests := []struct {474 name string475 input []string476 expectedGauges map[statsDMetricDescription]pmetric.ScopeMetrics477 expectedCounters map[statsDMetricDescription]pmetric.ScopeMetrics478 expectedTimer []pmetric.ScopeMetrics479 err error480 }{481 {482 name: "parsedMetric error: empty metric value",483 input: []string{484 "test.metric:|c",485 },486 err: errors.New("empty metric value"),487 },488 {489 name: "parsedMetric error: empty metric name",490 input: []string{491 ":42|c",492 },493 err: errors.New("empty metric name"),494 },495 {496 name: "gauge plus",497 input: []string{498 "statsdTestMetric1:1|g|#mykey:myvalue",499 "statsdTestMetric2:2|g|#mykey:myvalue",500 "statsdTestMetric1:+1|g|#mykey:myvalue",501 "statsdTestMetric1:+100|g|#mykey:myvalue",502 "statsdTestMetric1:+10000|g|#mykey:myvalue",503 "statsdTestMetric2:+5|g|#mykey:myvalue",504 "statsdTestMetric2:+500|g|#mykey:myvalue",505 },506 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{507 testDescription("statsdTestMetric1", "g",508 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10102, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),509 testDescription("statsdTestMetric2", "g",510 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric2", 507, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),511 },512 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{},513 expectedTimer: []pmetric.ScopeMetrics{},514 },515 {516 name: "gauge minus",517 input: []string{518 "statsdTestMetric1:5000|g|#mykey:myvalue",519 "statsdTestMetric2:10|g|#mykey:myvalue",520 "statsdTestMetric1:-1|g|#mykey:myvalue",521 "statsdTestMetric2:-5|g|#mykey:myvalue",522 "statsdTestMetric1:-1|g|#mykey:myvalue",523 "statsdTestMetric1:-1|g|#mykey:myvalue",524 "statsdTestMetric1:-10|g|#mykey:myvalue",525 "statsdTestMetric1:-1|g|#mykey:myvalue",526 "statsdTestMetric1:-100|g|#mykey:myvalue",527 "statsdTestMetric1:-1|g|#mykey:myvalue",528 },529 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{530 testDescription("statsdTestMetric1", "g",531 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 4885, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),532 testDescription("statsdTestMetric2", "g",533 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric2", 5, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),534 },535 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{},536 expectedTimer: []pmetric.ScopeMetrics{},537 },538 {539 name: "gauge plus and minus",540 input: []string{541 "statsdTestMetric1:5000|g|#mykey:myvalue",542 "statsdTestMetric1:4000|g|#mykey:myvalue",543 "statsdTestMetric1:+500|g|#mykey:myvalue",544 "statsdTestMetric1:-400|g|#mykey:myvalue",545 "statsdTestMetric1:+2|g|#mykey:myvalue",546 "statsdTestMetric1:-1|g|#mykey:myvalue",547 "statsdTestMetric2:365|g|#mykey:myvalue",548 "statsdTestMetric2:+300|g|#mykey:myvalue",549 "statsdTestMetric2:-200|g|#mykey:myvalue",550 "statsdTestMetric2:200|g|#mykey:myvalue",551 },552 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{553 testDescription("statsdTestMetric1", "g",554 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 4101, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),555 testDescription("statsdTestMetric2", "g",556 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric2", 200, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),557 },558 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{},559 expectedTimer: []pmetric.ScopeMetrics{},560 },561 {562 name: "counter with increment and sample rate",563 input: []string{564 "statsdTestMetric1:3000|c|#mykey:myvalue",565 "statsdTestMetric1:4000|c|#mykey:myvalue",566 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",567 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",568 },569 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{},570 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{571 testDescription("statsdTestMetric1", "c",572 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric1", 7000, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), false, time.Unix(711, 0), time.Unix(611, 0)),573 testDescription("statsdTestMetric2", "c",574 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric2", 50, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), false, time.Unix(711, 0), time.Unix(611, 0)),575 },576 expectedTimer: []pmetric.ScopeMetrics{},577 },578 {579 name: "counter and gauge: one gauge and two counters",580 input: []string{581 "statsdTestMetric1:3000|c|#mykey:myvalue",582 "statsdTestMetric1:500|g|#mykey:myvalue",583 "statsdTestMetric1:400|g|#mykey:myvalue",584 "statsdTestMetric1:+20|g|#mykey:myvalue",585 "statsdTestMetric1:4000|c|#mykey:myvalue",586 "statsdTestMetric1:-1|g|#mykey:myvalue",587 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",588 "statsdTestMetric1:+2|g|#mykey:myvalue",589 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",590 },591 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{592 testDescription("statsdTestMetric1", "g",593 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 421, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),594 },595 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{596 testDescription("statsdTestMetric1", "c",597 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric1", 7000, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), false, time.Unix(711, 0), time.Unix(611, 0)),598 testDescription("statsdTestMetric2", "c",599 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric2", 50, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), false, time.Unix(711, 0), time.Unix(611, 0)),600 },601 expectedTimer: []pmetric.ScopeMetrics{},602 },603 {604 name: "counter and gauge: 2 gauges and 2 counters",605 input: []string{606 "statsdTestMetric1:500|g|#mykey:myvalue",607 "statsdTestMetric1:400|g|#mykey:myvalue1",608 "statsdTestMetric1:300|g|#mykey:myvalue",609 "statsdTestMetric1:-1|g|#mykey:myvalue1",610 "statsdTestMetric1:+20|g|#mykey:myvalue",611 "statsdTestMetric1:-1|g|#mykey:myvalue",612 "statsdTestMetric1:20|c|@0.1|#mykey:myvalue",613 "statsdTestMetric2:50|c|#mykey:myvalue",614 "statsdTestMetric1:15|c|#mykey:myvalue",615 "statsdTestMetric2:5|c|@0.2|#mykey:myvalue",616 },617 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{618 testDescription("statsdTestMetric1", "g",619 []string{"mykey"}, []string{"myvalue"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 319, false, "g", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),620 testDescription("statsdTestMetric1", "g",621 []string{"mykey"}, []string{"myvalue1"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 399, false, "g", 0, []string{"mykey"}, []string{"myvalue1"}), time.Unix(711, 0)),622 },623 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{624 testDescription("statsdTestMetric1", "c",625 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric1", 215, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), false, time.Unix(711, 0), time.Unix(611, 0)),626 testDescription("statsdTestMetric2", "c",627 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric2", 75, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), false, time.Unix(711, 0), time.Unix(611, 0)),628 },629 expectedTimer: []pmetric.ScopeMetrics{},630 },631 {632 name: "counter and gauge: 2 timings and 2 histograms",633 input: []string{634 "statsdTestMetric1:500|ms|#mykey:myvalue",635 "statsdTestMetric1:400|h|#mykey:myvalue",636 "statsdTestMetric1:300|ms|#mykey:myvalue",637 "statsdTestMetric1:10|h|@0.1|#mykey:myvalue",638 },639 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{},640 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{},641 expectedTimer: []pmetric.ScopeMetrics{642 buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 500, false, "ms", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),643 buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 400, false, "h", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),644 buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 300, false, "ms", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),645 buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10, false, "h", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),646 },647 },648 }649 for _, tt := range tests {650 t.Run(tt.name, func(t *testing.T) {651 var err error652 p := &StatsDParser{}653 p.Initialize(false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})654 p.lastIntervalTime = time.Unix(611, 0)655 for _, line := range tt.input {656 err = p.Aggregate(line)657 }658 if tt.err != nil {659 assert.Equal(t, tt.err, err)660 } else {661 assert.Equal(t, tt.expectedGauges, p.gauges)662 assert.Equal(t, tt.expectedCounters, p.counters)663 assert.Equal(t, tt.expectedTimer, p.timersAndDistributions)664 }665 })666 }667}668func TestStatsDParser_AggregateWithMetricType(t *testing.T) {669 timeNowFunc = func() time.Time {670 return time.Unix(711, 0)671 }672 tests := []struct {673 name string674 input []string675 expectedGauges map[statsDMetricDescription]pmetric.ScopeMetrics676 expectedCounters map[statsDMetricDescription]pmetric.ScopeMetrics677 err error678 }{679 {680 name: "gauge plus",681 input: []string{682 "statsdTestMetric1:1|g|#mykey:myvalue",683 "statsdTestMetric2:2|g|#mykey:myvalue",684 "statsdTestMetric1:+1|g|#mykey:myvalue",685 "statsdTestMetric1:+100|g|#mykey:myvalue",686 "statsdTestMetric1:+10000|g|#mykey:myvalue",687 "statsdTestMetric2:+5|g|#mykey:myvalue",688 "statsdTestMetric2:+500|g|#mykey:myvalue",689 },690 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{691 testDescription("statsdTestMetric1", "g",692 []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10102, false, "g", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}), time.Unix(711, 0)),693 testDescription("statsdTestMetric2", "g",694 []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}): buildGaugeMetric(testStatsDMetric("statsdTestMetric2", 507, false, "g", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}), time.Unix(711, 0)),695 },696 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{},697 },698 {699 name: "counter with increment and sample rate",700 input: []string{701 "statsdTestMetric1:3000|c|#mykey:myvalue",702 "statsdTestMetric1:4000|c|#mykey:myvalue",703 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",704 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",705 },706 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{},707 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{708 testDescription("statsdTestMetric1", "c",709 []string{"mykey", "metric_type"}, []string{"myvalue", "counter"}): buildCounterMetric(testStatsDMetric("statsdTestMetric1", 7000, false, "c", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "counter"}), false, time.Unix(711, 0), time.Unix(611, 0)),710 testDescription("statsdTestMetric2", "c",711 []string{"mykey", "metric_type"}, []string{"myvalue", "counter"}): buildCounterMetric(testStatsDMetric("statsdTestMetric2", 50, false, "c", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "counter"}), false, time.Unix(711, 0), time.Unix(611, 0)),712 },713 },714 }715 for _, tt := range tests {716 t.Run(tt.name, func(t *testing.T) {717 var err error718 p := &StatsDParser{}719 p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})720 p.lastIntervalTime = time.Unix(611, 0)721 for _, line := range tt.input {722 err = p.Aggregate(line)723 }724 if tt.err != nil {725 assert.Equal(t, tt.err, err)726 } else {727 assert.Equal(t, tt.expectedGauges, p.gauges)728 assert.Equal(t, tt.expectedCounters, p.counters)729 }730 })731 }732}733func TestStatsDParser_AggregateWithIsMonotonicCounter(t *testing.T) {734 timeNowFunc = func() time.Time {735 return time.Unix(711, 0)736 }737 tests := []struct {738 name string739 input []string740 expectedGauges map[statsDMetricDescription]pmetric.ScopeMetrics741 expectedCounters map[statsDMetricDescription]pmetric.ScopeMetrics742 err error743 }{744 {745 name: "counter with increment and sample rate",746 input: []string{747 "statsdTestMetric1:3000|c|#mykey:myvalue",748 "statsdTestMetric1:4000|c|#mykey:myvalue",749 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",750 "statsdTestMetric2:20|c|@0.8|#mykey:myvalue",751 },752 expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{},753 expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{754 testDescription("statsdTestMetric1", "c",755 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric1", 7000, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), true, time.Unix(711, 0), time.Unix(611, 0)),756 testDescription("statsdTestMetric2", "c",757 []string{"mykey"}, []string{"myvalue"}): buildCounterMetric(testStatsDMetric("statsdTestMetric2", 50, false, "c", 0, []string{"mykey"}, []string{"myvalue"}), true, time.Unix(711, 0), time.Unix(611, 0)),758 },759 },760 }761 for _, tt := range tests {762 t.Run(tt.name, func(t *testing.T) {763 var err error764 p := &StatsDParser{}765 p.Initialize(false, true, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})766 p.lastIntervalTime = time.Unix(611, 0)767 for _, line := range tt.input {768 err = p.Aggregate(line)769 }770 if tt.err != nil {771 assert.Equal(t, tt.err, err)772 } else {773 assert.Equal(t, tt.expectedGauges, p.gauges)774 assert.Equal(t, tt.expectedCounters, p.counters)775 }776 })777 }778}779func TestStatsDParser_AggregateTimerWithSummary(t *testing.T) {780 timeNowFunc = func() time.Time {781 return time.Unix(711, 0)782 }783 tests := []struct {784 name string785 input []string786 expectedSummaries map[statsDMetricDescription]summaryMetric787 err error788 }{789 {790 name: "timer",791 input: []string{792 "statsdTestMetric1:1|ms|#mykey:myvalue",793 "statsdTestMetric2:2|ms|#mykey:myvalue",794 "statsdTestMetric1:1|ms|#mykey:myvalue",795 "statsdTestMetric1:10|ms|#mykey:myvalue",796 "statsdTestMetric1:20|ms|#mykey:myvalue",797 "statsdTestMetric2:5|ms|#mykey:myvalue",798 "statsdTestMetric2:10|ms|#mykey:myvalue",799 "statsdTestMetric1:20|ms|#mykey:myvalue",800 },801 expectedSummaries: map[statsDMetricDescription]summaryMetric{802 testDescription("statsdTestMetric1", "ms",803 []string{"mykey"}, []string{"myvalue"}): {804 points: []float64{1, 1, 10, 20, 20},805 weights: []float64{1, 1, 1, 1, 1},806 },807 testDescription("statsdTestMetric2", "ms",808 []string{"mykey"}, []string{"myvalue"}): {809 points: []float64{2, 5, 10},810 weights: []float64{1, 1, 1},811 },812 },813 },814 {815 name: "histogram",816 input: []string{817 "statsdTestMetric1:1|h|#mykey:myvalue",818 "statsdTestMetric2:2|h|#mykey:myvalue",819 "statsdTestMetric1:1|h|#mykey:myvalue",820 "statsdTestMetric1:10|h|#mykey:myvalue",821 "statsdTestMetric1:20|h|#mykey:myvalue",822 "statsdTestMetric2:5|h|#mykey:myvalue",823 "statsdTestMetric2:10|h|#mykey:myvalue",824 },825 expectedSummaries: map[statsDMetricDescription]summaryMetric{826 testDescription("statsdTestMetric1", "h",827 []string{"mykey"}, []string{"myvalue"}): {828 points: []float64{1, 1, 10, 20},829 weights: []float64{1, 1, 1, 1},830 },831 testDescription("statsdTestMetric2", "h",832 []string{"mykey"}, []string{"myvalue"}): {833 points: []float64{2, 5, 10},834 weights: []float64{1, 1, 1},835 },836 },837 },838 {839 name: "histogram_sampled",840 input: []string{841 "statsdTestMetric1:300|h|@0.1|#mykey:myvalue",842 "statsdTestMetric1:100|h|@0.05|#mykey:myvalue",843 "statsdTestMetric1:300|h|@0.1|#mykey:myvalue",844 "statsdTestMetric1:200|h|@0.01|#mykey:myvalue",845 },846 expectedSummaries: map[statsDMetricDescription]summaryMetric{847 testDescription("statsdTestMetric1", "h",848 []string{"mykey"}, []string{"myvalue"}): {849 points: []float64{300, 100, 300, 200},850 weights: []float64{10, 20, 10, 100},851 },852 },853 },854 }855 for _, tt := range tests {856 t.Run(tt.name, func(t *testing.T) {857 var err error858 p := &StatsDParser{}859 p.Initialize(false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "summary"}})860 for _, line := range tt.input {861 err = p.Aggregate(line)862 }863 if tt.err != nil {864 assert.Equal(t, tt.err, err)865 } else {866 assert.EqualValues(t, tt.expectedSummaries, p.summaries)867 }868 })869 }870}871func TestStatsDParser_Initialize(t *testing.T) {872 p := &StatsDParser{}873 p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})874 teststatsdDMetricdescription := statsDMetricDescription{875 name: "test",876 metricType: "g",877 attrs: *attribute.EmptySet()}878 p.gauges[teststatsdDMetricdescription] = pmetric.ScopeMetrics{}879 assert.Equal(t, 1, len(p.gauges))880 assert.Equal(t, GaugeObserver, p.observeTimer)881 assert.Equal(t, GaugeObserver, p.observeHistogram)882}883func TestStatsDParser_GetMetricsWithMetricType(t *testing.T) {884 p := &StatsDParser{}885 p.Initialize(true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})886 p.gauges[testDescription("statsdTestMetric1", "g",887 []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"})] =888 buildGaugeMetric(testStatsDMetric("testGauge1", 1, false, "g", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}), time.Unix(711, 0))889 p.gauges[testDescription("statsdTestMetric1", "g",890 []string{"mykey2", "metric_type"}, []string{"myvalue2", "gauge"})] =891 buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10102, false, "g", 0, []string{"mykey2", "metric_type"}, []string{"myvalue2", "gauge"}), time.Unix(711, 0))892 p.counters[testDescription("statsdTestMetric1", "g",893 []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"})] =894 buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10102, false, "g", 0, []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"}), time.Unix(711, 0))895 p.timersAndDistributions = append(p.timersAndDistributions, buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10102, false, "ms", 0, []string{"mykey2", "metric_type"}, []string{"myvalue2", "gauge"}), time.Unix(711, 0)))896 p.summaries = map[statsDMetricDescription]summaryMetric{897 testDescription("statsdTestMetric1", "h",898 []string{"mykey"}, []string{"myvalue"}): {899 points: []float64{1, 1, 10, 20},900 weights: []float64{1, 1, 1, 1},901 }}902 metrics := p.GetMetrics()903 assert.Equal(t, 5, metrics.ResourceMetrics().At(0).ScopeMetrics().Len())904}905func TestStatsDParser_Mappings(t *testing.T) {906 type testCase struct {907 name string908 mapping []TimerHistogramMapping909 expect map[string]string910 }911 for _, tc := range []testCase{...

Full Screen

Full Screen

metrics_test.go

Source:metrics_test.go Github

copy

Full Screen

1package raw_test2import (3 "encoding/json"4 "testing"5 "github.com/runatlantis/atlantis/server/core/config/raw"6 "github.com/stretchr/testify/assert"7 "gopkg.in/yaml.v2"8)9func TestMetrics_Unmarshal(t *testing.T) {10 t.Run("yaml", func(t *testing.T) {11 rawYaml := `12statsd:13 host: 127.0.0.114 port: 812515prometheus:16 endpoint: /metrics17`18 var result raw.Metrics19 err := yaml.UnmarshalStrict([]byte(rawYaml), &result)20 assert.NoError(t, err)21 })22 t.Run("json", func(t *testing.T) {23 rawJSON := `24{25 "statsd": {26 "host": "127.0.0.1",27 "port": "8125"28 },29 "prometheus": {30 "endpoint": "/metrics"31 }32} 33`34 var result raw.Metrics35 err := json.Unmarshal([]byte(rawJSON), &result)36 assert.NoError(t, err)37 })38}39func TestMetrics_Validate_Success(t *testing.T) {40 cases := []struct {41 description string42 subject raw.Metrics43 }{44 {45 description: "success with stats config",46 subject: raw.Metrics{47 Statsd: &raw.Statsd{48 Host: "127.0.0.1",49 Port: "8125",50 },51 },52 },53 {54 description: "missing stats",55 },56 {57 description: "success with prometheus config",58 subject: raw.Metrics{59 Prometheus: &raw.Prometheus{60 Endpoint: "/metrics",61 },62 },63 },64 {65 description: "success with both configs",66 subject: raw.Metrics{67 Statsd: &raw.Statsd{68 Host: "127.0.0.1",69 Port: "8125",70 },71 Prometheus: &raw.Prometheus{72 Endpoint: "/metrics",73 },74 },75 },76 }77 for _, c := range cases {78 t.Run(c.description, func(t *testing.T) {79 assert.NoError(t, c.subject.Validate())80 })81 }82}83func TestMetrics_Validate_Error(t *testing.T) {84 cases := []struct {85 description string86 subject raw.Metrics87 }{88 {89 description: "missing host",90 subject: raw.Metrics{91 Statsd: &raw.Statsd{92 Port: "8125",93 },94 },95 },96 {97 description: "missing port",98 subject: raw.Metrics{99 Statsd: &raw.Statsd{100 Host: "127.0.0.1",101 },102 },103 },104 {105 description: "invalid port",106 subject: raw.Metrics{107 Statsd: &raw.Statsd{108 Host: "127.0.0.1",109 Port: "string",110 },111 },112 },113 {114 description: "invalid host",115 subject: raw.Metrics{116 Statsd: &raw.Statsd{117 Host: "127.0.1",118 Port: "8125",119 },120 },121 },122 {123 description: "invalid endpoint",124 subject: raw.Metrics{125 Prometheus: &raw.Prometheus{126 Endpoint: "",127 },128 },129 },130 }131 for _, c := range cases {132 t.Run(c.description, func(t *testing.T) {133 assert.Error(t, c.subject.Validate())134 })135 }136}...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...10var description = `11kqm [OPTIONS] host:port [host:port]...12KQM is a command line tool to monitor Apache Kafka for lags.13It also comes with an option to send the lag statistics to Statsd.14Option Description15------ -----------16--statsd-addr Use this option if you need to send17 the lag statistics to Statsd.18 Default: localhost:812519--statsd-prefix Set a prefix for the data being sent20 to Statsd.21 Default: kqm22--interval Specify the interval of calculating23 the lag statistics (in seconds).24 Default: 60 seconds25--log-level Specify the level of severity of the26 logger. Levels are as follows:27 0 - Panic28 1 - Fatal...

Full Screen

Full Screen

Description

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client, err := statsd.New(statsd.Address("localhost:8125"))4 if err != nil {5 fmt.Println(err)6 }7 defer client.Close()8 client.Increment("requests")9 client.Gauge("temperature", 22)10 client.Timing("request.duration", time.Millisecond*123)11 client.Description("this is a description")12}13import (14func main() {15 client, err := statsd.New(statsd.Address("localhost:8125"))16 if err != nil {17 fmt.Println(err)18 }19 defer client.Close()20 client.Increment("requests")21 client.Gauge("temperature", 22)22 client.Timing("request.duration", time.Millisecond*123)23 client.Description("this is a description")24}25import (26func main() {27 client, err := statsd.New(statsd.Address("localhost:8125"))28 if err != nil {29 fmt.Println(err)30 }31 defer client.Close()32 client.Increment("requests")33 client.Gauge("temperature", 22)34 client.Timing("request.duration", time.Millisecond*123)35 client.Description("this is a description")36}37import (38func main() {39 client, err := statsd.New(statsd.Address("localhost:8125"))40 if err != nil {41 fmt.Println(err)42 }43 defer client.Close()44 client.Increment("requests")45 client.Gauge("temperature", 22)46 client.Timing("request.duration", time.Millisecond*123)47 client.Description("this is a description")48}

Full Screen

Full Screen

Description

Using AI Code Generation

copy

Full Screen

1import "github.com/abc/def"2import "github.com/abc/def"3import "github.com/abc/def"4func Description() string{5}6import "github.com/abc/def"7import "github.com/abc/def"8import "github.com/abc/def"9func Description() string{10}11import "github.com/abc/def"12import "github.com/abc/def"

Full Screen

Full Screen

Description

Using AI Code Generation

copy

Full Screen

1type statsd struct {2}3func (s statsd) Description() string {4}5type statsd struct {6}7func (s *statsd) Description() string {8}9func (s *statsd) SetDescription(desc string) {10}11s := &statsd{}12s.SetDescription("foo")

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful