Skip to content

Commit

Permalink
Skip adding metrics to logger if logger is not used
Browse files Browse the repository at this point in the history
If --log_path="" and --proxyLogDir="" then s.Logger == nil so we
shouldnt save any metrics

Test: I cannot reproduce in an integration test but this should
eliminate any chance of a panic here
Bug: b/300041630

Change-Id: Id7239d31a6c5c3d5bdf548f3d5f863fe418878c3
GitOrigin-RevId: e73330678ee8f635b91eaf80c4f1a0db50e7e81a
  • Loading branch information
bentekkie authored and copybara-github committed Sep 13, 2023
1 parent 12f7982 commit 55b9dd0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ func New(format Format, dir, includeScanner string, s statCollector, mi *ignorem

// AddEventTimeToProxyInfo will add an reproxy level event to the ProxyInfo object.
func (l *Logger) AddEventTimeToProxyInfo(key string, from, to time.Time) {
if l == nil {
return
}
// A call to this function should be very rare so locking should be ok.
l.mu.Lock()
defer l.mu.Unlock()
Expand All @@ -424,6 +427,9 @@ func (l *Logger) AddEventTimeToProxyInfo(key string, from, to time.Time) {

// AddEventTimesToProxyInfo will add a map of reproxy level events to the ProxyInfo object.
func (l *Logger) AddEventTimesToProxyInfo(m map[string]*cpb.TimeInterval) {
if l == nil {
return
}
// A call to this function should be very rare so locking should be ok.
l.mu.Lock()
defer l.mu.Unlock()
Expand All @@ -434,6 +440,9 @@ func (l *Logger) AddEventTimesToProxyInfo(m map[string]*cpb.TimeInterval) {

// AddMetricIntToProxyInfo will add an reproxy level event to the ProxyInfo object.
func (l *Logger) AddMetricIntToProxyInfo(key string, value int64) {
if l == nil {
return
}
// A call to this function should be very rare so locking should be ok.
l.mu.Lock()
defer l.mu.Unlock()
Expand All @@ -442,6 +451,9 @@ func (l *Logger) AddMetricIntToProxyInfo(key string, value int64) {

// IncrementMetricIntToProxyInfo will increment a reproxy level event to the ProxyInfo object.
func (l *Logger) IncrementMetricIntToProxyInfo(key string, delta int64) {
if l == nil {
return
}
// A call to this function should be very rare so locking should be ok.
l.mu.Lock()
defer l.mu.Unlock()
Expand All @@ -459,6 +471,9 @@ func (l *Logger) IncrementMetricIntToProxyInfo(key string, delta int64) {

// AddMetricDoubleToProxyInfo will add an reproxy level event to the ProxyInfo object.
func (l *Logger) AddMetricDoubleToProxyInfo(key string, value float64) {
if l == nil {
return
}
// A call to this function should be very rare so locking should be ok.
l.mu.Lock()
defer l.mu.Unlock()
Expand All @@ -467,6 +482,9 @@ func (l *Logger) AddMetricDoubleToProxyInfo(key string, value float64) {

// AddMetricBoolToProxyInfo will add an reproxy level event to the ProxyInfo object.
func (l *Logger) AddMetricBoolToProxyInfo(key string, value bool) {
if l == nil {
return
}
// A call to this function should be very rare so locking should be ok.
l.mu.Lock()
defer l.mu.Unlock()
Expand All @@ -475,6 +493,9 @@ func (l *Logger) AddMetricBoolToProxyInfo(key string, value bool) {

// AddFlagStringToProxyInfo will add an reproxy flag to the ProxyInfo object.
func (l *Logger) AddFlagStringToProxyInfo(key string, value string) {
if l == nil {
return
}
// A call to this function could be very frequent, so it's required to lock the
// entire section of adding flags.
l.mu.Lock()
Expand All @@ -490,6 +511,9 @@ func (l *Logger) AddFlagStringToProxyInfo(key string, value string) {

// AddFlags will add all reproxy flags to the ProxyInfo object.
func (l *Logger) AddFlags(flagSet *flag.FlagSet) {
if l == nil {
return
}
if flagSet == nil {
log.Warningf("nil FlagSet pointer")
return
Expand Down

0 comments on commit 55b9dd0

Please sign in to comment.