func Increment() {
	if EnableCounting {
		NetMonitor.increment()
	}
}
Increment increases the all request counters by 1, signifying an HTTP
request to GCR has been made.
package reqcounter
import (
	"fmt"
	"sync"
	"time"
	"github.com/sirupsen/logrus"
	tw "sigs.k8s.io/promo-tools/v3/legacy/timewrapper"
)
type RequestCounter struct {
	Mutex     sync.Mutex     
	Requests  uint64         
	Since     time.Time      
	Interval  time.Duration  
	Threshold uint64         
}
func (rc *RequestCounter) Increment() {
	rc.Mutex.Lock()
	rc.Requests++
	rc.Mutex.Unlock()
}
func (rc *RequestCounter) Flush() {
	rc.Mutex.Lock()
	defer rc.Mutex.Unlock()
	rc.log()
	if rc.Threshold > 0 {
		rc.reset()
	}
}
func (rc *RequestCounter) log() {
	msg := fmt.Sprintf("From %s to %s [%d min] there have been %d requests to GCR.", rc.Since.Format(TimestampFormat), Clock.Now().Format(TimestampFormat), rc.Interval/time.Minute, rc.Requests)
	Debug(msg)
	if rc.Threshold > 0 && rc.Requests > rc.Threshold {
		msg = fmt.Sprintf("The threshold of %d requests has been surpassed.", rc.Threshold)
		Warn(msg)
	}
}
func (rc *RequestCounter) reset() {
	rc.Requests = 0
	rc.Since = Clock.Now()
}
func (rc *RequestCounter) watch() {
	go func() {
		for {
			rc.Cycle()
		}
	}()
}
func (rc *RequestCounter) Cycle() {
	Clock.Sleep(rc.Interval)
	rc.Flush()
}
type RequestCounters []*RequestCounter
type NetworkMonitor struct {
	RequestCounters RequestCounters
}
func (nm *NetworkMonitor) increment() {
	for _, rc := range nm.RequestCounters {
		rc.Increment()
	}
}
func (nm *NetworkMonitor) Log() {
	for _, rc := range nm.RequestCounters {
		rc.watch()
	}
}
const (
	QuotaWindowShort time.Duration = time.Minute * 10
	QuotaWindowLong time.Duration = time.Hour * 24
	TimestampFormat string = "2006-01-02 15:04:05"
)
var (
	EnableCounting bool
	NetMonitor *NetworkMonitor
	Debug func(args ...interface{}) = logrus.Debug
	Warn func(args ...interface{}) = logrus.Warn
	Clock tw.Time = tw.RealTime{}
)
func Init() {
	EnableCounting = true
	requestCounters := RequestCounters{
		{
			Mutex:     sync.Mutex{},
			Requests:  0,
			Since:     Clock.Now(),
			Interval:  QuotaWindowShort,
			Threshold: 50000,
		},
		{
			Mutex:     sync.Mutex{},
			Requests:  0,
			Since:     Clock.Now(),
			Interval:  QuotaWindowLong,
			Threshold: 1000000,
		},
		{
			Mutex:    sync.Mutex{},
			Requests: 0,
			Since:    Clock.Now(),
			Interval: QuotaWindowShort,
		},
	}
	NetMonitor = &NetworkMonitor{
		RequestCounters: requestCounters,
	}
	NetMonitor.Log()
}