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:
parent
545fe31ad6
commit
fc4994c93c
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
|
@ -32,8 +31,6 @@ import (
|
|||
// to an expected output in the Prometheus text exposition format.
|
||||
// metricNames allows only comparing the given metrics. All are compared if it's nil.
|
||||
func GatherAndCompare(c prometheus.Collector, expected string, metricNames ...string) error {
|
||||
expected = removeUnusedWhitespace(expected)
|
||||
|
||||
reg := prometheus.NewPedanticRegistry()
|
||||
if err := reg.Register(c); err != nil {
|
||||
return fmt.Errorf("registering collector failed: %s", err)
|
||||
|
@ -100,26 +97,6 @@ func filterMetrics(metrics []*dto.MetricFamily, names []string) []*dto.MetricFam
|
|||
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
|
||||
// label pair sorting.
|
||||
// https://github.com/prometheus/client_golang/blob/ea6e1db4cb8127eeb0b6954f7320363e5451820f/prometheus/registry.go#L642-L684
|
||||
|
|
|
@ -22,7 +22,8 @@ func TestGatherAndCompare(t *testing.T) {
|
|||
c.Inc()
|
||||
|
||||
expected := `
|
||||
some_total{label1="value1"} 1
|
||||
|
||||
some_total{ label1 = "value1" } 1
|
||||
`
|
||||
|
||||
if err := GatherAndCompare(c, metadata+expected, "some_total"); err != nil {
|
||||
|
|
Loading…
Reference in New Issue