How to use Contains method of metrics Package

Best K6 code snippet using metrics.Contains

go_metrics_test.go

Source:go_metrics_test.go Github

copy

Full Screen

...9)10func TestNewMetrics(t *testing.T) {11 registry := metrics.NewRegistry()12 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus, openrtb_ext.BidderRubicon}, config.DisabledMetrics{})13 ensureContains(t, registry, "app_requests", m.AppRequestMeter)14 ensureContains(t, registry, "no_cookie_requests", m.NoCookieMeter)15 ensureContains(t, registry, "safari_requests", m.SafariRequestMeter)16 ensureContains(t, registry, "safari_no_cookie_requests", m.SafariNoCookieMeter)17 ensureContains(t, registry, "request_time", m.RequestTimer)18 ensureContains(t, registry, "amp_no_cookie_requests", m.AmpNoCookieMeter)19 ensureContainsAdapterMetrics(t, registry, "adapter.appnexus", m.AdapterMetrics["appnexus"])20 ensureContainsAdapterMetrics(t, registry, "adapter.rubicon", m.AdapterMetrics["rubicon"])21 ensureContains(t, registry, "cookie_sync_requests", m.CookieSyncMeter)22 ensureContains(t, registry, "cookie_sync.appnexus.gen", m.CookieSyncGen["appnexus"])23 ensureContains(t, registry, "cookie_sync.appnexus.gdpr_prevent", m.CookieSyncGDPRPrevent["appnexus"])24 ensureContains(t, registry, "usersync.appnexus.gdpr_prevent", m.userSyncGDPRPrevent["appnexus"])25 ensureContains(t, registry, "usersync.rubicon.gdpr_prevent", m.userSyncGDPRPrevent["rubicon"])26 ensureContains(t, registry, "usersync.unknown.gdpr_prevent", m.userSyncGDPRPrevent["unknown"])27 ensureContains(t, registry, "prebid_cache_request_time.ok", m.PrebidCacheRequestTimerSuccess)28 ensureContains(t, registry, "prebid_cache_request_time.err", m.PrebidCacheRequestTimerError)29 ensureContains(t, registry, "requests.ok.legacy", m.RequestStatuses[ReqTypeLegacy][RequestStatusOK])30 ensureContains(t, registry, "requests.badinput.legacy", m.RequestStatuses[ReqTypeLegacy][RequestStatusBadInput])31 ensureContains(t, registry, "requests.err.legacy", m.RequestStatuses[ReqTypeLegacy][RequestStatusErr])32 ensureContains(t, registry, "requests.networkerr.legacy", m.RequestStatuses[ReqTypeLegacy][RequestStatusNetworkErr])33 ensureContains(t, registry, "requests.ok.openrtb2-web", m.RequestStatuses[ReqTypeORTB2Web][RequestStatusOK])34 ensureContains(t, registry, "requests.badinput.openrtb2-web", m.RequestStatuses[ReqTypeORTB2Web][RequestStatusBadInput])35 ensureContains(t, registry, "requests.err.openrtb2-web", m.RequestStatuses[ReqTypeORTB2Web][RequestStatusErr])36 ensureContains(t, registry, "requests.networkerr.openrtb2-web", m.RequestStatuses[ReqTypeORTB2Web][RequestStatusNetworkErr])37 ensureContains(t, registry, "requests.ok.openrtb2-app", m.RequestStatuses[ReqTypeORTB2App][RequestStatusOK])38 ensureContains(t, registry, "requests.badinput.openrtb2-app", m.RequestStatuses[ReqTypeORTB2App][RequestStatusBadInput])39 ensureContains(t, registry, "requests.err.openrtb2-app", m.RequestStatuses[ReqTypeORTB2App][RequestStatusErr])40 ensureContains(t, registry, "requests.networkerr.openrtb2-app", m.RequestStatuses[ReqTypeORTB2App][RequestStatusNetworkErr])41 ensureContains(t, registry, "requests.ok.amp", m.RequestStatuses[ReqTypeAMP][RequestStatusOK])42 ensureContains(t, registry, "requests.badinput.amp", m.RequestStatuses[ReqTypeAMP][RequestStatusBadInput])43 ensureContains(t, registry, "requests.err.amp", m.RequestStatuses[ReqTypeAMP][RequestStatusErr])44 ensureContains(t, registry, "requests.networkerr.amp", m.RequestStatuses[ReqTypeAMP][RequestStatusNetworkErr])45 ensureContains(t, registry, "requests.ok.video", m.RequestStatuses[ReqTypeVideo][RequestStatusOK])46 ensureContains(t, registry, "requests.badinput.video", m.RequestStatuses[ReqTypeVideo][RequestStatusBadInput])47 ensureContains(t, registry, "requests.err.video", m.RequestStatuses[ReqTypeVideo][RequestStatusErr])48 ensureContains(t, registry, "requests.networkerr.video", m.RequestStatuses[ReqTypeVideo][RequestStatusNetworkErr])49 ensureContains(t, registry, "queued_requests.video.rejected", m.RequestsQueueTimer[ReqTypeVideo][false])50 ensureContains(t, registry, "queued_requests.video.accepted", m.RequestsQueueTimer[ReqTypeVideo][true])51 ensureContains(t, registry, "timeout_notification.ok", m.TimeoutNotificationSuccess)52 ensureContains(t, registry, "timeout_notification.failed", m.TimeoutNotificationFailure)53 ensureContains(t, registry, "privacy.request.ccpa.specified", m.PrivacyCCPARequest)54 ensureContains(t, registry, "privacy.request.ccpa.opt-out", m.PrivacyCCPARequestOptOut)55 ensureContains(t, registry, "privacy.request.coppa", m.PrivacyCOPPARequest)56 ensureContains(t, registry, "privacy.request.lmt", m.PrivacyLMTRequest)57 ensureContains(t, registry, "privacy.request.tcf.v1", m.PrivacyTCFRequestVersion[TCFVersionV1])58 ensureContains(t, registry, "privacy.request.tcf.v2", m.PrivacyTCFRequestVersion[TCFVersionV2])59 ensureContains(t, registry, "privacy.request.tcf.err", m.PrivacyTCFRequestVersion[TCFVersionErr])60}61func TestRecordBidType(t *testing.T) {62 registry := metrics.NewRegistry()63 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, config.DisabledMetrics{})64 m.RecordAdapterBidReceived(AdapterLabels{65 Adapter: openrtb_ext.BidderAppnexus,66 }, openrtb_ext.BidTypeBanner, true)67 VerifyMetrics(t, "Appnexus Banner Adm Bids", m.AdapterMetrics[openrtb_ext.BidderAppnexus].MarkupMetrics[openrtb_ext.BidTypeBanner].AdmMeter.Count(), 1)68 VerifyMetrics(t, "Appnexus Banner Nurl Bids", m.AdapterMetrics[openrtb_ext.BidderAppnexus].MarkupMetrics[openrtb_ext.BidTypeBanner].NurlMeter.Count(), 0)69 m.RecordAdapterBidReceived(AdapterLabels{70 Adapter: openrtb_ext.BidderAppnexus,71 }, openrtb_ext.BidTypeVideo, false)72 VerifyMetrics(t, "Appnexus Video Adm Bids", m.AdapterMetrics[openrtb_ext.BidderAppnexus].MarkupMetrics[openrtb_ext.BidTypeVideo].AdmMeter.Count(), 0)73 VerifyMetrics(t, "Appnexus Video Nurl Bids", m.AdapterMetrics[openrtb_ext.BidderAppnexus].MarkupMetrics[openrtb_ext.BidTypeVideo].NurlMeter.Count(), 1)74}75func TestRecordGDPRRejection(t *testing.T) {76 registry := metrics.NewRegistry()77 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, config.DisabledMetrics{})78 m.RecordUserIDSet(UserLabels{79 Action: RequestActionGDPR,80 Bidder: openrtb_ext.BidderAppnexus,81 })82 VerifyMetrics(t, "GDPR sync rejects", m.userSyncGDPRPrevent[openrtb_ext.BidderAppnexus].Count(), 1)83}84func ensureContains(t *testing.T, registry metrics.Registry, name string, metric interface{}) {85 t.Helper()86 if inRegistry := registry.Get(name); inRegistry == nil {87 t.Errorf("No metric in registry at %s.", name)88 } else if inRegistry != metric {89 t.Errorf("Bad value stored at metric %s.", name)90 }91}92func ensureContainsAdapterMetrics(t *testing.T, registry metrics.Registry, name string, adapterMetrics *AdapterMetrics) {93 t.Helper()94 ensureContains(t, registry, name+".no_cookie_requests", adapterMetrics.NoCookieMeter)95 ensureContains(t, registry, name+".requests.gotbids", adapterMetrics.GotBidsMeter)96 ensureContains(t, registry, name+".requests.nobid", adapterMetrics.NoBidMeter)97 ensureContains(t, registry, name+".requests.badinput", adapterMetrics.ErrorMeters[AdapterErrorBadInput])98 ensureContains(t, registry, name+".requests.badserverresponse", adapterMetrics.ErrorMeters[AdapterErrorBadServerResponse])99 ensureContains(t, registry, name+".requests.timeout", adapterMetrics.ErrorMeters[AdapterErrorTimeout])100 ensureContains(t, registry, name+".requests.unknown_error", adapterMetrics.ErrorMeters[AdapterErrorUnknown])101 ensureContains(t, registry, name+".request_time", adapterMetrics.RequestTimer)102 ensureContains(t, registry, name+".prices", adapterMetrics.PriceHistogram)103 ensureContainsBidTypeMetrics(t, registry, name, adapterMetrics.MarkupMetrics)104 ensureContains(t, registry, name+".connections_created", adapterMetrics.ConnCreated)105 ensureContains(t, registry, name+".connections_reused", adapterMetrics.ConnReused)106 ensureContains(t, registry, name+".connection_wait_time", adapterMetrics.ConnWaitTime)107}108func TestRecordBidTypeDisabledConfig(t *testing.T) {109 testCases := []struct {110 hasAdm bool111 DisabledMetrics config.DisabledMetrics112 ExpectedAdmMeterCount int64113 ExpectedNurlMeterCount int64114 BidType openrtb_ext.BidType115 PubID string116 }{117 {118 hasAdm: true,119 DisabledMetrics: config.DisabledMetrics{},120 ExpectedAdmMeterCount: 1,121 ExpectedNurlMeterCount: 0,122 BidType: openrtb_ext.BidTypeBanner,123 PubID: "acct-id",124 },125 {126 hasAdm: false,127 DisabledMetrics: config.DisabledMetrics{},128 ExpectedAdmMeterCount: 0,129 ExpectedNurlMeterCount: 1,130 BidType: openrtb_ext.BidTypeVideo,131 PubID: "acct-id",132 },133 {134 hasAdm: false,135 DisabledMetrics: config.DisabledMetrics{AccountAdapterDetails: true},136 ExpectedAdmMeterCount: 0,137 ExpectedNurlMeterCount: 1,138 BidType: openrtb_ext.BidTypeVideo,139 PubID: "acct-id",140 },141 {142 hasAdm: true,143 DisabledMetrics: config.DisabledMetrics{AccountAdapterDetails: true},144 ExpectedAdmMeterCount: 1,145 ExpectedNurlMeterCount: 0,146 BidType: openrtb_ext.BidTypeBanner,147 PubID: "acct-id",148 },149 }150 for _, test := range testCases {151 registry := metrics.NewRegistry()152 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, test.DisabledMetrics)153 m.RecordAdapterBidReceived(AdapterLabels{154 Adapter: openrtb_ext.BidderAppnexus,155 PubID: test.PubID,156 }, test.BidType, test.hasAdm)157 assert.Equal(t, test.ExpectedAdmMeterCount, m.AdapterMetrics[openrtb_ext.BidderAppnexus].MarkupMetrics[test.BidType].AdmMeter.Count(), "Appnexus Banner Adm Bids")158 assert.Equal(t, test.ExpectedNurlMeterCount, m.AdapterMetrics[openrtb_ext.BidderAppnexus].MarkupMetrics[test.BidType].NurlMeter.Count(), "Appnexus Banner Nurl Bids")159 if test.DisabledMetrics.AccountAdapterDetails {160 assert.Len(t, m.accountMetrics[test.PubID].adapterMetrics, 0, "Test failed. Account metrics that contain adapter information are disabled, therefore we expect no entries in m.accountMetrics[accountId].adapterMetrics, we have %d \n", len(m.accountMetrics[test.PubID].adapterMetrics))161 } else {162 assert.NotEqual(t, 0, len(m.accountMetrics[test.PubID].adapterMetrics), "Test failed. Account metrics that contain adapter information are disabled, therefore we expect no entries in m.accountMetrics[accountId].adapterMetrics, we have %d \n", len(m.accountMetrics[test.PubID].adapterMetrics))163 }164 }165}166func TestRecordDNSTime(t *testing.T) {167 testCases := []struct {168 description string169 inDnsLookupDuration time.Duration170 outExpDuration time.Duration171 }{172 {173 description: "Five second DNS lookup time",174 inDnsLookupDuration: time.Second * 5,175 outExpDuration: time.Second * 5,176 },177 {178 description: "Zero DNS lookup time",179 inDnsLookupDuration: time.Duration(0),180 outExpDuration: time.Duration(0),181 },182 }183 for _, test := range testCases {184 registry := metrics.NewRegistry()185 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, config.DisabledMetrics{AccountAdapterDetails: true})186 m.RecordDNSTime(test.inDnsLookupDuration)187 assert.Equal(t, test.outExpDuration.Nanoseconds(), m.DNSLookupTimer.Sum(), test.description)188 }189}190func TestRecordAdapterConnections(t *testing.T) {191 var fakeBidder openrtb_ext.BidderName = "fooAdvertising"192 type testIn struct {193 adapterName openrtb_ext.BidderName194 connWasReused bool195 connWait time.Duration196 connMetricsDisabled bool197 }198 type testOut struct {199 expectedConnReusedCount int64200 expectedConnCreatedCount int64201 expectedConnWaitTime time.Duration202 }203 testCases := []struct {204 description string205 in testIn206 out testOut207 }{208 {209 description: "Successful, new connection created, has connection wait",210 in: testIn{211 adapterName: openrtb_ext.BidderAppnexus,212 connWasReused: false,213 connWait: time.Second * 5,214 connMetricsDisabled: false,215 },216 out: testOut{217 expectedConnReusedCount: 0,218 expectedConnCreatedCount: 1,219 expectedConnWaitTime: time.Second * 5,220 },221 },222 {223 description: "Successful, new connection created, has connection wait",224 in: testIn{225 adapterName: openrtb_ext.BidderAppnexus,226 connWasReused: false,227 connWait: time.Second * 4,228 connMetricsDisabled: false,229 },230 out: testOut{231 expectedConnCreatedCount: 1,232 expectedConnWaitTime: time.Second * 4,233 },234 },235 {236 description: "Successful, was reused, no connection wait",237 in: testIn{238 adapterName: openrtb_ext.BidderAppnexus,239 connWasReused: true,240 connMetricsDisabled: false,241 },242 out: testOut{243 expectedConnReusedCount: 1,244 expectedConnWaitTime: 0,245 },246 },247 {248 description: "Successful, was reused, has connection wait",249 in: testIn{250 adapterName: openrtb_ext.BidderAppnexus,251 connWasReused: true,252 connWait: time.Second * 5,253 connMetricsDisabled: false,254 },255 out: testOut{256 expectedConnReusedCount: 1,257 expectedConnWaitTime: time.Second * 5,258 },259 },260 {261 description: "Fake bidder, nothing gets updated",262 in: testIn{263 adapterName: fakeBidder,264 connWasReused: false,265 connWait: 0,266 connMetricsDisabled: false,267 },268 out: testOut{},269 },270 {271 description: "Adapter connection metrics are disabled, nothing gets updated",272 in: testIn{273 adapterName: openrtb_ext.BidderAppnexus,274 connWasReused: false,275 connWait: time.Second * 5,276 connMetricsDisabled: true,277 },278 out: testOut{},279 },280 }281 for i, test := range testCases {282 registry := metrics.NewRegistry()283 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, config.DisabledMetrics{AdapterConnectionMetrics: test.in.connMetricsDisabled})284 m.RecordAdapterConnections(test.in.adapterName, test.in.connWasReused, test.in.connWait)285 assert.Equal(t, test.out.expectedConnReusedCount, m.AdapterMetrics[openrtb_ext.BidderAppnexus].ConnReused.Count(), "Test [%d] incorrect number of reused connections to adapter", i)286 assert.Equal(t, test.out.expectedConnCreatedCount, m.AdapterMetrics[openrtb_ext.BidderAppnexus].ConnCreated.Count(), "Test [%d] incorrect number of new connections to adapter created", i)287 assert.Equal(t, test.out.expectedConnWaitTime.Nanoseconds(), m.AdapterMetrics[openrtb_ext.BidderAppnexus].ConnWaitTime.Sum(), "Test [%d] incorrect wait time in connection to adapter", i)288 }289}290func TestNewMetricsWithDisabledConfig(t *testing.T) {291 registry := metrics.NewRegistry()292 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus, openrtb_ext.BidderRubicon}, config.DisabledMetrics{AccountAdapterDetails: true})293 assert.True(t, m.MetricsDisabled.AccountAdapterDetails, "Accound adapter metrics should be disabled")294}295func TestRecordPrebidCacheRequestTimeWithSuccess(t *testing.T) {296 registry := metrics.NewRegistry()297 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, config.DisabledMetrics{AccountAdapterDetails: true})298 m.RecordPrebidCacheRequestTime(true, 42)299 assert.Equal(t, m.PrebidCacheRequestTimerSuccess.Count(), int64(1))300 assert.Equal(t, m.PrebidCacheRequestTimerError.Count(), int64(0))301}302func TestRecordPrebidCacheRequestTimeWithNotSuccess(t *testing.T) {303 registry := metrics.NewRegistry()304 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus}, config.DisabledMetrics{AccountAdapterDetails: true})305 m.RecordPrebidCacheRequestTime(false, 42)306 assert.Equal(t, m.PrebidCacheRequestTimerSuccess.Count(), int64(0))307 assert.Equal(t, m.PrebidCacheRequestTimerError.Count(), int64(1))308}309func TestRecordRequestPrivacy(t *testing.T) {310 registry := metrics.NewRegistry()311 m := NewMetrics(registry, []openrtb_ext.BidderName{openrtb_ext.BidderAppnexus, openrtb_ext.BidderRubicon}, config.DisabledMetrics{AccountAdapterDetails: true})312 // CCPA313 m.RecordRequestPrivacy(PrivacyLabels{314 CCPAEnforced: true,315 CCPAProvided: true,316 })317 m.RecordRequestPrivacy(PrivacyLabels{318 CCPAEnforced: true,319 CCPAProvided: false,320 })321 m.RecordRequestPrivacy(PrivacyLabels{322 CCPAEnforced: false,323 CCPAProvided: true,324 })325 // COPPA326 m.RecordRequestPrivacy(PrivacyLabels{327 COPPAEnforced: true,328 })329 // LMT330 m.RecordRequestPrivacy(PrivacyLabels{331 LMTEnforced: true,332 })333 // GDPR334 m.RecordRequestPrivacy(PrivacyLabels{335 GDPREnforced: true,336 GDPRTCFVersion: TCFVersionErr,337 })338 m.RecordRequestPrivacy(PrivacyLabels{339 GDPREnforced: true,340 GDPRTCFVersion: TCFVersionV1,341 })342 m.RecordRequestPrivacy(PrivacyLabels{343 GDPREnforced: true,344 GDPRTCFVersion: TCFVersionV2,345 })346 m.RecordRequestPrivacy(PrivacyLabels{347 GDPREnforced: true,348 GDPRTCFVersion: TCFVersionV1,349 })350 assert.Equal(t, m.PrivacyCCPARequest.Count(), int64(2), "CCPA")351 assert.Equal(t, m.PrivacyCCPARequestOptOut.Count(), int64(1), "CCPA Opt Out")352 assert.Equal(t, m.PrivacyCOPPARequest.Count(), int64(1), "COPPA")353 assert.Equal(t, m.PrivacyLMTRequest.Count(), int64(1), "LMT")354 assert.Equal(t, m.PrivacyTCFRequestVersion[TCFVersionErr].Count(), int64(1), "TCF Err")355 assert.Equal(t, m.PrivacyTCFRequestVersion[TCFVersionV1].Count(), int64(2), "TCF V1")356 assert.Equal(t, m.PrivacyTCFRequestVersion[TCFVersionV2].Count(), int64(1), "TCF V2")357}358func ensureContainsBidTypeMetrics(t *testing.T, registry metrics.Registry, prefix string, mdm map[openrtb_ext.BidType]*MarkupDeliveryMetrics) {359 ensureContains(t, registry, prefix+".banner.adm_bids_received", mdm[openrtb_ext.BidTypeBanner].AdmMeter)360 ensureContains(t, registry, prefix+".banner.nurl_bids_received", mdm[openrtb_ext.BidTypeBanner].NurlMeter)361 ensureContains(t, registry, prefix+".video.adm_bids_received", mdm[openrtb_ext.BidTypeVideo].AdmMeter)362 ensureContains(t, registry, prefix+".video.nurl_bids_received", mdm[openrtb_ext.BidTypeVideo].NurlMeter)363 ensureContains(t, registry, prefix+".audio.adm_bids_received", mdm[openrtb_ext.BidTypeAudio].AdmMeter)364 ensureContains(t, registry, prefix+".audio.nurl_bids_received", mdm[openrtb_ext.BidTypeAudio].NurlMeter)365 ensureContains(t, registry, prefix+".native.adm_bids_received", mdm[openrtb_ext.BidTypeNative].AdmMeter)366 ensureContains(t, registry, prefix+".native.nurl_bids_received", mdm[openrtb_ext.BidTypeNative].NurlMeter)367}368func VerifyMetrics(t *testing.T, name string, expected int64, actual int64) {369 if expected != actual {370 t.Errorf("Error in metric %s: expected %d, got %d.", name, expected, actual)371 }372}...

Full Screen

Full Screen

accumulator_test.go

Source:accumulator_test.go Github

copy

Full Screen

...18 a.Add("acctest", float64(101), map[string]string{"acc": "test"})19 a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)20 testm := <-a.metrics21 actual := testm.String()22 assert.Contains(t, actual, "acctest value=101")23 testm = <-a.metrics24 actual = testm.String()25 assert.Contains(t, actual, "acctest,acc=test value=101")26 testm = <-a.metrics27 actual = testm.String()28 assert.Equal(t,29 fmt.Sprintf("acctest,acc=test value=101 %d", now.UnixNano()),30 actual)31}32func TestAddDefaultTags(t *testing.T) {33 a := accumulator{}34 a.addDefaultTag("default", "tag")35 now := time.Now()36 a.metrics = make(chan telegraf.Metric, 10)37 defer close(a.metrics)38 a.inputConfig = &internal_models.InputConfig{}39 a.Add("acctest", float64(101), map[string]string{})40 a.Add("acctest", float64(101), map[string]string{"acc": "test"})41 a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)42 testm := <-a.metrics43 actual := testm.String()44 assert.Contains(t, actual, "acctest,default=tag value=101")45 testm = <-a.metrics46 actual = testm.String()47 assert.Contains(t, actual, "acctest,acc=test,default=tag value=101")48 testm = <-a.metrics49 actual = testm.String()50 assert.Equal(t,51 fmt.Sprintf("acctest,acc=test,default=tag value=101 %d", now.UnixNano()),52 actual)53}54func TestAddFields(t *testing.T) {55 a := accumulator{}56 now := time.Now()57 a.metrics = make(chan telegraf.Metric, 10)58 defer close(a.metrics)59 a.inputConfig = &internal_models.InputConfig{}60 fields := map[string]interface{}{61 "usage": float64(99),62 }63 a.AddFields("acctest", fields, map[string]string{})64 a.AddFields("acctest", fields, map[string]string{"acc": "test"})65 a.AddFields("acctest", fields, map[string]string{"acc": "test"}, now)66 testm := <-a.metrics67 actual := testm.String()68 assert.Contains(t, actual, "acctest usage=99")69 testm = <-a.metrics70 actual = testm.String()71 assert.Contains(t, actual, "acctest,acc=test usage=99")72 testm = <-a.metrics73 actual = testm.String()74 assert.Equal(t,75 fmt.Sprintf("acctest,acc=test usage=99 %d", now.UnixNano()),76 actual)77}78// Test that all Inf fields get dropped, and not added to metrics channel79func TestAddInfFields(t *testing.T) {80 inf := math.Inf(1)81 ninf := math.Inf(-1)82 a := accumulator{}83 now := time.Now()84 a.metrics = make(chan telegraf.Metric, 10)85 defer close(a.metrics)86 a.inputConfig = &internal_models.InputConfig{}87 fields := map[string]interface{}{88 "usage": inf,89 "nusage": ninf,90 }91 a.AddFields("acctest", fields, map[string]string{})92 a.AddFields("acctest", fields, map[string]string{"acc": "test"})93 a.AddFields("acctest", fields, map[string]string{"acc": "test"}, now)94 assert.Len(t, a.metrics, 0)95 // test that non-inf fields are kept and not dropped96 fields["notinf"] = float64(100)97 a.AddFields("acctest", fields, map[string]string{})98 testm := <-a.metrics99 actual := testm.String()100 assert.Contains(t, actual, "acctest notinf=100")101}102// Test that nan fields are dropped and not added103func TestAddNaNFields(t *testing.T) {104 nan := math.NaN()105 a := accumulator{}106 now := time.Now()107 a.metrics = make(chan telegraf.Metric, 10)108 defer close(a.metrics)109 a.inputConfig = &internal_models.InputConfig{}110 fields := map[string]interface{}{111 "usage": nan,112 }113 a.AddFields("acctest", fields, map[string]string{})114 a.AddFields("acctest", fields, map[string]string{"acc": "test"})115 a.AddFields("acctest", fields, map[string]string{"acc": "test"}, now)116 assert.Len(t, a.metrics, 0)117 // test that non-nan fields are kept and not dropped118 fields["notnan"] = float64(100)119 a.AddFields("acctest", fields, map[string]string{})120 testm := <-a.metrics121 actual := testm.String()122 assert.Contains(t, actual, "acctest notnan=100")123}124func TestAddUint64Fields(t *testing.T) {125 a := accumulator{}126 now := time.Now()127 a.metrics = make(chan telegraf.Metric, 10)128 defer close(a.metrics)129 a.inputConfig = &internal_models.InputConfig{}130 fields := map[string]interface{}{131 "usage": uint64(99),132 }133 a.AddFields("acctest", fields, map[string]string{})134 a.AddFields("acctest", fields, map[string]string{"acc": "test"})135 a.AddFields("acctest", fields, map[string]string{"acc": "test"}, now)136 testm := <-a.metrics137 actual := testm.String()138 assert.Contains(t, actual, "acctest usage=99i")139 testm = <-a.metrics140 actual = testm.String()141 assert.Contains(t, actual, "acctest,acc=test usage=99i")142 testm = <-a.metrics143 actual = testm.String()144 assert.Equal(t,145 fmt.Sprintf("acctest,acc=test usage=99i %d", now.UnixNano()),146 actual)147}148func TestAddUint64Overflow(t *testing.T) {149 a := accumulator{}150 now := time.Now()151 a.metrics = make(chan telegraf.Metric, 10)152 defer close(a.metrics)153 a.inputConfig = &internal_models.InputConfig{}154 fields := map[string]interface{}{155 "usage": uint64(9223372036854775808),156 }157 a.AddFields("acctest", fields, map[string]string{})158 a.AddFields("acctest", fields, map[string]string{"acc": "test"})159 a.AddFields("acctest", fields, map[string]string{"acc": "test"}, now)160 testm := <-a.metrics161 actual := testm.String()162 assert.Contains(t, actual, "acctest usage=9223372036854775807i")163 testm = <-a.metrics164 actual = testm.String()165 assert.Contains(t, actual, "acctest,acc=test usage=9223372036854775807i")166 testm = <-a.metrics167 actual = testm.String()168 assert.Equal(t,169 fmt.Sprintf("acctest,acc=test usage=9223372036854775807i %d", now.UnixNano()),170 actual)171}172func TestAddInts(t *testing.T) {173 a := accumulator{}174 a.addDefaultTag("default", "tag")175 now := time.Now()176 a.metrics = make(chan telegraf.Metric, 10)177 defer close(a.metrics)178 a.inputConfig = &internal_models.InputConfig{}179 a.Add("acctest", int(101), map[string]string{})180 a.Add("acctest", int32(101), map[string]string{"acc": "test"})181 a.Add("acctest", int64(101), map[string]string{"acc": "test"}, now)182 testm := <-a.metrics183 actual := testm.String()184 assert.Contains(t, actual, "acctest,default=tag value=101i")185 testm = <-a.metrics186 actual = testm.String()187 assert.Contains(t, actual, "acctest,acc=test,default=tag value=101i")188 testm = <-a.metrics189 actual = testm.String()190 assert.Equal(t,191 fmt.Sprintf("acctest,acc=test,default=tag value=101i %d", now.UnixNano()),192 actual)193}194func TestAddFloats(t *testing.T) {195 a := accumulator{}196 a.addDefaultTag("default", "tag")197 now := time.Now()198 a.metrics = make(chan telegraf.Metric, 10)199 defer close(a.metrics)200 a.inputConfig = &internal_models.InputConfig{}201 a.Add("acctest", float32(101), map[string]string{"acc": "test"})202 a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)203 testm := <-a.metrics204 actual := testm.String()205 assert.Contains(t, actual, "acctest,acc=test,default=tag value=101")206 testm = <-a.metrics207 actual = testm.String()208 assert.Equal(t,209 fmt.Sprintf("acctest,acc=test,default=tag value=101 %d", now.UnixNano()),210 actual)211}212func TestAddStrings(t *testing.T) {213 a := accumulator{}214 a.addDefaultTag("default", "tag")215 now := time.Now()216 a.metrics = make(chan telegraf.Metric, 10)217 defer close(a.metrics)218 a.inputConfig = &internal_models.InputConfig{}219 a.Add("acctest", "test", map[string]string{"acc": "test"})220 a.Add("acctest", "foo", map[string]string{"acc": "test"}, now)221 testm := <-a.metrics222 actual := testm.String()223 assert.Contains(t, actual, "acctest,acc=test,default=tag value=\"test\"")224 testm = <-a.metrics225 actual = testm.String()226 assert.Equal(t,227 fmt.Sprintf("acctest,acc=test,default=tag value=\"foo\" %d", now.UnixNano()),228 actual)229}230func TestAddBools(t *testing.T) {231 a := accumulator{}232 a.addDefaultTag("default", "tag")233 now := time.Now()234 a.metrics = make(chan telegraf.Metric, 10)235 defer close(a.metrics)236 a.inputConfig = &internal_models.InputConfig{}237 a.Add("acctest", true, map[string]string{"acc": "test"})238 a.Add("acctest", false, map[string]string{"acc": "test"}, now)239 testm := <-a.metrics240 actual := testm.String()241 assert.Contains(t, actual, "acctest,acc=test,default=tag value=true")242 testm = <-a.metrics243 actual = testm.String()244 assert.Equal(t,245 fmt.Sprintf("acctest,acc=test,default=tag value=false %d", now.UnixNano()),246 actual)247}...

