Skip to content

Commit

Permalink
Revert "Add presubmit to check stable metrics are stable"
Browse files Browse the repository at this point in the history
This reverts commit 68c8bda.
  • Loading branch information
CatherineF-dev committed Oct 19, 2022
1 parent 68c8bda commit abeb519
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 154 deletions.
108 changes: 0 additions & 108 deletions internal/store/stable_metrics_test.go

This file was deleted.

53 changes: 13 additions & 40 deletions internal/store/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,9 @@ type generateMetricsTestCase struct {
Want string
Headers []string
Func func(interface{}) []metric.FamilyInterface
DropHelp bool
}

type generateStableMetricsTestCase struct {
Name string
FilePath string
generateMetricsTestCase
}

func (testCase *generateMetricsTestCase) run() error {
out := testCase.generateOut()
testCase.Want, out = alignResult(testCase.Want, out)

if diff := cmp.Diff(testCase.Want, out); diff != "" {
return fmt.Errorf("expected wanted output to equal output: %w", fmt.Errorf("(-want, +got):\n%s", diff))
}
return nil
}

func (testCase *generateMetricsTestCase) runWithOutput() string {
out := testCase.generateOut()
out, _ = alignResult(out, out)
return out
}

func (testCase *generateMetricsTestCase) generateOut() string {
metricFamilies := testCase.Func(testCase.Obj)
metricFamilyStrings := []string{}
for _, f := range metricFamilies {
Expand All @@ -71,24 +48,31 @@ func (testCase *generateMetricsTestCase) generateOut() string {
metric := strings.Split(strings.Join(metricFamilyStrings, ""), "\n")
filteredMetrics := filterMetricNames(metric, testCase.MetricNames)
filteredHeaders := filterMetricNames(testCase.Headers, testCase.MetricNames)
if testCase.DropHelp {
filteredHeaders = dropHELP(filteredHeaders)
}
headers := strings.Join(filteredHeaders, "\n")
metrics := strings.Join(filteredMetrics, "\n")
out := headers + "\n" + metrics
return out

if err := compareOutput(testCase.Want, out); err != nil {
return fmt.Errorf("expected wanted output to equal output: %w", err)
}

return nil
}

func alignResult(expected, actual string) (string, string) {
func compareOutput(expected, actual string) error {
entities := []string{expected, actual}
// Align wanted and actual
for i := 0; i < len(entities); i++ {
for _, f := range []func(string) string{removeUnusedWhitespace, sortLabels, sortByLine} {
entities[i] = f(entities[i])
}
}
return entities[0], entities[1]

if diff := cmp.Diff(entities[0], entities[1]); diff != "" {
return fmt.Errorf("(-want, +got):\n%s", diff)
}

return nil
}

// sortLabels sorts the order of labels in each line of the given metric. The
Expand Down Expand Up @@ -157,17 +141,6 @@ func filterMetricNames(ms []string, names []string) []string {
return filtered
}

func dropHELP(header []string) []string {
filtered := []string{}
for _, ms := range header {
m := strings.Split(ms, "\n")
if len(m) == 2 && m[1][:6] == "# TYPE" {
filtered = append(filtered, m[1])
}
}
return filtered
}

func removeUnusedWhitespace(s string) string {
var (
trimmedLine string
Expand Down
6 changes: 0 additions & 6 deletions tests/testdata/stable_node_metrics.txt

This file was deleted.

0 comments on commit abeb519

Please sign in to comment.