How to use AddTags method of gauge Package

Best Gauge code snippet using gauge.AddTags

metrics_test.go

Source:metrics_test.go Github

copy

Full Screen

...32	tags := map[string]string{"k1": "v1", "k2": "v2"}33	if len(cb.Tags) != 0 {34		t.Errorf("bad default tags: %v", cb.Tags)35	}36	cb.AddTags(tags)37	if !reflect.DeepEqual(cb.Tags, tags) {38		t.Errorf("bad tags: %v", cb.Tags)39	}40}41func TestCounterN(t *testing.T) {42	metric := "hujter.test"43	cnt := 244	cb := CounterNEBuilder(metric, cnt)45	if cb.Metric != metric {46		t.Errorf("bad metric: %s", cb.Metric)47	}48	if cb.Value != fmt.Sprintf("%d", cnt) {49		t.Errorf("bad value: %s", cb.Value)50	}51	if cb.Aggregator != "ce" {52		t.Errorf("bad aggregator: %s", cb.Aggregator)53	}54	// ns55	namepace := "1"56	if cb.Namespace != "" {57		t.Errorf("bad default ns: %s", cb.Namespace)58	}59	cb.Ns(namepace)60	if cb.Namespace != namepace {61		t.Errorf("bad ns: %s", cb.Namespace)62	}63	// tags64	tags := map[string]string{"k1": "v1", "k2": "v2"}65	if len(cb.Tags) != 0 {66		t.Errorf("bad default tags: %v", cb.Tags)67	}68	cb.AddTags(tags)69	if !reflect.DeepEqual(cb.Tags, tags) {70		t.Errorf("bad tags: %v", cb.Tags)71	}72}73func TestGauge(t *testing.T) {74	metric := "gauge.test"75	val := 94.676	gauge := GaugeBuilder(metric, val)77	if gauge.Metric != metric {78		t.Errorf("bad metric: %s", gauge.Metric)79	}80	if gauge.Value != fmt.Sprintf("%f", val) {81		t.Errorf("bad value: %s", gauge.Value)82	}83	if gauge.Aggregator != "g" {84		t.Errorf("bad aggregator: %s", gauge.Aggregator)85	}86	// ns87	namepace := "1"88	if gauge.Namespace != "" {89		t.Errorf("bad default ns: %s", gauge.Namespace)90	}91	gauge.Ns(namepace)92	if gauge.Namespace != namepace {93		t.Errorf("bad ns: %s", gauge.Namespace)94	}95	// tags96	tags := map[string]string{"k1": "v1", "k2": "v2"}97	if len(gauge.Tags) != 0 {98		t.Errorf("bad default tags: %v", gauge.Tags)99	}100	gauge.AddTags(tags)101	if !reflect.DeepEqual(gauge.Tags, tags) {102		t.Errorf("bad tags: %v", gauge.Tags)103	}104}105func TestRatio(t *testing.T) {106	metric := "ratio.test"107	rt := RatioBuilder(metric, "ok")108	if rt.Metric != metric {109		t.Errorf("bad metric: %s", rt.Metric)110	}111	if rt.Value != "ok" {112		t.Errorf("bad value: %s", rt.Value)113	}114	if rt.Aggregator != "rt" {115		t.Errorf("bad aggregator: %s", rt.Aggregator)116	}117	// ns118	namepace := "1"119	if rt.Namespace != "" {120		t.Errorf("bad default ns: %s", rt.Namespace)121	}122	rt.Ns(namepace)123	if rt.Namespace != namepace {124		t.Errorf("bad ns: %s", rt.Namespace)125	}126}127func TestPercentile(t *testing.T) {128	metric := "percentile.test"129	val := 88.0130	percentiles := []string{"p99", "p75"}131	pt := PercentileBuilder(metric, val, percentiles)132	if pt.Metric != metric {133		t.Errorf("bad metric: %s", pt.Metric)134	}135	if pt.Value != fmt.Sprintf("%f", val) {136		t.Errorf("bad value: %s", pt.Value)137	}138	if pt.Aggregator != strings.Join(percentiles, ",") {139		t.Errorf("bad aggregator: %s", pt.Aggregator)140	}141	// ns142	namepace := "1"143	if pt.Namespace != "" {144		t.Errorf("bad default ns: %s", pt.Namespace)145	}146	pt.Ns(namepace)147	if pt.Namespace != namepace {148		t.Errorf("bad ns: %s", pt.Namespace)149	}150	// tags151	tags := map[string]string{"k1": "v1", "k2": "v2"}152	if len(pt.Tags) != 0 {153		t.Errorf("bad default tags: %v", pt.Tags)154	}155	pt.AddTags(tags)156	if !reflect.DeepEqual(pt.Tags, tags) {157		t.Errorf("bad tags: %v", pt.Tags)158	}159}160func TestRpc(t *testing.T) {161	// Rpc162	{163		metric := "rpc"164		caller := "caller"165		callee := "callee"166		code := "ok"167		cnt := 2168		cb := RpcBuilder(caller, callee, time.Duration(cnt*1000000), code)169		if cb.Metric != metric {170			t.Errorf("bad metric: %s", cb.Metric)171		}172		if cb.Value != fmt.Sprintf("%v,%v", cnt, code) {173			t.Errorf("bad value: %s", cb.Value)174		}175		if cb.Aggregator != "rpc" {176			t.Errorf("bad aggregator: %s", cb.Aggregator)177		}178		v, ok := cb.Tags["caller"]179		if !(ok && v == caller) {180			t.Errorf("bad caller")181		}182		v, ok = cb.Tags["callee"]183		if !(ok && v == callee) {184			t.Errorf("bad callee")185		}186		// ns187		namepace := "1"188		if cb.Namespace != "" {189			t.Errorf("bad default ns: %s", cb.Namespace)190		}191		cb.Ns(namepace)192		if cb.Namespace != namepace {193			t.Errorf("bad ns: %s", cb.Namespace)194		}195		// tags196		tags := map[string]string{"k1": "v1", "k2": "v2"}197		cb.AddTags(tags)198		tags["caller"] = caller199		tags["callee"] = callee200		if !reflect.DeepEqual(cb.Tags, tags) {201			t.Errorf("bad tags: %v", cb.Tags)202		}203	}204	// RpcMetric205	{206		metric := "rpctest"207		caller := "caller"208		callee := "callee"209		code := "ok"210		cnt := 2211		cb := RpcMetricBuilder(metric, caller, callee, time.Duration(cnt*1000000), code, DefaultRpcVersion)212		if cb.Metric != metric {213			t.Errorf("bad metric: %s", cb.Metric)214		}215		if cb.Value != fmt.Sprintf("%v,%v", cnt, code) {216			t.Errorf("bad value: %s", cb.Value)217		}218		if cb.Aggregator != "rpc" {219			t.Errorf("bad aggregator: %s", cb.Aggregator)220		}221		v, ok := cb.Tags["caller"]222		if !(ok && v == caller) {223			t.Errorf("bad caller")224		}225		v, ok = cb.Tags["callee"]226		if !(ok && v == callee) {227			t.Errorf("bad callee")228		}229		// ns230		namepace := "1"231		if cb.Namespace != "" {232			t.Errorf("bad default ns: %s", cb.Namespace)233		}234		cb.Ns(namepace)235		if cb.Namespace != namepace {236			t.Errorf("bad ns: %s", cb.Namespace)237		}238		// tags239		tags := map[string]string{"k1": "v1", "k2": "v2"}240		cb.AddTags(tags)241		tags["caller"] = caller242		tags["callee"] = callee243		if !reflect.DeepEqual(cb.Tags, tags) {244			t.Errorf("bad tags: %v", cb.Tags)245		}246	}247}248func TestCheck(t *testing.T) {249	bads := ""250	for i := 0; i < 51; i++ {251		bads = fmt.Sprintf("%s.%d", bads, i)252	}253	if len(bads) < 101 {254		t.Errorf("gen bads error")255	}256	// ns257	cb := CounterNBuilder("m", 1).Ns("")258	err := cb.Check()259	if !(err != nil && strings.Contains(err.Error(), "empty ns")) {260		t.Errorf("bad ns check")261	}262	// metric263	ns := "1"264	cb = CounterNBuilder("", 1).Ns(ns)265	err = cb.Check()266	if !(err != nil && strings.Contains(err.Error(), "empty metric")) {267		t.Errorf("bad metric check")268	}269	cb = CounterNBuilder(bads, 1).Ns(ns)270	err = cb.Check()271	if !(err != nil && strings.Contains(err.Error(), "metric too long")) {272		t.Errorf("bad metric check")273	}274	// tags275	cb = CounterNBuilder("m", 1).Ns(ns)276	tags := map[string]string{"k": "v"}277	cb.AddTags(tags)278	err = cb.Check()279	if err != nil {280		t.Errorf("bad tags check")281	}282	cb = CounterNBuilder("m", 1).Ns(ns)283	tags = map[string]string{"": "v"}284	cb.AddTags(tags)285	err = cb.Check()286	if !(err != nil && strings.Contains(err.Error(), "empty tagk")) {287		t.Errorf("bad tags check")288	}289	cb = CounterNBuilder("m", 1).Ns(ns)290	tags = map[string]string{bads: "v"}291	cb.AddTags(tags)292	err = cb.Check()293	if !(err != nil && strings.Contains(err.Error(), "tagk too long")) {294		t.Errorf("bad tags check")295	}296	cb = CounterNBuilder("m", 1).Ns(ns)297	tags = map[string]string{"k": ""}298	cb.AddTags(tags)299	err = cb.Check()300	if !(err != nil && strings.Contains(err.Error(), "empty tagv")) {301		t.Errorf("bad tags check")302	}303	cb = CounterNBuilder("m", 1).Ns(ns)304	tags = map[string]string{"k": bads}305	cb.AddTags(tags)306	err = cb.Check()307	if !(err != nil && strings.Contains(err.Error(), "tagv too long")) {308		t.Errorf("bad tags check")309	}310	cb = CounterNBuilder("m", 1).Ns(ns)311	tags = map[string]string{}312	for i := 0; i < 9; i++ {313		kv := fmt.Sprintf("%d", i)314		tags[kv] = kv315	}316	cb.AddTags(tags)317	err = cb.Check()318	if !(err != nil && strings.Contains(err.Error(), "too many tags")) {319		t.Errorf("bad tags check")320	}321}322func TestPush(t *testing.T) {323	SetDefaultNs("1")324	Counter("niean.test")325	Counter("niean.test", map[string]string{"k": "v"})326	time.Sleep(time.Second * time.Duration(1))327	CounterN("niean.test", 2)328	CounterN("niean.test", 2, map[string]string{"k": "v"})329	time.Sleep(time.Second * time.Duration(1))330	Rpc("caller", "callee", time.Duration(10000000), "ok")...

Full Screen

Full Screen

wrappers_test.go

Source:wrappers_test.go Github

copy

Full Screen

...22	s.Count("anything", 1.0, tag)23	s.Gauge("anything", 1.0, tag)24	s.Histogram("anything", 1.0, tag)25	s.Timing("anything", 1.0, tag)26	s.AddTags(NewKVTag("a", "b"))27	s2 := s.Scope("x")28	assert.SameInstance(t, s2, s)29	assert.Nil(t, s.Close())30	assert.DeepEqual(t, s, NewNoopStats())31}32func TestNewRecordingStatsGauge(t *testing.T) {33	ch := make(chan Recorded, 10)34	s := NewRecordingStats(ch)35	defer func() {36		assert.Nil(t, s.Close())37	}()38	abTag := NewKVTag("a", "b")39	xyTag := NewKVTag("x", "y")40	s.Gauge("g", 1.1)41	s.Gauge("g", 1.2, abTag)42	s.AddTags(xyTag)43	s.Gauge("g", 1.3, abTag)44	s = NewRecordingStats(ch)45	s.Gauge("g", 1.4)46	s = s.Scope("i", "j")47	s.Gauge("g", 1.5)48	s.Gauge("g", 1.6, abTag)49	s.AddTags(xyTag)50	s.Gauge("g", 1.7, abTag)51	assert.DeepEqual(t, <-ch, Recorded{52		Method: "gauge",53		Metric: "g",54		Value:  1.1,55	})56	assert.DeepEqual(t, <-ch, Recorded{57		Method: "gauge",58		Metric: "g",59		Value:  1.2,60		Tags:   []Tag{abTag},61	})62	assert.DeepEqual(t, <-ch, Recorded{63		Method: "gauge",64		Metric: "g",65		Value:  1.3,66		Tags:   []Tag{xyTag, abTag},67	})68	assert.DeepEqual(t, <-ch, Recorded{69		Method: "gauge",70		Metric: "g",71		Value:  1.4,72	})73	assert.DeepEqual(t, <-ch, Recorded{74		Scope:  "i.j",75		Method: "gauge",76		Metric: "g",77		Value:  1.5,78	})79	assert.DeepEqual(t, <-ch, Recorded{80		Scope:  "i.j",81		Method: "gauge",82		Metric: "g",83		Value:  1.6,84		Tags:   []Tag{abTag},85	})86	assert.DeepEqual(t, <-ch, Recorded{87		Scope:  "i.j",88		Method: "gauge",89		Metric: "g",90		Value:  1.7,91		Tags:   []Tag{xyTag, abTag},92	})93	assert.ChannelEmpty(t, ch)94}95func TestNewRecordingStatsCount(t *testing.T) {96	ch := make(chan Recorded, 10)97	abTag := NewKVTag("a", "b")98	xyTag := NewKVTag("x", "y")99	s := NewRecordingStats(ch)100	defer func() {101		assert.Nil(t, s.Close())102	}()103	s.AddTags(xyTag)104	s = s.Scope("i", "j")105	s = s.Scope("k")106	s.Count("c", 100.0, abTag, abTag)107	assert.DeepEqual(t, <-ch, Recorded{108		Scope:  "i.j.k",109		Method: "count",110		Metric: "c",111		Value:  100.0,112		Tags:   []Tag{xyTag, abTag, abTag},113	})114	assert.ChannelEmpty(t, ch)115}116func TestNewRecordingStatsHistogram(t *testing.T) {117	ch := make(chan Recorded, 10)118	abTag := NewKVTag("a", "b")119	xyTag := NewKVTag("x", "y")120	s := NewRecordingStats(ch)121	defer func() {122		assert.Nil(t, s.Close())123	}()124	s.AddTags(xyTag)125	s = s.Scope("i", "j")126	s = s.Scope("k")127	s.Histogram("h", 200.0, abTag, abTag)128	assert.DeepEqual(t, <-ch, Recorded{129		Scope:  "i.j.k",130		Method: "histogram",131		Metric: "h",132		Value:  200.0,133		Tags:   []Tag{xyTag, abTag, abTag},134	})135	assert.ChannelEmpty(t, ch)136}137func TestNewRecordingStatsTiming(t *testing.T) {138	ch := make(chan Recorded, 10)139	abTag := NewKVTag("a", "b")140	xyTag := NewKVTag("x", "y")141	s := NewRecordingStats(ch)142	defer func() {143		assert.Nil(t, s.Close())144	}()145	s.AddTags(xyTag)146	s = s.Scope("i", "j")147	s = s.Scope("k")148	s.Timing("t", 10*time.Second, abTag, abTag)149	assert.DeepEqual(t, <-ch, Recorded{150		Scope:  "i.j.k",151		Method: "timing",152		Metric: "t",153		Timing: 10 * time.Second,154		Tags:   []Tag{xyTag, abTag, abTag},155	})156	assert.ChannelEmpty(t, ch)157}158func TestNewAsyncStats(t *testing.T) {159	tag := NewKVTag("a", "b")...

Full Screen

Full Screen

client.go

Source:client.go Github

copy

Full Screen

1package scopedstatsd2import (3	"time"4	"github.com/DataDog/datadog-go/statsd"5	"github.com/stripe/veneur/v14/ssf"6)7// StatsdClient represents the statsd client functions that veneur's8// SSF sinks call (so as not to write-amplify by reporting its own9// metrics).10type Client interface {11	Gauge(name string, value float64, tags []string, rate float64) error12	Count(name string, value int64, tags []string, rate float64) error13	Incr(name string, tags []string, rate float64) error14	Histogram(name string, value float64, tags []string, rate float64) error15	TimeInMilliseconds(name string, value float64, tags []string, rate float64) error16	Timing(name string, value time.Duration, tags []string, rate float64) error17}18// Ensure takes a statsd client and wraps it in such a way that it is19// safe to store in a struct if it should be nil. Otherwise returns20// the Client unchanged.21func Ensure(cl Client) Client {22	if cl == nil {23		return &ScopedClient{}24	}25	return cl26}27// MetricScopes holds the scopes that are configured for each metric28// type.29type MetricScopes struct {30	Gauge     ssf.SSFSample_Scope31	Count     ssf.SSFSample_Scope32	Histogram ssf.SSFSample_Scope33}34type ScopedClient struct {35	client *statsd.Client36	addTags []string37	scopes  MetricScopes38}39var _ Client = &ScopedClient{}40func addScopeTag(tags []string, scope ssf.SSFSample_Scope) []string {41	switch scope {42	case ssf.SSFSample_LOCAL:43		return append(tags, "veneurlocalonly:true")44	case ssf.SSFSample_GLOBAL:45		return append(tags, "veneurglobalonly:true")46	default:47		return tags48	}49}50func (s *ScopedClient) Gauge(name string, value float64, tags []string, rate float64) error {51	if s == nil {52		return nil53	}54	tags = append(tags, s.addTags...)55	tags = addScopeTag(tags, s.scopes.Gauge)56	return s.client.Gauge(name, value, tags, rate)57}58func (s *ScopedClient) Count(name string, value int64, tags []string, rate float64) error {59	if s == nil {60		return nil61	}62	tags = append(tags, s.addTags...)63	tags = addScopeTag(tags, s.scopes.Count)64	return s.client.Count(name, value, tags, rate)65}66func (s *ScopedClient) Incr(name string, tags []string, rate float64) error {67	if s == nil {68		return nil69	}70	return s.Count(name, 1, tags, rate)71}72func (s *ScopedClient) TimeInMilliseconds(name string, value float64, tags []string, rate float64) error {73	if s == nil {74		return nil75	}76	tags = append(tags, s.addTags...)77	tags = addScopeTag(tags, s.scopes.Histogram)78	return s.client.TimeInMilliseconds(name, value, tags, rate)79}80func (s *ScopedClient) Timing(name string, value time.Duration, tags []string, rate float64) error {81	if s == nil {82		return nil83	}84	tags = append(tags, s.addTags...)85	tags = addScopeTag(tags, s.scopes.Histogram)86	return s.client.Timing(name, value, tags, rate)87}88func (s *ScopedClient) Histogram(name string, value float64, tags []string, rate float64) error {89	if s == nil {90		return nil91	}92	tags = append(tags, s.addTags...)93	tags = addScopeTag(tags, s.scopes.Histogram)94	return s.client.Histogram(name, value, tags, rate)95}96func NewClient(inner *statsd.Client, addTags []string, scopes MetricScopes) *ScopedClient {97	return &ScopedClient{98		client:  inner,99		addTags: addTags,100		scopes:  scopes,101	}102}...

Full Screen

Full Screen

AddTags

Using AI Code Generation

copy

Full Screen

1gauge.AddTags("tag1", "tag2")2gauge.AddTags("tag1", "tag2")3gauge.AddTags("tag1", "tag2")4gauge.AddTags("tag1", "tag2")5gauge.AddTags("tag1", "tag2")6gauge.AddTags("tag1", "tag2")7gauge.AddTags("tag1", "tag2")8gauge.AddTags("tag1", "tag2")9gauge.AddTags("tag1", "tag2")10gauge.AddTags("tag1", "tag2")11gauge.AddTags("tag1", "tag2")12gauge.AddTags("tag1", "tag2")13gauge.AddTags("tag1", "tag2")14gauge.AddTags("tag1", "tag2")15gauge.AddTags("tag1", "tag2")16gauge.AddTags("tag1", "tag2")17gauge.AddTags("tag1", "tag2")

Full Screen

Full Screen

AddTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	gauge.AddTags("tag1")4	gauge.AddTags("tag2", "tag3")5	fmt.Println("Gauge tags: ", gauge.Tags())6}7import (8func main() {9	gauge.AddTags("tag1")10	gauge.AddTags("tag2", "tag3")11	fmt.Println("Gauge tags: ", gauge.Tags())12}13import (14func main() {15	gauge.AddTags("tag1")16	gauge.AddTags("tag2", "tag3")17	fmt.Println("Gauge tags: ", gauge.Tags())18}19import (20func main() {21	gauge.AddTags("tag1")22	gauge.AddTags("tag2", "tag3")23	fmt.Println("Gauge tags: ", gauge.Tags())24}25import (26func main() {27	gauge.AddTags("tag1")28	gauge.AddTags("tag2", "tag3")29	fmt.Println("Gauge tags: ", gauge.Tags())30}31import (32func main() {33	gauge.AddTags("tag1")34	gauge.AddTags("tag2", "

Full Screen

Full Screen

AddTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println("Hello World!")4}5import (6func main() {7	fmt.Println("Hello World!")8}

Full Screen

Full Screen

AddTags

Using AI Code Generation

copy

Full Screen

1gauge.AddTags("tag1","tag2","tag3");2gauge.AddTags("tag1","tag2","tag3");3gauge.AddTags("tag1","tag2","tag3");4gauge.AddTags("tag1","tag2","tag3");5gauge.AddTags("tag1","tag2","tag3");6gauge.AddTags("tag1","tag2","tag3");7gauge.AddTags("tag1","tag2","tag3");8gauge.AddTags("tag1","tag2","tag3");9gauge.AddTags("tag1","tag2","tag3");10gauge.AddTags("tag1","tag2","tag3");11gauge.AddTags("tag1","tag2","tag3");12gauge.AddTags("tag1","tag2","tag3");13gauge.AddTags("tag1","tag2","tag3");14gauge.AddTags("tag1","tag2","tag3");15gauge.AddTags("tag1","tag2","tag3");16gauge.AddTags("tag1","tag2","tag3");

Full Screen

Full Screen

AddTags

Using AI Code Generation

copy

Full Screen

1gauge.AddTags("tag1", "tag2")2gauge.AddTags("tag1", "tag2")3gauge.WithTags("tag1", "tag2").AddTags("tag3", "tag4")4gauge.AddTags("tag1", "tag2")5gauge.WithTags("tag1", "tag2").AddTags("tag3", "tag4")6gauge.WithTags("tag1", "tag2").AddTags("tag3", "tag4")7gauge.WithTags("tag1", "tag2").AddTags("tag3", "tag4")8gauge.WithTags("tag1", "tag2").AddTags("tag3", "tag4")

Full Screen

Full Screen

AddTags

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3    g := gauge{make(map[string]string)}4    g.AddTags("key1", "value1")5    fmt.Println(g.tags)6}

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.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful