Skip to content

test(buffer): verify deeply nested JSON events do not corrupt disk buffer (LOG-9386) - #3377

Open
vparfonov wants to merge 1 commit into
openshift:masterfrom
vparfonov:log9386
Open

test(buffer): verify deeply nested JSON events do not corrupt disk buffer (LOG-9386)#3377
vparfonov wants to merge 1 commit into
openshift:masterfrom
vparfonov:log9386

Conversation

@vparfonov

@vparfonov vparfonov commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description

Verify that deeply nested JSON events (>32 protobuf nesting levels) don't crash Vector when disk buffering if enabled (AtLeastOnce delivery mode) and JSON parse filter.

/cc @Clee2691
/assign @jcantrill

Links

Summary by CodeRabbit

  • Tests
    • Added functional coverage for deeply nested JSON events when using HTTP delivery with JSON parsing and disk buffering.
    • Verified overly nested events are safely dropped without interrupting delivery of valid messages.
    • Confirmed collector behavior avoids protobuf decoding failures and reports nesting cost warnings.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9a7dd7d9-63e5-43b7-aa04-f4878ef5cde3

📥 Commits

Reviewing files that changed from the base of the PR and between 5222621 and 012b739.

📒 Files selected for processing (1)
  • test/functional/outputs/http/forward_to_http_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/functional/outputs/http/forward_to_http_test.go

📝 Walkthrough

Walkthrough

Adds functional coverage for deeply nested JSON with AtLeastOnce HTTP output buffering, verifying shallow messages remain deliverable and collector logs record expected handling without protobuf or crash failures.

Changes

Nested JSON HTTP output test

Layer / File(s) Summary
Nested JSON buffering and delivery validation
test/functional/outputs/http/forward_to_http_test.go
Adds a test that sends 40-level nested JSON and a shallow message with JSON parsing and AtLeastOnce delivery enabled, then verifies shallow delivery and expected collector log messages.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: clee2691, cahartma

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: a regression test for deeply nested JSON with disk buffering.
Description check ✅ Passed The description matches the template well, includes the required intent, reviewer/approver mentions, and relevant links.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@qodo-for-rh-openshift

Copy link
Copy Markdown

PR Summary by Qodo

Test deeply nested JSON handling with disk-buffered HTTP output

🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Add regression coverage for JSON exceeding protobuf's 32-level nesting limit.
• Exercise JSON parsing with at-least-once, disk-buffered HTTP delivery.
• Confirm invalid events drop safely while shallow events continue downstream.
Diagram

graph TD
  A["Application logs"] --> B["JSON parser"] --> C{"Nesting valid?"}
  C -->|Yes| D["Disk buffer"] --> E["HTTP output"]
  C -->|No| F["Drop warning"]
Loading
High-Level Assessment

The functional regression test is the appropriate approach because the failure depends on the complete JSON parsing, protobuf disk-buffering, and HTTP delivery pipeline. A unit test or static fixture would provide less confidence than dynamically generating an event beyond the known nesting limit and verifying both graceful dropping and continued delivery.

Files changed (1) +52 / -0

Tests (1) +52 / -0
forward_to_http_test.goCover over-nested JSON events in the disk-buffered HTTP pipeline +52/-0

Cover over-nested JSON events in the disk-buffered HTTP pipeline

• Adds a functional regression test that generates a 40-level JSON event and forwards it through JSON parsing with at-least-once HTTP delivery. The test verifies the invalid event is reported as dropped without protobuf decode failures or a Vector crash, while a shallow event remains deliverable.

