Skip to content

Commit

Permalink
test: add k8s test spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-newrelic committed Feb 25, 2025
1 parent 145feb5 commit e0e0dfd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
7 changes: 2 additions & 5 deletions distributions/nrdot-collector-host/test-spec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
fast:
testCaseSpecs:
- on_host
slow:
testCaseSpecs:
- on_host
- host
nightly:
ec2:
enabled: true
testCaseSpecs:
- on_host
- host
8 changes: 3 additions & 5 deletions distributions/nrdot-collector-k8s/test-spec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
fast:
testCaseSpecs:
- on_host
slow:
testCaseSpecs:
- on_host
- k8s
- host
nightly:
ec2:
enabled: false
testCaseSpecs:
- on_host
- host
2 changes: 1 addition & 1 deletion test/e2e/hostmetrics_nightly/hostmetrics_nightly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestNightly(t *testing.T) {
assertion := assertionFactory.NewNrMetricAssertion(testCase.Metric, testCase.Assertions)
// space out requests to avoid rate limiting
time.Sleep(time.Duration(counter) * requestSpacing)
assertion.ExecuteWithRetries(t, client, 15, 5*time.Second)
assertion.ExecuteWithRetries(t, client, 24, 5*time.Second)
})
counter += 1
}
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/hostmetrics_slow/hostmetrics_slow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ func TestSlow(t *testing.T) {
client := nr.NewClient()

testEnvironment := map[string]string{
"hostName": testChart.NrQueryHostNamePattern,
"hostName": testChart.NrQueryHostNamePattern,
"clusterName": kubectlOptions.ContextName,
}
for _, testCaseSpecName := range testSpec.Slow.TestCaseSpecs {
testCaseSpec := spec.LoadTestCaseSpec(testCaseSpecName)
whereClause := testCaseSpec.RenderWhereClause(testEnvironment)
t.Logf("test case spec where clause: %s", whereClause)

counter := 0
for caseName, testCase := range testCaseSpec.TestCases {
t.Run(fmt.Sprintf(caseName), func(t *testing.T) {
t.Run(fmt.Sprintf("%s/%s", testCaseSpecName, caseName), func(t *testing.T) {
t.Parallel()
assertionFactory := assert.NewNrMetricAssertionFactory(
whereClause,
Expand All @@ -59,7 +61,7 @@ func TestSlow(t *testing.T) {
assertion := assertionFactory.NewNrMetricAssertion(testCase.Metric, testCase.Assertions)
// space out requests to avoid rate limiting
time.Sleep(time.Duration(counter) * requestSpacing)
assertion.ExecuteWithRetries(t, client, 15, 5*time.Second)
assertion.ExecuteWithRetries(t, client, 24, 5*time.Second)
})
counter += 1
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/util/assert/nr_metric_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (m *NrMetricAssertion) ExecuteWithRetries(t testing.TB, client *newrelic.Ne
t.Logf("Assertion attempt %d failed with: %+v", attempt, err)
}
}
t.Fatalf("Assertions failed after %d attempts", retries)
t.Fatalf("Assertions failed after %d attempts using query: %s", retries, nrdb.NRQL(m.AsQuery()))
}

func (m *NrMetricAssertion) execute(client *newrelic.NewRelic) error {
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions test/e2e/util/spec/k8s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
whereClause:
template: "WHERE k8s.cluster.name='{{ .clusterName }}'"
vars:
- clusterName

# TODO: add more, just one example test case to ensure the overall setup works
testCases:
host_receiver_cpu.utilization_user:
metric:
name: k8s.pod.cpu.utilization
assertions:
- aggregationFunction: max
comparisonOperator: ">"
threshold: 0

0 comments on commit e0e0dfd

Please sign in to comment.