Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #81 - Reduce log levels #92

Merged
merged 2 commits into from
Aug 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ func (b *Exporter) Listen(e <-chan Events) {
// We don't accept negative values for counters. Incrementing the counter with a negative number
// will cause the exporter to panic. Instead we will warn and continue to the next event.
if event.Value() < 0.0 {
log.Errorf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
log.Debugf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't seem to have a metric associated with it. But, I don't think it's that important.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add such a metric/error counter before reducing the log level though. Silently dropping metrics would be very annoying.

eventStats.WithLabelValues("illegal_negative_counter").Inc()
continue
}

Expand All @@ -287,7 +288,7 @@ func (b *Exporter) Listen(e <-chan Events) {

eventStats.WithLabelValues("counter").Inc()
} else {
log.Errorf(regErrF, metricName, err)
log.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("counter").Inc()
}

Expand All @@ -306,7 +307,7 @@ func (b *Exporter) Listen(e <-chan Events) {

eventStats.WithLabelValues("gauge").Inc()
} else {
log.Errorf(regErrF, metricName, err)
log.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("gauge").Inc()
}

Expand All @@ -330,7 +331,7 @@ func (b *Exporter) Listen(e <-chan Events) {
histogram.Observe(event.Value())
eventStats.WithLabelValues("timer").Inc()
} else {
log.Errorf(regErrF, metricName, err)
log.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("timer").Inc()
}

Expand All @@ -343,7 +344,7 @@ func (b *Exporter) Listen(e <-chan Events) {
summary.Observe(event.Value())
eventStats.WithLabelValues("timer").Inc()
} else {
log.Errorf(regErrF, metricName, err)
log.Debugf(regErrF, metricName, err)
conflictingEventStats.WithLabelValues("timer").Inc()
}

Expand All @@ -352,7 +353,7 @@ func (b *Exporter) Listen(e <-chan Events) {
}

default:
log.Errorln("Unsupported event type")
log.Debugln("Unsupported event type")
eventStats.WithLabelValues("illegal").Inc()
}
}
Expand Down Expand Up @@ -408,7 +409,7 @@ func parseDogStatsDTagsToLabels(component string) map[string]string {

if len(kv) < 2 || len(kv[1]) == 0 {
networkStats.WithLabelValues("malformed_dogstatsd_tag").Inc()
log.Errorf("Malformed or empty DogStatsD tag %s in component %s", t, component)
log.Debugf("Malformed or empty DogStatsD tag %s in component %s", t, component)
continue
}

Expand All @@ -426,7 +427,7 @@ func lineToEvents(line string) Events {
elements := strings.SplitN(line, ":", 2)
if len(elements) < 2 || len(elements[0]) == 0 || !utf8.ValidString(line) {
networkStats.WithLabelValues("malformed_line").Inc()
log.Errorln("Bad line from StatsD:", line)
log.Debugln("Bad line from StatsD:", line)
return events
}
metric := elements[0]
Expand All @@ -443,7 +444,7 @@ samples:
samplingFactor := 1.0
if len(components) < 2 || len(components) > 4 {
networkStats.WithLabelValues("malformed_component").Inc()
log.Errorln("Bad component on line:", line)
log.Debugln("Bad component on line:", line)
continue
}
valueStr, statType := components[0], components[1]
Expand All @@ -455,7 +456,7 @@ samples:

value, err := strconv.ParseFloat(valueStr, 64)
if err != nil {
log.Errorf("Bad value %s on line: %s", valueStr, line)
log.Debugf("Bad value %s on line: %s", valueStr, line)
networkStats.WithLabelValues("malformed_value").Inc()
continue
}
Expand All @@ -465,7 +466,7 @@ samples:
if len(components) >= 3 {
for _, component := range components[2:] {
if len(component) == 0 {
log.Errorln("Empty component on line: ", line)
log.Debugln("Empty component on line: ", line)
networkStats.WithLabelValues("malformed_component").Inc()
continue samples
}
Expand All @@ -475,13 +476,13 @@ samples:
switch component[0] {
case '@':
if statType != "c" && statType != "ms" {
log.Errorln("Illegal sampling factor for non-counter metric on line", line)
log.Debugln("Illegal sampling factor for non-counter metric on line", line)
networkStats.WithLabelValues("illegal_sample_factor").Inc()
continue
}
samplingFactor, err = strconv.ParseFloat(component[1:], 64)
if err != nil {
log.Errorf("Invalid sampling factor %s on line %s", component[1:], line)
log.Debugf("Invalid sampling factor %s on line %s", component[1:], line)
networkStats.WithLabelValues("invalid_sample_factor").Inc()
}
if samplingFactor == 0 {
Expand All @@ -496,7 +497,7 @@ samples:
case '#':
labels = parseDogStatsDTagsToLabels(component)
default:
log.Errorf("Invalid sampling factor or tag section %s on line %s", components[2], line)
log.Debugf("Invalid sampling factor or tag section %s on line %s", components[2], line)
networkStats.WithLabelValues("invalid_sample_factor").Inc()
continue
}
Expand All @@ -506,7 +507,7 @@ samples:
for i := 0; i < multiplyEvents; i++ {
event, err := buildEvent(statType, metric, value, relative, labels)
if err != nil {
log.Errorf("Error building event on line %s: %s", line, err)
log.Debugf("Error building event on line %s: %s", line, err)
networkStats.WithLabelValues("illegal_event").Inc()
continue
}
Expand Down Expand Up @@ -564,13 +565,13 @@ func (l *StatsDTCPListener) handleConn(c *net.TCPConn, e chan<- Events) {
if err != nil {
if err != io.EOF {
networkStats.WithLabelValues("tcp_error").Inc()
log.Errorf("Read %s failed: %v", c.RemoteAddr(), err)
log.Debugf("Read %s failed: %v", c.RemoteAddr(), err)
}
break
}
if isPrefix {
networkStats.WithLabelValues("tcp_line_too_long").Inc()
log.Errorf("Read %s failed: line too long", c.RemoteAddr())
log.Debugf("Read %s failed: line too long", c.RemoteAddr())
break
}
e <- lineToEvents(string(line))
Expand Down