test/functional/outputs/http/forward_to_http_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/functional/outputs/http/forward_to_http_test.go`:
- Around line 215-224: Update the deep-event assertions near
framework.ReadCollectorLogs to verify the collector container restart count is
zero after sending the event, rather than relying only on current-instance log
substrings. If the restart count is nonzero, inspect the terminated container’s
previous logs so crashes are detected and diagnosed; retain the existing
dropped-event and nesting-warning checks.
- Around line 211-213: Strengthen the assertions in the HTTP output test after
ReadRawApplicationLogsFrom by verifying the delivered raw output contains or
parses the expected “shallow” payload. Keep the existing error and non-empty
checks, but ensure the test distinguishes the shallow event from an over-nested
event.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c0e64908-87be-4cad-b67d-a467f3cf348f

📥 Commits

Reviewing files that changed from the base of the PR and between d3b6f7a and 5222621.

📒 Files selected for processing (1)
  • test/functional/outputs/http/forward_to_http_test.go

Comment on lines +211 to +213
raw, err := framework.ReadRawApplicationLogsFrom(string(obs.OutputTypeHTTP))
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(raw).ToNot(BeEmpty(), "Expected the shallow message to be delivered")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that the delivered record is the shallow event.

A non-empty HTTP response can be the over-nested event. Verify the output contains/parses the "shallow" payload so this test actually covers continued delivery.

Proposed assertion
 			Expect(err).To(BeNil(), "Expected no errors reading the logs")
 			Expect(raw).ToNot(BeEmpty(), "Expected the shallow message to be delivered")
+			Expect(strings.Join(raw, "\n")).To(ContainSubstring("shallow"))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
raw, err := framework.ReadRawApplicationLogsFrom(string(obs.OutputTypeHTTP))
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(raw).ToNot(BeEmpty(), "Expected the shallow message to be delivered")
raw, err := framework.ReadRawApplicationLogsFrom(string(obs.OutputTypeHTTP))
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(raw).ToNot(BeEmpty(), "Expected the shallow message to be delivered")
Expect(strings.Join(raw, "\n")).To(ContainSubstring("shallow"))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/functional/outputs/http/forward_to_http_test.go` around lines 211 - 213,
Strengthen the assertions in the HTTP output test after
ReadRawApplicationLogsFrom by verifying the delivered raw output contains or
parses the expected “shallow” payload. Keep the existing error and non-empty
checks, but ensure the test distinguishes the shallow event from an over-nested
event.

Comment on lines +215 to +224
collectorLogs, err := framework.ReadCollectorLogs()
Expect(err).To(BeNil())
Expect(collectorLogs).ToNot(ContainSubstring("InvalidProtobufPayload"),
"Vector should not crash with InvalidProtobufPayload on deeply nested events")
Expect(collectorLogs).ToNot(ContainSubstring("failed to decoded record"),
"Vector should not fail to decode buffered records")
Expect(collectorLogs).To(ContainSubstring("Events dropped"),
"Expected over-nested event to be reported as dropped")
Expect(collectorLogs).To(ContainSubstring("Event nesting cost exceeds maximum"),
"Expected nesting cost warning for the over-nested event")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Detect collector restarts, not just current log text.

