How to use Peek method of gauge Package

Best Gauge code snippet using gauge.Peek

statstash_test.go

Source:statstash_test.go Github

copy

Full Screen

1// Copyright 2014 pendo.io2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14// Package statstash is a service used to collect statistics15// for a Google App Engine project and package them up to a backend server.16package statstash17import (18 "fmt"19 "math"20 "math/rand"21 "os"22 "time"23 "github.com/pendo-io/appwrap"24 "github.com/stretchr/testify/mock"25 . "gopkg.in/check.v1"26)27type MockFlusher struct {28 mock.Mock29 counters []StatDataCounter30 timings []StatDataTiming31 gauges []StatDataGauge32}33func (m *MockFlusher) Flush(data []interface{}, cfg *FlusherConfig) error {34 rargs := m.Called(data, cfg)35 m.counters = make([]StatDataCounter, 0)36 m.timings = make([]StatDataTiming, 0)37 m.gauges = make([]StatDataGauge, 0)38 for i := range data {39 switch data[i].(type) {40 case StatDataCounter:41 m.counters = append(m.counters, data[i].(StatDataCounter))42 case StatDataTiming:43 m.timings = append(m.timings, data[i].(StatDataTiming))44 case StatDataGauge:45 m.gauges = append(m.gauges, data[i].(StatDataGauge))46 }47 }48 return rargs.Error(0)49}50func (s *StatStashTest) newTestStatsStash() StatImplementation {51 ssi := NewStatInterface(appwrap.NewWriterLogger(os.Stderr), appwrap.NewLocalDatastore(false, nil), appwrap.NewLocalMemcache(), true).(StatImplementation)52 ssi.randGen = rand.New(rand.NewSource(time.Now().UnixNano()))53 return ssi54}55func (s *StatStashTest) TestStatCounters(c *C) {56 ssi := s.newTestStatsStash()57 c.Assert(ssi.IncrementCounter("TestStatCounters.foo", "a"), IsNil)58 c.Assert(ssi.IncrementCounter("TestStatCounters.foo", "a"), IsNil)59 c.Assert(ssi.IncrementCounter("TestStatCounters.foo", "b"), IsNil)60 c.Assert(ssi.IncrementCounter("TestStatCounters.bar", ""), IsNil)61 c.Assert(ssi.IncrementCounter("TestStatCounters.bar", ""), IsNil)62 c.Assert(ssi.IncrementCounterBy("TestStatCounters.bar", "", int64(10)), IsNil)63 now := time.Now()64 // at this point65 // foo, a = 266 fooA, err := ssi.peekCounter("TestStatCounters.foo", "a", now)67 c.Assert(err, IsNil)68 c.Check(fooA, Equals, uint64(2))69 // foo, b = 170 fooB, err := ssi.peekCounter("TestStatCounters.foo", "b", now)71 c.Assert(err, IsNil)72 c.Check(fooB, Equals, uint64(1))73 // bar = 174 bar, err := ssi.peekCounter("TestStatCounters.bar", "", now)75 c.Assert(err, IsNil)76 c.Check(bar, Equals, uint64(12))77}78func (s *StatStashTest) TestStatGauge(c *C) {79 ssi := s.newTestStatsStash()80 c.Assert(ssi.RecordGauge("TestStatGauge.subroutine", "A", 24.0), IsNil)81 c.Assert(ssi.RecordGauge("TestStatGauge.subroutine", "B", 10.0), IsNil)82 c.Assert(ssi.RecordGauge("TestStatGauge.subroutine", "B", 15.5), IsNil)83 c.Assert(ssi.RecordGauge("TestStatGauge.grand_total", "", 7264534001), IsNil)84 now := time.Now()85 subA, err := ssi.peekGauge("TestStatGauge.subroutine", "A", now)86 c.Assert(err, IsNil)87 c.Assert(subA, HasLen, 1)88 c.Check(subA[0], Equals, 24.0)89 subB, err := ssi.peekGauge("TestStatGauge.subroutine", "B", now)90 c.Assert(err, IsNil)91 c.Assert(subB, HasLen, 1)92 c.Check(subB[0], Equals, 15.5)93 grand, err := ssi.peekGauge("TestStatGauge.grand_total", "", now)94 c.Assert(err, IsNil)95 c.Assert(grand, HasLen, 1)96 c.Check(grand[0], Equals, float64(7264534001))97 for i := 0; i < 10; i++ {98 c.Assert(ssi.RecordGauge("TestStatGauge.upandtotheright", "", float64(i)), IsNil)99 }100 upAndToTheRight, err := ssi.peekGauge("TestStatGauge.upandtotheright", "", now)101 c.Assert(err, IsNil)102 c.Assert(upAndToTheRight, HasLen, 1)103 c.Check(upAndToTheRight[0], Equals, float64(9))104}105func (s *StatStashTest) TestStatTimings(c *C) {106 ssi := s.newTestStatsStash()107 c.Assert(ssi.RecordTiming("TestStatTimings.subroutine", "A", 24.0, 1.0), IsNil)108 c.Assert(ssi.RecordTiming("TestStatTimings.subroutine", "B", 10.0, 1.0), IsNil)109 c.Assert(ssi.RecordTiming("TestStatTimings.subroutine", "B", 15.5, 1.0), IsNil)110 c.Assert(ssi.RecordTiming("TestStatTimings.grand_total", "", 7264534001.0, 1.0), IsNil)111 now := time.Now()112 subA, err := ssi.peekTiming("TestStatTimings.subroutine", "A", now)113 c.Assert(err, IsNil)114 c.Assert(subA, HasLen, 1)115 c.Check(subA[0], Equals, 24.0)116 subB, err := ssi.peekTiming("TestStatTimings.subroutine", "B", now)117 c.Assert(err, IsNil)118 c.Assert(subB, HasLen, 2)119 c.Check(subB[0], Equals, 10.0)120 c.Check(subB[1], Equals, 15.5)121 grand, err := ssi.peekTiming("TestStatTimings.grand_total", "", now)122 c.Assert(err, IsNil)123 c.Assert(grand, HasLen, 1)124 c.Check(grand[0], Equals, 7264534001.0)125 for i := 0; i < 10; i++ {126 c.Assert(ssi.RecordTiming("TestStatTimings.upandtotheright", "", float64(i), 1.0), IsNil)127 }128 upAndToTheRight, err := ssi.peekTiming("TestStatTimings.upandtotheright", "", now)129 c.Assert(err, IsNil)130 for i, metric := range upAndToTheRight {131 c.Check(metric, Equals, float64(i))132 }133}134func (s *StatStashTest) TestGetActiveConfigs(c *C) {135 ssi := s.newTestStatsStash()136 c.Assert(ssi.Purge(), IsNil)137 c.Assert(ssi.IncrementCounter("TestGetActiveConfigs.foo", "a"), IsNil)138 c.Assert(ssi.IncrementCounter("TestGetActiveConfigs.foo", "a"), IsNil)139 c.Assert(ssi.IncrementCounter("TestGetActiveConfigs.foo", "b"), IsNil)140 c.Assert(ssi.IncrementCounter("TestGetActiveConfigs.bar", ""), IsNil)141 c.Assert(ssi.IncrementCounter("TestGetActiveConfigs.bar", ""), IsNil)142 c.Assert(ssi.IncrementCounterBy("TestGetActiveConfigs.bar", "", int64(10)), IsNil)143 now := time.Now()144 bucketTs := getStartOfFlushPeriod(now, 0).Unix()145 cfgMap, err := ssi.getActiveConfigs(now, 0)146 c.Assert(err, IsNil)147 c.Assert(cfgMap, HasLen, 3)148 for _, key := range []string{149 fmt.Sprintf("ss-metric:counter-TestGetActiveConfigs.foo-a-%d", bucketTs),150 fmt.Sprintf("ss-metric:counter-TestGetActiveConfigs.foo-b-%d", bucketTs),151 fmt.Sprintf("ss-metric:counter-TestGetActiveConfigs.bar--%d", bucketTs)} {152 _, found := cfgMap[key]153 c.Check(found, Equals, true)154 }155}156func (s *StatStashTest) TestFlushToBackend(c *C) {157 ssi := s.newTestStatsStash()158 mockFlusher := &MockFlusher{}159 c.Assert(ssi.Purge(), IsNil)160 c.Assert(ssi.IncrementCounter("TestFlushToBackend.foo", "a"), IsNil)161 c.Assert(ssi.IncrementCounter("TestFlushToBackend.foo", "a"), IsNil)162 c.Assert(ssi.IncrementCounter("TestFlushToBackend.foo", "b"), IsNil)163 c.Assert(ssi.IncrementCounter("TestFlushToBackend.bar", ""), IsNil)164 c.Assert(ssi.IncrementCounter("TestFlushToBackend.bar", ""), IsNil)165 c.Assert(ssi.IncrementCounterBy("TestFlushToBackend.bar", "", int64(10)), IsNil)166 c.Assert(ssi.RecordGauge("TestFlushToBackend.temperature", "raleigh", 24.0), IsNil)167 c.Assert(ssi.RecordGauge("TestFlushToBackend.temperature", "anchorage", 10.0), IsNil)168 c.Assert(ssi.RecordGauge("TestFlushToBackend.temperature", "anchorage", 15.5), IsNil)169 c.Assert(ssi.RecordGauge("TestFlushToBackend.temperature", "buffalo", -1.2), IsNil)170 c.Assert(ssi.RecordTiming("TestFlushToBackend.subroutine", "A", 24.0, 1.0), IsNil)171 c.Assert(ssi.RecordTiming("TestFlushToBackend.subroutine", "B", 10.0, 1.0), IsNil)172 c.Assert(ssi.RecordTiming("TestFlushToBackend.subroutine", "B", 15.5, 1.0), IsNil)173 for i := 0; i < 10; i++ {174 c.Assert(ssi.RecordTiming("TestFlushToBackend.upandtotheright", "", float64(i), 1.0), IsNil)175 }176 mockFlusher.On("Flush", mock.Anything, mock.Anything).Return(nil).Once()177 now := time.Now()178 c.Assert(ssi.UpdateBackend(now, mockFlusher, nil, true), IsNil)179 mockFlusher.AssertExpectations(c)180 c.Check(mockFlusher.counters, HasLen, 3)181 c.Check(mockFlusher.timings, HasLen, 3)182 c.Check(mockFlusher.gauges, HasLen, 3)183 for _, counter := range mockFlusher.counters {184 nameAndSource := fmt.Sprintf("%s-%s", counter.Name, counter.Source)185 switch nameAndSource {186 case "TestFlushToBackend.foo-a":187 c.Check(counter.Count, Equals, uint64(2))188 case "TestFlushToBackend.foo-b":189 c.Check(counter.Count, Equals, uint64(1))190 case "TestFlushToBackend.bar-":191 c.Check(counter.Count, Equals, uint64(12))192 }193 }194 for _, timing := range mockFlusher.timings {195 nameAndSource := fmt.Sprintf("%s-%s", timing.Name, timing.Source)196 switch nameAndSource {197 case "TestFlushToBackend.subroutine-A":198 c.Check(timing.Count, Equals, 1)199 c.Check(timing.Min, Equals, 24.0)200 c.Check(timing.Max, Equals, 24.0)201 c.Check(timing.Sum, Equals, 24.0)202 c.Check(timing.SumSquares, Equals, 576.0)203 c.Check(timing.Median, Equals, 24.0)204 c.Check(timing.NinthDecileCount, Equals, 1)205 c.Check(timing.NinthDecileValue, Equals, 24.0)206 c.Check(timing.NinthDecileSum, Equals, 24.0)207 case "TestFlushToBackend.subroutine-B":208 c.Check(timing.Count, Equals, 2)209 c.Check(timing.Min, Equals, 10.0)210 c.Check(timing.Max, Equals, 15.5)211 c.Check(timing.Sum, Equals, 25.5)212 c.Check(timing.SumSquares, Equals, 340.25)213 c.Check(timing.Median, Equals, 12.75)214 c.Check(timing.NinthDecileCount, Equals, 2)215 c.Check(timing.NinthDecileValue, Equals, 15.5)216 c.Check(timing.NinthDecileSum, Equals, 25.5)217 case "TestFlushToBackend.upandtotheright-":218 c.Check(timing.Count, Equals, 10)219 c.Check(timing.Min, Equals, 0.0)220 c.Check(timing.Max, Equals, 9.0)221 c.Check(timing.Sum, Equals, 45.0)222 c.Check(timing.SumSquares, Equals, 285.0)223 c.Check(timing.Median, Equals, 4.5)224 c.Check(timing.NinthDecileCount, Equals, 9)225 c.Check(timing.NinthDecileValue, Equals, 8.0)226 c.Check(timing.NinthDecileSum, Equals, 36.0)227 }228 }229 for _, gauge := range mockFlusher.gauges {230 nameAndSource := fmt.Sprintf("%s-%s", gauge.Name, gauge.Source)231 switch nameAndSource {232 case "TestFlushToBackend.foo-a":233 c.Check(gauge, Equals, 24.0)234 case "TestFlushToBackend.foo-b":235 c.Check(gauge, Equals, 15.5)236 case "TestFlushToBackend.bar-":237 c.Check(gauge, Equals, -1.2)238 }239 }240 // Make sure that flushing again does nothing (i.e. don't force)241 c.Assert(ssi.UpdateBackend(now, mockFlusher, nil, false), Equals, ErrStatFlushTooSoon)242}243func (s *StatStashTest) TestPeriodStart(c *C) {244 utc, _ := time.LoadLocation("UTC")245 ref := time.Date(2014, 10, 4, 12, 0, 0, 0, utc)246 c.Check(getStartOfFlushPeriod(ref, 0).Unix(), Equals, ref.Unix())247 c.Check(getStartOfFlushPeriod(ref.Add(1*time.Second), 0).Unix(), Equals, ref.Unix())248 c.Check(getStartOfFlushPeriod(ref, -1).Unix(), Equals, ref.Add(defaultAggregationPeriod*time.Duration(-1)).Unix())249 c.Check(getStartOfFlushPeriod(ref.Add(1*time.Second), -1).Unix(), Equals, ref.Add(defaultAggregationPeriod*time.Duration(-1)).Unix())250}251type StatSamplingTestImplementation struct {252 randGen *rand.Rand253}254func (c StatSamplingTestImplementation) IncrementCounter(name, source string) error { return nil }255func (c StatSamplingTestImplementation) IncrementCounterBy(name, source string, delta int64) error {256 return nil257}258func (c StatSamplingTestImplementation) RecordGauge(name, source string, value float64) error {259 return nil260}261func (c StatSamplingTestImplementation) RecordTiming(name, source string, value, sampleRate float64) error {262 // We use this code copied from the other code to prevent actually having to263 // use memcache and blowing up the test suite.264 if sampleRate < 1.0 && c.randGen.Float64() > sampleRate {265 return ErrStatNotSampled // do nothing here, as we are sampling266 }267 return nil268}269func (c StatSamplingTestImplementation) UpdateBackend(periodStart time.Time, flusher StatsFlusher, cfg *FlusherConfig, force bool) error {270 return nil271}272func (s *StatStashTest) TestTimingSampling(c *C) {273 ssi := StatSamplingTestImplementation{rand.New(rand.NewSource(time.Now().UnixNano()))}274 // Let's record a million timings at a sample rate of 0.0001.275 // We'll expect 100 samples, give or take 50276 statsSampled := 0277 for i := 0; i < 1000000; i++ {278 if err := ssi.RecordTiming("yowza", "fast", 1, 0.0001); err == ErrStatNotSampled {279 continue280 } else if err != nil {281 // unexpected error, fail282 c.Fail()283 } else {284 statsSampled++285 }286 }287 fmt.Printf("Stats sampled %d\n", statsSampled)288 c.Assert(math.Abs(100.0-float64(statsSampled)) <= 50.0, Equals, true)289}...

