Skip to content

Add OpenCost log inspector integration test.#104

Open
Aadarsh-Sankar wants to merge 3 commits into
opencost:mainfrom
Aadarsh-Sankar:issue-87-log-inspector
Open

Add OpenCost log inspector integration test.#104
Aadarsh-Sankar wants to merge 3 commits into
opencost:mainfrom
Aadarsh-Sankar:issue-87-log-inspector

Conversation

@Aadarsh-Sankar

Copy link
Copy Markdown

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

@Aadarsh-Sankar
Aadarsh-Sankar requested a review from a team as a code owner June 16, 2026 16:42
Copilot AI review requested due to automatic review settings June 16, 2026 16:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via kubectl and 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
}
Comment thread test/integration/observability/log_inspector_test.go
@@ -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
Aadarsh Sankar and others added 2 commits June 16, 2026 12:12
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
Aadarsh-Sankar force-pushed the issue-87-log-inspector branch from 1f3a086 to 9af2947 Compare June 16, 2026 17:12
Copilot AI review requested due to automatic review settings June 22, 2026 14:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

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",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add log inspector test

3 participants