ReadCollectorLogs() runs oc logs for the current container instance. Vector can crash and restart, then deliver the shallow message, without these substring checks seeing the terminated instance’s logs. Assert the collector container restart count remains zero (and inspect previous logs when nonzero) after sending the deep event.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/functional/outputs/http/forward_to_http_test.go` around lines 215 - 224,
Update the deep-event assertions near framework.ReadCollectorLogs to verify the
collector container restart count is zero after sending the event, rather than
relying only on current-instance log substrings. If the restart count is
nonzero, inspect the terminated container’s previous logs so crashes are
detected and diagnosed; retain the existing dropped-event and nesting-warning
checks.

@qodo-for-rh-openshift

qodo-for-rh-openshift Bot commented Jul 28, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
⚠️ Tickets: not configured — ticket URL found in PR but could not be fetched — check ticket provider credentials
✅ Compliance rules (platform): 9 rules

Grey Divider


Remediation recommended

1. Framework reassignment leaks namespace ✓ Resolved 🐞 Bug ☼ Reliability
Description
The test overwrites the framework created by the outer BeforeEach, while AfterEach cleans only
the replacement. The first framework's namespace is therefore left behind on every execution.
Code

test/functional/outputs/http/forward_to_http_test.go[181]

+			framework = functional.NewCollectorFunctionalFramework()
Relevance

⭐⭐⭐ High

Deterministic namespace leak from overwriting the cleanup target; recent same-file framework
reassignment makes it directly relevant.

PR-#3337

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The outer setup creates the first framework, and NewTest creates its namespace immediately. Line
181 replaces that framework, while the sole cleanup hook invokes Cleanup only through the
replacement pointer.

test/functional/outputs/http/forward_to_http_test.go[28-45]
test/functional/outputs/http/forward_to_http_test.go[179-191]
test/client/test.go[35-49]
test/framework/functional/framework.go[132-163]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The test replaces the framework initialized by the outer setup, making its namespace unreachable by the existing cleanup hook.

## Issue Context
Creating a functional framework creates a test namespace. `AfterEach` calls `Cleanup` only on the framework currently stored in the variable, so reassignment leaks the original namespace and resources.

## Fix Focus Areas
- test/functional/outputs/http/forward_to_http_test.go[28-45]
- test/functional/outputs/http/forward_to_http_test.go[179-191]
- test/framework/functional/framework.go[87-123]
- test/framework/functional/framework.go[132-163]
- test/client/test.go[35-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Collector restart goes undetected 🐞 Bug ☼ Reliability
Description
The test checks only the current collector instance's logs, so a crash followed by a container
restart can lose the failure logs and still pass after the shallow event is delivered. This does not
reliably verify the test's core no-crash requirement.
Code

test/functional/outputs/http/forward_to_http_test.go[215]

+			collectorLogs, err := framework.ReadCollectorLogs()
Relevance

⭐⭐ Medium

Valid no-crash coverage concern, but restart-aware verification materially expands test behavior
without close review precedent.

PR-#3072

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The functional pod is built without an explicit restart policy, and ReadCollectorLogs executes
plain oc logs without requesting previous-instance logs. The new test neither refreshes the pod
status nor checks the collector container's restart count.

test/functional/outputs/http/forward_to_http_test.go[211-224]
test/framework/functional/read.go[208-210]
test/framework/functional/framework.go[290-303]
internal/runtime/core.go[27-31]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The regression test can pass after the collector container crashes and restarts because it reads only the current container instance's logs and never checks restart history.

## Issue Context
`ReadCollectorLogs` invokes ordinary `oc logs`, which excludes a previous container instance. The functional pod also does not set a non-restarting policy, so the test must explicitly verify that the collector's restart count remains unchanged.

## Fix Focus Areas
- test/functional/outputs/http/forward_to_http_test.go[211-224]
- test/framework/functional/read.go[208-210]
- test/framework/functional/framework.go[290-303]
- internal/runtime/core.go[27-31]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(raw).ToNot(BeEmpty(), "Expected the shallow message to be delivered")

collectorLogs, err := framework.ReadCollectorLogs()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Collector restart goes undetected 🐞 Bug ☼ Reliability

The test checks only the current collector instance's logs, so a crash followed by a container
restart can lose the failure logs and still pass after the shallow event is delivered. This does not
reliably verify the test's core no-crash requirement.
Agent Prompt
## Issue description
The regression test can pass after the collector container crashes and restarts because it reads only the current container instance's logs and never checks restart history.

## Issue Context
`ReadCollectorLogs` invokes ordinary `oc logs`, which excludes a previous container instance. The functional pod also does not set a non-restarting policy, so the test must explicitly verify that the collector's restart count remains unchanged.

## Fix Focus Areas
- test/functional/outputs/http/forward_to_http_test.go[211-224]
- test/framework/functional/read.go[208-210]
- test/framework/functional/framework.go[290-303]
- internal/runtime/core.go[27-31]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread test/functional/outputs/http/forward_to_http_test.go Outdated
@openshift-ci
openshift-ci Bot requested review from Clee2691 and cahartma July 28, 2026 16:26
@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vparfonov
Once this PR has been reviewed and has the lgtm label, please assign jcantrill for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

…ffer (LOG-9386)

Signed-off-by: Vitalii Parfonov <vparfono@redhat.com>
@openshift-ci

openshift-ci Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@vparfonov: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/functional-target 012b739 link true /test functional-target
ci/prow/e2e-using-bundle 012b739 link false /test e2e-using-bundle

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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.

1 participant