Full Screen

Full Screen

telemetry.go

Source:telemetry.go Github

copy

Full Screen

...105 case LegacyGaugeEndpoint:106 e.legacyGauge.incr(status)107 }108}109// PeekEndpointStatus increments the count of a specific status code for a specific endpoint110func (e *EndpointStatusCodes) PeekEndpointStatus(endpoint int) map[int]int64 {111 switch endpoint {112 case AuthEndpoint:113 return e.auth.peek()114 case SplitChangesEndpoint:115 return e.splitChanges.peek()116 case SegmentChangesEndpoint:117 return e.segmentChanges.peek()118 case MySegmentsEndpoint:119 return e.mySegments.peek()120 case ImpressionsBulkEndpoint:121 return e.impressionsBulk.peek()122 case ImpressionsBulkBeaconEndpoint:123 return e.impressionsBulkBeacon.peek()124 case ImpressionsCountEndpoint:125 return e.impressionsCount.peek()126 case ImpressionsCountBeaconEndpoint:127 return e.impressionsCountBeacon.peek()128 case EventsBulkEndpoint:129 return e.eventsBulk.peek()130 case EventsBulkBeaconEndpoint:131 return e.eventsBulkBeacon.peek()132 case TelemetryConfigEndpoint:133 return e.telemetryConfig.peek()134 case TelemetryRuntimeEndpoint:135 return e.telemetryRuntime.peek()136 case LegacyTimeEndpoint:137 return e.legacyTime.peek()138 case LegacyTimesEndpoint:139 return e.legacyTimes.peek()140 case LegacyCounterEndpoint:141 return e.legacyCounter.peek()142 case LegacyCountersEndpoint:143 return e.legacyCounters.peek()144 case LegacyGaugeEndpoint:145 return e.legacyGauge.peek()146 }147 return nil148}149func newEndpointStatusCodes() EndpointStatusCodes {150 return EndpointStatusCodes{151 auth: newStatusCodeMap(),152 splitChanges: newStatusCodeMap(),153 segmentChanges: newStatusCodeMap(),154 mySegments: newStatusCodeMap(),155 impressionsBulk: newStatusCodeMap(),156 impressionsBulkBeacon: newStatusCodeMap(),157 impressionsCount: newStatusCodeMap(),158 impressionsCountBeacon: newStatusCodeMap(),159 eventsBulk: newStatusCodeMap(),160 eventsBulkBeacon: newStatusCodeMap(),161 telemetryConfig: newStatusCodeMap(),162 telemetryRuntime: newStatusCodeMap(),163 legacyTime: newStatusCodeMap(),164 legacyTimes: newStatusCodeMap(),165 legacyCounter: newStatusCodeMap(),166 legacyCounters: newStatusCodeMap(),167 legacyGauge: newStatusCodeMap(),168 }169}170// ProxyEndpointLatencies defines an interface to access proxy server endpoint latencies numbers171type ProxyEndpointLatencies interface {172 PeekEndpointLatency(endpoint int) []int64173 RecordEndpointLatency(endpoint int, latency time.Duration)174}175// ProxyEndpointLatenciesImpl keep track of the latency introudiced by each proxy endpoint176type ProxyEndpointLatenciesImpl struct {177 auth inmemory.AtomicInt64Slice178 splitChanges inmemory.AtomicInt64Slice179 segmentChanges inmemory.AtomicInt64Slice180 mySegments inmemory.AtomicInt64Slice181 impressionsBulk inmemory.AtomicInt64Slice182 impressionsBulkBeacon inmemory.AtomicInt64Slice183 impressionsCount inmemory.AtomicInt64Slice184 impressionsCountBeacon inmemory.AtomicInt64Slice185 eventsBulk inmemory.AtomicInt64Slice186 eventsBulkBeacon inmemory.AtomicInt64Slice187 telemetryConfig inmemory.AtomicInt64Slice188 telemetryRuntime inmemory.AtomicInt64Slice189 legacyTime inmemory.AtomicInt64Slice190 legacyTimes inmemory.AtomicInt64Slice191 legacyCounter inmemory.AtomicInt64Slice192 legacyCounters inmemory.AtomicInt64Slice193 legacyGauge inmemory.AtomicInt64Slice194}195// RecordEndpointLatency records a (bucketed) latency for a specific endpoint196func (p *ProxyEndpointLatenciesImpl) RecordEndpointLatency(endpoint int, latency time.Duration) {197 bucket := telemetry.Bucket(latency.Milliseconds())198 switch endpoint {199 case AuthEndpoint:200 p.auth.Incr(bucket)201 case SplitChangesEndpoint:202 p.splitChanges.Incr(bucket)203 case SegmentChangesEndpoint:204 p.segmentChanges.Incr(bucket)205 case MySegmentsEndpoint:206 p.mySegments.Incr(bucket)207 case ImpressionsBulkEndpoint:208 p.impressionsBulk.Incr(bucket)209 case ImpressionsBulkBeaconEndpoint:210 p.impressionsBulkBeacon.Incr(bucket)211 case ImpressionsCountEndpoint:212 p.impressionsCount.Incr(bucket)213 case ImpressionsCountBeaconEndpoint:214 p.impressionsCountBeacon.Incr(bucket)215 case EventsBulkEndpoint:216 p.eventsBulk.Incr(bucket)217 case EventsBulkBeaconEndpoint:218 p.eventsBulkBeacon.Incr(bucket)219 case TelemetryConfigEndpoint:220 p.telemetryRuntime.Incr(bucket)221 case TelemetryRuntimeEndpoint:222 p.telemetryConfig.Incr(bucket)223 case LegacyTimeEndpoint:224 p.legacyTime.Incr(bucket)225 case LegacyTimesEndpoint:226 p.legacyTimes.Incr(bucket)227 case LegacyCounterEndpoint:228 p.legacyCounter.Incr(bucket)229 case LegacyCountersEndpoint:230 p.legacyCounters.Incr(bucket)231 case LegacyGaugeEndpoint:232 p.legacyGauge.Incr(bucket)233 }234}235// PeekEndpointLatency records a (bucketed) latency for a specific endpoint236func (p *ProxyEndpointLatenciesImpl) PeekEndpointLatency(endpoint int) []int64 {237 switch endpoint {238 case AuthEndpoint:239 return p.auth.ReadAll()240 case SplitChangesEndpoint:241 return p.splitChanges.ReadAll()242 case SegmentChangesEndpoint:243 return p.segmentChanges.ReadAll()244 case MySegmentsEndpoint:245 return p.mySegments.ReadAll()246 case ImpressionsBulkEndpoint:247 return p.impressionsBulk.ReadAll()248 case ImpressionsBulkBeaconEndpoint:249 return p.impressionsBulkBeacon.ReadAll()250 case ImpressionsCountEndpoint:251 return p.impressionsCount.ReadAll()252 case ImpressionsCountBeaconEndpoint:253 return p.impressionsCountBeacon.ReadAll()254 case EventsBulkEndpoint:255 return p.eventsBulk.ReadAll()256 case EventsBulkBeaconEndpoint:257 return p.eventsBulkBeacon.ReadAll()258 case TelemetryConfigEndpoint:259 return p.telemetryRuntime.ReadAll()260 case TelemetryRuntimeEndpoint:261 return p.telemetryConfig.ReadAll()262 case LegacyTimeEndpoint:263 return p.legacyTime.ReadAll()264 case LegacyTimesEndpoint:265 return p.legacyTimes.ReadAll()266 case LegacyCounterEndpoint:267 return p.legacyCounter.ReadAll()268 case LegacyCountersEndpoint:269 return p.legacyCounters.ReadAll()270 case LegacyGaugeEndpoint:271 return p.legacyGauge.ReadAll()272 }273 return nil274}275// newProxyEndpointLatenciesImpl creates a new latency tracker276func newProxyEndpointLatenciesImpl() ProxyEndpointLatenciesImpl {277 init := func() inmemory.AtomicInt64Slice {278 toRet, _ := inmemory.NewAtomicInt64Slice(telemetry.LatencyBucketCount)279 return toRet280 }281 return ProxyEndpointLatenciesImpl{282 auth: init(),283 splitChanges: init(),284 segmentChanges: init(),285 mySegments: init(),286 impressionsBulk: init(),287 impressionsBulkBeacon: init(),288 impressionsCount: init(),289 impressionsCountBeacon: init(),290 eventsBulk: init(),291 eventsBulkBeacon: init(),292 telemetryConfig: init(),293 telemetryRuntime: init(),294 legacyTime: init(),295 legacyTimes: init(),296 legacyCounter: init(),297 legacyCounters: init(),298 legacyGauge: init(),299 }300}301// ProxyTelemetryPeeker is able to peek at locally captured metrics302type ProxyTelemetryPeeker interface {303 PeekEndpointLatency(resource int) []int64304 PeekEndpointStatus(resource int) map[int]int64305}306// ProxyEndpointTelemetry defines the interface that endpoints use to capture latency & status codes307type ProxyEndpointTelemetry interface {308 ProxyTelemetryPeeker309 RecordEndpointLatency(endpoint int, latency time.Duration)310 IncrEndpointStatus(endpoint int, status int)311}312// ProxyTelemetryFacade defines the set of methods required to accept local telemetry as well as runtime telemetry313type ProxyTelemetryFacade interface {314 storage.TelemetryStorage315 storage.TelemetryPeeker316 ProxyEndpointTelemetry317}318// ProxyTelemetryFacadeImpl exposes local telemetry functionality319type ProxyTelemetryFacadeImpl struct {320 ProxyEndpointLatenciesImpl321 EndpointStatusCodes322 *inmemory.TelemetryStorage323}324// NewProxyTelemetryFacade instantiates a local telemetry facade325func NewProxyTelemetryFacade() *ProxyTelemetryFacadeImpl {326 ts, _ := inmemory.NewTelemetryStorage()327 return &ProxyTelemetryFacadeImpl{328 ProxyEndpointLatenciesImpl: newProxyEndpointLatenciesImpl(),329 EndpointStatusCodes: newEndpointStatusCodes(),330 TelemetryStorage: ts,331 }332}333// Ensure interface compliance334var _ ProxyTelemetryFacade = (*ProxyTelemetryFacadeImpl)(nil)335var _ storage.TelemetryStorage = (*ProxyTelemetryFacadeImpl)(nil)336var _ storage.TelemetryPeeker = (*ProxyTelemetryFacadeImpl)(nil)...

