[amazon-cloudwatch-agent-test] Add scraper routing integration tests - #724
wenegiemepraise wants to merge 1 commit into
Conversation
| // carries no scraperRole (default role: claims only unannotated monitors). The two roles are | ||
| // complementary, giving exactly-one ownership. | ||
| func TestScraperRoleWiring(t *testing.T) { | ||
| assert.Equal(t, clusterScraperRoleValue, scraperRoleOf(t, clusterScraperAgentName), |
There was a problem hiding this comment.
TestScraperRoleWiring only reads the rendered scraperRole and the health test only checks the Target Allocator is up, so neither actually proves routing. Could we annotate one monitor and assert via each /jobs that the annotated job lands only on cluster-scraper and the bare one only on per-node?
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| dep, err := clientset.AppsV1().Deployments(agentNamespace).Get(ctx, clusterScraperTADeploymentName, metav1.GetOptions{}) |
There was a problem hiding this comment.
The harness only provisions cloudwatch-agent, so the cluster-scraper CR and its Target Allocator never render and these tests fail NotFound, and patch_cr only patches the custom image onto cloudwatch-agent. Could we render both agents and patch that image onto the cluster-scraper CR too?
| // monitor is owned by exactly one agent (no double-scrape, no gap). | ||
| // | ||
| // These assertions are deterministic and checkable out-of-cluster (CR spec + TA Deployment health); | ||
| // the per-monitor claim is exercised by the operator unit test TestAnnotationRoleMatches. |
There was a problem hiding this comment.
This deferral comment points at TestAnnotationRoleMatches, which is just a predicate unit test, rather than TestLoadConfigScraperRouting where an annotated monitor actually gets filtered into the scrape jobs. Could we repoint it so readers chasing routing land on the real test?
| return role | ||
| } | ||
|
|
||
| func unstructuredNestedString(obj map[string]interface{}, fields ...string) (string, bool, error) { |
There was a problem hiding this comment.
unstructuredNestedString reimplements unstructured.NestedString from a package that's already in the graph and can never actually return an error, so the error it returns and the require.NoError at :64 are both dead. Could we just use unstructured.NestedString?
| // scraperRoleOf reads spec.targetAllocator.prometheusCR.scraperRole from an AmazonCloudWatchAgent CR. | ||
| func scraperRoleOf(t *testing.T, agentName string) string { | ||
| t.Helper() | ||
| restConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath()) |
There was a problem hiding this comment.
scraperRoleOf rebuilds its own restConfig and dynamic client on every call, the health test duplicates deploymentAvailable from ta_resilience_test.go, and one 30s context covers both calls. Could we centralize the client and health helpers in k8s_helpers_test.go and give each call its own context?
|
Checklist posted for the PR author to move into the PR description under a PR Checklist
|
6a689d5 to
96dc0dd
Compare
…tests Adds tests for the cloudwatch.aws/scraper: cluster-scraper routing partition: the cluster-scraper AmazonCloudWatchAgent CR carries scraperRole=cluster-scraper while the per-node agent carries none, the cluster-scraper Target Allocator is Available and not crashlooping, and each Target Allocator's /jobs shows it owns only its side of the partition so monitors are neither double-scraped nor dropped. Verified: make simple-lint passes; go vet -tags integration ./test/otel/pernode/... is clean.
96dc0dd to
46ee70b
Compare
Summary
Add annotation-based scraper-routing integration tests to the
test/otel/pernodesuite (integrationbuild tag).What
TestScraperRoleWiring: the cluster-scraperAmazonCloudWatchAgentCR carriesspec.targetAllocator.prometheusCR.scraperRole=cluster-scraperand the per-node agent carries none (default role) — the annotation-routing partition wiring.TestClusterScraperTargetAllocatorHealthy: the operator built the cluster-scraper Target Allocator Deployment and it is Available and not crashlooping.Testing
go vet -tags integration ./test/otel/pernode/clean. Run against a cluster with the SR operator + helm PRs deployed:KUBECONFIG=... CLUSTER_NAME=<c> AWS_REGION=<r> go test -tags integration ./test/otel/pernode/ -run 'TestScraperRoleWiring|TestClusterScraperTargetAllocatorHealthy' -vDependencies
Exercises the SR operator (aws/amazon-cloudwatch-agent-operator#399) + helm PRs. Stacks on the E2E suite (#720,
pernode-e2e).