Full Screen

Full Screen

metrics_test.go

Source:metrics_test.go Github

copy

Full Screen

...28 we, err := s.Client().DescribeWorkflowExecution(context.Background(), w.GetID(), w.GetRunID())29 assert.NoError(t, err)30 metrics, err := get()31 assert.NoError(t, err)32 assert.Contains(t, metrics, "request_attempt")33 assert.Contains(t, metrics, "schedule_to_start_latency")34 assert.Contains(t, metrics, "long_request_attempt")35 assert.Contains(t, metrics, "long_request_latency")36 assert.Contains(t, metrics, "long_request_latency_attempt")37 assert.Contains(t, metrics, "poller_start")38 assert.Contains(t, metrics, "request_attempt")39 assert.Contains(t, metrics, "request")40 assert.Contains(t, metrics, "request_latency_attempt")41 assert.Contains(t, metrics, "sticky_cache_size")42 assert.Contains(t, metrics, "worker_start")43 assert.Contains(t, metrics, "workflow_endtoend_latency")44 assert.Contains(t, metrics, "workflow_task_execution_latency")45 assert.Contains(t, metrics, "workflow_task_execution_latency_sum")46 assert.Contains(t, metrics, "samples_rr_activities_pool_queue_size")47 assert.Contains(t, metrics, "samples_rr_workflows_pool_queue_size")48 assert.Contains(t, metrics, "workflow_task_queue_poll_succeed")49 assert.Contains(t, metrics, "workflow_task_replay_latency")50 assert.Contains(t, metrics, "workflow_task_schedule_to_start_latency")51 assert.Equal(t, "Completed", we.WorkflowExecutionInfo.Status.String())52 stopCh <- struct{}{}53 wg.Wait()54}55// get request and return body56func get() (string, error) {57 r, err := http.Get("http://127.0.0.1:9095/metrics")58 if err != nil {59 return "", err60 }61 b, err := ioutil.ReadAll(r.Body)62 if err != nil {63 return "", err64 }...

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 http.Handle("/metrics", promhttp.Handler())4 go func() {5 http.ListenAndServe(":2112", nil)6 }()7 counter := promauto.NewCounter(prometheus.CounterOpts{8 })9 counter.Add(1)10 fmt.Println("Running at port 2112")11 fmt.Println("Metrics available at /metrics")12 fmt.Println("Press enter to stop")13 fmt.Scanln()14}15 Loaded: loaded (/lib/systemd/system/prometheus.service; enabled; vendor preset: enabled)16 Active: active (running) since Wed 2020-12-09 16:39:24 UTC; 2min 22s ago

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 http.Handle("/metrics", promhttp.Handler())4 fmt.Println("Server is running on port 8080")5 http.ListenAndServe(":8080", nil)6}7import (8func main() {9 http.Handle("/metrics", promhttp.Handler())10 fmt.Println("Server is running on port 8080")11 http.ListenAndServe(":8080", nil)12}

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := prometheus.NewRegistry()4 h := prometheus.NewHistogram(prometheus.HistogramOpts{5 Buckets: prometheus.LinearBuckets(5, 5, 5),6 })7 r.MustRegister(h)8 h.Observe(15.0)9 if r.MetricFamilySamples()[0].GetName() == "example_histogram" {10 fmt.Println("Histogram is registered with the registry")11 } else {12 fmt.Println("Histogram is not registered with the registry")13 }14}15import (16func main() {17 r := prometheus.NewRegistry()18 h := prometheus.NewHistogram(prometheus.HistogramOpts{19 Buckets: prometheus.LinearBuckets(5, 5, 5),20 })21 r.MustRegister(h)22 h.Observe(15.0)23 m, err := h.GetMetricWithLabelValues("example_label")24 if err != nil {25 fmt.Println(err)26 }27 m.Observe(20.0)28 if r.MetricFamilySamples()[0].GetName() == "example_histogram" {29 fmt.Println("Histogram is registered with the registry")30 } else {31 fmt.Println("Histogram is not registered with the registry")32 }33}34import (

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := metrics.New()4 m.Add("foo", 1)5 m.Add("bar", 2)6 m.Add("baz", 3)7 fmt.Println(m.Contains("foo"))8 fmt.Println(m.Contains("bar"))9 fmt.Println(m.Contains("baz"))10 fmt.Println(m.Contains("quux"))11}12import (13func main() {14 m := metrics.New()15 m.Add("foo", 1)16 m.Add("bar", 2)17 m.Add("baz", 3)18 fmt.Println(m.Get("foo"))19 fmt.Println(m.Get("bar"))20 fmt.Println(m.Get("baz"))21 fmt.Println(m.Get("quux"))22}23import (24func main() {25 m := metrics.New()26 m.Add("foo", 1)27 m.Add("bar", 2)28 m.Add("baz", 3)29 fmt.Println(m.Get("foo"))30 fmt.Println(m.Get("bar"))31 fmt.Println(m.Get("baz"))32 fmt.Println(m.Get("quux"))33}34import (35func main() {36 m := metrics.New()37 m.Add("foo", 1)38 m.Add("bar", 2)39 m.Add("baz", 3)40 fmt.Println(m.List())41}42import (43func main() {

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 m := prometheus.NewCounterVec(5 prometheus.CounterOpts{6 },7 []string{"label1", "label2"},8 m.WithLabelValues("val1", "val2").Inc()9 fmt.Println(m.MetricVec.Contains(prometheus.Labels{"label1": "val1", "label2": "val2"}))10}11import (12func main() {13 fmt.Println("Hello, playground")14 m := prometheus.NewCounter(15 prometheus.CounterOpts{16 },17 m.Inc()18 fmt.Println(m)19}20test_counter{} 121import (22func main() {23 fmt.Println("Hello, playground")24 m := prometheus.NewGauge(25 prometheus.GaugeOpts{26 },27 m.Inc()28 m.Add(10)29 fmt.Println(m)30}31test_gauge{} 1132import (33func main() {34 fmt.Println("Hello, playground")35 m := prometheus.NewHistogram(36 prometheus.HistogramOpts{37 },38 m.Observe(10

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := metric.New()4 m.Add(1)5 m.Add(2)6 m.Add(3)7}8import (9func main() {10 m := metric.New()11 m.Add(1)12 m.Add(2)13 m.Add(3)14}

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 metrics := skyline.NewMetrics()4 metrics.Add("metric1", 1.0)5 metrics.Add("metric2", 2.0)6 metrics.Add("metric3", 3.0)7}8import (9func main() {10 metrics := skyline.NewMetrics()11 metrics.Add("metric1", 1.0)12 metrics.Add("metric2", 2.0)13 metrics.Add("metric3", 3.0)14}15import (16func main() {17 metrics := skyline.NewMetrics()18 metrics.Add("metric1", 1.0)19 metrics.Add("metric2", 2.0)20 metrics.Add("metric3", 3.0)21}22import (23func main() {24 metrics := skyline.NewMetrics()

Full Screen

Full Screen

Contains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 metrics := metrics.NewMetrics()4 metrics.Add("a", 1)5 metrics.Add("b", 2)6 metrics.Add("c", 3)7}

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 K6 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