Full Screen

Full Screen

formatSpecification.go

Source:formatSpecification.go Github

copy

Full Screen

...26 if !strings.HasSuffix(formatter.buffer.String(), "\n\n") {27 formatter.buffer.WriteString("\n")28 }29 formatter.buffer.WriteString(FormatTags(tags))30 if formatter.itemQueue.Peek() != nil && (formatter.itemQueue.Peek().Kind() != gauge.CommentKind || strings.TrimSpace(formatter.itemQueue.Peek().(*gauge.Comment).Value) != "") {31 formatter.buffer.WriteString("\n")32 }33}34func (formatter *formatter) Table(table *gauge.Table) {35 formatter.buffer.WriteString(strings.TrimPrefix(FormatTable(table), "\n"))36}37func (formatter *formatter) DataTable(dataTable *gauge.DataTable) {38 if !dataTable.IsExternal {39 formatter.Table(dataTable.Table)40 } else {41 formatter.buffer.WriteString(formatExternalDataTable(dataTable))42 }43}44func (formatter *formatter) TearDown(t *gauge.TearDown) {...

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 gauge := prometheus.NewGauge(prometheus.GaugeOpts{4 })5 gauge.Set(10)6 fmt.Println(gauge.Get())7 fmt.Println(gauge.Peek())8}

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := metrics.NewGauge()4 g.Update(100)5 fmt.Println(g.Peek())6}

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := metrics.NewGauge()4 g.Update(100)5 fmt.Println(g.Value())6 g.Update(200)7 fmt.Println(g.Value())8 g.Update(300)9 fmt.Println(g.Value())10 g.Update(400)11 fmt.Println(g.Value())12 g.Update(500)13 fmt.Println(g.Value())14}

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := metrics.NewGauge()4 g.Update(100)5 fmt.Println("Gauge value:", g.Value())6 fmt.Println("Gauge value:", g.Peek())7}

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := gauge.NewGauge()4 g.Add(10)5 g.Add(20)6 fmt.Println(g.Peek())7 g.Add(30)8 fmt.Println(g.Peek())9 g.Add(40)10 fmt.Println(g.Peek())11 g.Add(50)12 fmt.Println(g.Peek())13}

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := gauge.NewGauge()4 g.Add(5)5 g.Add(10)6 g.Add(20)7 fmt.Printf("The current value is %d\n", g.Peek())8}

Full Screen

Full Screen

Peek

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 g := new(Gauge)4 g.Init(100)5 fmt.Println(g.Peek())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