Remove removeUnusedWhitespace

It wasn't needed, as is now proven by the tests

Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
beorn7 2018-08-22 23:54:26 +02:00
parent 545fe31ad6
commit fc4994c93c
2 changed files with 2 additions and 24 deletions

View File

@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"sort" "sort"
"strings"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
@ -32,8 +31,6 @@ import (
// to an expected output in the Prometheus text exposition format. // to an expected output in the Prometheus text exposition format.
// metricNames allows only comparing the given metrics. All are compared if it's nil. // metricNames allows only comparing the given metrics. All are compared if it's nil.
func GatherAndCompare(c prometheus.Collector, expected string, metricNames ...string) error { func GatherAndCompare(c prometheus.Collector, expected string, metricNames ...string) error {
expected = removeUnusedWhitespace(expected)
reg := prometheus.NewPedanticRegistry() reg := prometheus.NewPedanticRegistry()
if err := reg.Register(c); err != nil { if err := reg.Register(c); err != nil {
return fmt.Errorf("registering collector failed: %s", err) return fmt.Errorf("registering collector failed: %s", err)
@ -100,26 +97,6 @@ func filterMetrics(metrics []*dto.MetricFamily, names []string) []*dto.MetricFam
return filtered return filtered
} }
func removeUnusedWhitespace(s string) string {
var (
trimmedLine string
trimmedLines []string
lines = strings.Split(s, "\n")
)
for _, l := range lines {
trimmedLine = strings.TrimSpace(l)
if len(trimmedLine) > 0 {
trimmedLines = append(trimmedLines, trimmedLine)
}
}
// The Prometheus metrics representation parser expects an empty line at the
// end otherwise fails with an unexpected EOF error.
return strings.Join(trimmedLines, "\n") + "\n"
}
// The below sorting code is copied form the Prometheus client library modulo the added // The below sorting code is copied form the Prometheus client library modulo the added
// label pair sorting. // label pair sorting.
// https://github.com/prometheus/client_golang/blob/ea6e1db4cb8127eeb0b6954f7320363e5451820f/prometheus/registry.go#L642-L684 // https://github.com/prometheus/client_golang/blob/ea6e1db4cb8127eeb0b6954f7320363e5451820f/prometheus/registry.go#L642-L684

View File

@ -22,6 +22,7 @@ func TestGatherAndCompare(t *testing.T) {
c.Inc() c.Inc()
expected := ` expected := `
some_total{ label1 = "value1" } 1 some_total{ label1 = "value1" } 1
` `