refactor: use go-kit logger instead of deprecated common log package

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2021-06-07 16:00:08 +02:00
parent 5f419f96dd
commit 278a862099
No known key found for this signature in database
GPG key ID: 31AB0439F4C5C90E
3 changed files with 22 additions and 12 deletions

View file

@ -325,7 +325,7 @@ func main() {
defer close(events)
eventQueue := event.NewEventQueue(events, *eventFlushThreshold, *eventFlushInterval, eventsFlushed)
thisMapper := &mapper.MetricMapper{Registerer: prometheus.DefaultRegisterer, MappingsCount: mappingsCount}
thisMapper := &mapper.MetricMapper{Registerer: prometheus.DefaultRegisterer, MappingsCount: mappingsCount, Logger: logger}
cache, err := getCache(*cacheSize, *cacheType, thisMapper.Registerer)
if err != nil {

View file

@ -14,10 +14,12 @@
package fsm
import (
"fmt"
"regexp"
"strings"
"github.com/prometheus/common/log"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
)
type mappingState struct {
@ -232,7 +234,7 @@ func (f *FSM) GetMapping(statsdMetric string, statsdMetricType string) (*mapping
// TestIfNeedBacktracking tests if backtrack is needed for given list of mappings
// and whether ordering is disabled.
func TestIfNeedBacktracking(mappings []string, orderingDisabled bool) bool {
func TestIfNeedBacktracking(mappings []string, orderingDisabled bool, logger log.Logger) bool {
backtrackingNeeded := false
// A has * in rules, but there's other transisitions at the same state,
// this makes A the cause of backtracking
@ -248,7 +250,7 @@ func TestIfNeedBacktracking(mappings []string, orderingDisabled bool) bool {
metricRe = strings.Replace(metricRe, "*", "([^.]*)", -1)
regex, err := regexp.Compile("^" + metricRe + "$")
if err != nil {
log.Warnf("invalid match %s. cannot compile regex in mapping: %v", mapping, err)
level.Warn(logger).Log("msg", fmt.Sprintf("invalid match %s. cannot compile regex in mapping: %v", mapping, err))
}
// put into array no matter there's error or not, we will skip later if regex is nil
ruleREByLength[l] = append(ruleREByLength[l], regex)
@ -291,8 +293,8 @@ func TestIfNeedBacktracking(mappings []string, orderingDisabled bool) bool {
if i2 != i1 && len(re1.FindStringSubmatchIndex(r2)) > 0 {
// log if we care about ordering and the superset occurs before
if !orderingDisabled && i1 < i2 {
log.Warnf("match \"%s\" is a super set of match \"%s\" but in a lower order, "+
"the first will never be matched", r1, r2)
level.Warn(logger).Log("msg", fmt.Sprintf("match \"%s\" is a super set of match \"%s\" but in a lower order, "+
"the first will never be matched", r1, r2))
}
currentRuleNeedBacktrack = false
}
@ -310,8 +312,8 @@ func TestIfNeedBacktracking(mappings []string, orderingDisabled bool) bool {
}
if currentRuleNeedBacktrack {
log.Warnf("backtracking required because of match \"%s\", "+
"matching performance may be degraded", r1)
level.Warn(logger).Log("msg", fmt.Sprintf("backtracking required because of match \"%s\", "+
"matching performance may be degraded", r1))
backtrackingNeeded = true
}
}

View file

@ -20,8 +20,9 @@ import (
"sync"
"time"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
yaml "gopkg.in/yaml.v2"
"github.com/prometheus/statsd_exporter/pkg/mapper/fsm"
@ -51,6 +52,8 @@ type MetricMapper struct {
mutex sync.RWMutex
MappingsCount prometheus.Gauge
Logger log.Logger
}
type SummaryOptions struct {
@ -163,12 +166,12 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
if currentMapping.LegacyQuantiles != nil &&
(currentMapping.SummaryOptions == nil || currentMapping.SummaryOptions.Quantiles != nil) {
log.Warn("using the top level quantiles is deprecated. Please use quantiles in the summary_options hierarchy")
level.Warn(m.Logger).Log("msg", "using the top level quantiles is deprecated. Please use quantiles in the summary_options hierarchy")
}
if currentMapping.LegacyBuckets != nil &&
(currentMapping.HistogramOptions == nil || currentMapping.HistogramOptions.Buckets != nil) {
log.Warn("using the top level buckets is deprecated. Please use buckets in the histogram_options hierarchy")
level.Warn(m.Logger).Log("msg", "using the top level buckets is deprecated. Please use buckets in the histogram_options hierarchy")
}
if currentMapping.SummaryOptions != nil &&
@ -245,7 +248,7 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
mappings = append(mappings, mapping.Match)
}
}
n.FSM.BacktrackingNeeded = fsm.TestIfNeedBacktracking(mappings, n.FSM.OrderingDisabled)
n.FSM.BacktrackingNeeded = fsm.TestIfNeedBacktracking(mappings, n.FSM.OrderingDisabled, m.Logger)
m.FSM = n.FSM
m.doRegex = n.doRegex
@ -255,6 +258,11 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
if m.MappingsCount != nil {
m.MappingsCount.Set(float64(len(n.Mappings)))
}
if m.Logger == nil {
m.Logger = log.NewNopLogger()
}
return nil
}