Skip to content

Commit

Permalink
adjust bld prometheus ext test for concurrent tests, cross namespace …
Browse files Browse the repository at this point in the history
…builds
  • Loading branch information
gabemontero committed Dec 6, 2017
1 parent d1561b6 commit bc923a2
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions test/extended/prometheus/prometheus_builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ var _ = g.Describe("[Feature:Prometheus][Feature:Builds] Prometheus", func() {
activeTests := map[string][]metricTest{
activeBuildQuery: {
metricTest{
labels: map[string]string{"name": "frontend-1"},
greaterThan: true,
labels: map[string]string{"name": "frontend-1"},
greaterThanEqual: true,
},
},
}
Expand All @@ -88,14 +88,16 @@ var _ = g.Describe("[Feature:Prometheus][Feature:Builds] Prometheus", func() {
terminalTests := map[string][]metricTest{
buildCountQuery: {
metricTest{
labels: map[string]string{"phase": string(buildapi.BuildPhaseComplete)},
greaterThan: true,
labels: map[string]string{"phase": string(buildapi.BuildPhaseComplete)},
greaterThanEqual: true,
},
metricTest{
labels: map[string]string{"phase": string(buildapi.BuildPhaseCancelled)},
labels: map[string]string{"phase": string(buildapi.BuildPhaseCancelled)},
greaterThanEqual: true,
},
metricTest{
labels: map[string]string{"phase": string(buildapi.BuildPhaseFailed)},
labels: map[string]string{"phase": string(buildapi.BuildPhaseFailed)},
greaterThanEqual: true,
},
},
}
Expand All @@ -120,10 +122,14 @@ type prometheusResponseData struct {
}

type metricTest struct {
labels map[string]string
greaterThan bool
value float64
success bool
labels map[string]string
// we are not more precise (greater than only, or equal only) becauses the extended build tests
// run in parallel on the CI system, and some of the metrics are cross namespace, so we cannot
// reliably filter; we do precise count validation in the unit tests, where "entire cluster" activity
// is more controlled :-)
greaterThanEqual bool
value float64
success bool
}

func runQueries(metricTests map[string][]metricTest) {
Expand Down Expand Up @@ -209,10 +215,10 @@ func labelsWeWant(sample *model.Sample, labels map[string]string) bool {
}

func valueWeWant(sample *model.Sample, tc metricTest) bool {
//NOTE - we could use SampleValue has an Equals func, but since SampleValue has no GreaterThan,
//NOTE - we could use SampleValue has an Equals func, but since SampleValue has no GreaterThanEqual,
// we have to go down the float64 compare anyway
if tc.greaterThan {
return float64(sample.Value) > tc.value
if tc.greaterThanEqual {
return float64(sample.Value) >= tc.value
}
return float64(sample.Value) == tc.value
return float64(sample.Value) < tc.value
}

0 comments on commit bc923a2

Please sign in to comment.