Add OpenCost log inspector integration test.#104
Open
Aadarsh-Sankar wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds an integration test that inspects OpenCost pod logs for unexpected errors (panics, stack traces, and error-level messages), using a BATS test harness to invoke a Go test.
Changes:
- Adds a BATS test file that runs the Go-based log inspector test.
- Adds a Go test (
log_inspector_test.go) that fetches logs from OpenCost pods viakubectland flags suspicious lines (panics, goroutine dumps, ERR-level messages), with an allowlist mechanism.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/integration/observability/test.bats | BATS wrapper to invoke the Go log inspector test |
| test/integration/observability/log_inspector_test.go | Go test that fetches OpenCost pod logs and checks for unexpected errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+57
to
+60
| func stripAnsi(s string) string { | ||
| re := regexp.MustCompile(`\x1b\[[0-9;]*m`) //used to remove ANSI color codes | ||
| return re.ReplaceAllString(s, "") //return the string with the ANSI color codes removed | ||
| } |
| @@ -0,0 +1,4 @@ | |||
| #run go test files | |||
| @test "observability: OpenCost logs have no unexpected errors" { | |||
| go test ./test/integration/observability/log_inspector_test.go | |||
Scans OpenCost container logs for panics, stack traces, and ERR-level entries. Skips when kubectl is unavailable and supports an allow-list for known benign messages on test clusters. Fixes opencost#87 Signed-off-by: Aadarsh Sankar <aadarshsankar53@gmail.com>
… entries. Skips when kubectl is unavailable and supports an allow-list for known benign messages on test clusters. Fixes opencost#87 Signed-off-by: Aadarsh Sankar <aadarshsankar53@gmail.com>
Aadarsh-Sankar
force-pushed
the
issue-87-log-inspector
branch
from
June 16, 2026 17:12
1f3a086 to
9af2947
Compare
Comment on lines
+57
to
+60
| func stripAnsi(s string) string { | ||
| re := regexp.MustCompile(`\x1b\[[0-9;]*m`) //used to remove ANSI color codes | ||
| return re.ReplaceAllString(s, "") //return the string with the ANSI color codes removed | ||
| } |
Comment on lines
+35
to
+54
| var badLines []string //collect all the suspicious lines | ||
| for _, line := range lines { | ||
| if isSuspicious(line) { //if the line is suspicious | ||
| if isAllowlisted(line) { //if the line is allowlisted then skip it | ||
| continue | ||
| } | ||
| badLines = append(badLines, line) | ||
| } | ||
| } | ||
| t.Logf("found %d suspicious lines", len(badLines)) | ||
|
|
||
| if len(badLines) > 0 { | ||
| for i, line := range lines { | ||
| if !isSuspicious(line) || isAllowlisted(line) { | ||
| continue | ||
| } | ||
| t.Errorf("unexpected log issue at line %d:\n%s", i+1, formatContext(lines, i)) | ||
| } | ||
| t.Fatalf("found %d suspicious log lines", len(badLines)) | ||
| } |
| @@ -0,0 +1,4 @@ | |||
| #run go test files | |||
Comment on lines
+12
to
+14
| var allowlistedMessages = []string{ //list of messages that are allowed to be in the logs | ||
| "AllocationSetRange has empty AssetSet in accumulation", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scans OpenCost container logs for panics, stack traces, and ERR-level entries. Skips when kubectl is unavailable and supports an allow-list for known benign messages on test clusters.
Fixes #87