Skip to content

fix(backend): repair NewProducerMessage signature + self-loop tagging (unblocks component-tests) - #165

Merged
matthyx merged 2 commits into
mainfrom
fix/restore-producer-message-key
Jul 16, 2026
Merged

fix(backend): repair NewProducerMessage signature + self-loop tagging (unblocks component-tests)#165
matthyx merged 2 commits into
mainfrom
fix/restore-producer-message-key

Conversation

@matthyx

@matthyx matthyx commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Overview

The component-tests matrix had been failing on every PR (including #163). There were two distinct regressions, both introduced by the MQ-extraction refactor (3d79f17), which this PR fixes. All 17 component-tests now pass.

1. Compile break (build failed)

3d79f17 changed the signature of the exported helper adapters/backend/v1.NewProducerMessage, dropping the leading producerMessageKey argument. That helper is consumed outside this repo by github.com/armosec/event-ingester-service (synchronizer_producer), which the integration tests module builds against local synchronizer via replace. The argument mismatch made the whole tests module fail to compile, so every component-test died at the Run test step before executing:

event-ingester-service/synchronizer_producer/producer.go:210:
  cannot use eventType (string) as []byte value in argument to backend.NewProducerMessage
FAIL github.com/kubescape/synchronizer/tests [build failed]

Fix: restore the producerMessageKey parameter; synchronizer's own two callers pass messaging.SynchronizerServerProducerKey.

2. Self-loop filter dropped external producers' messages (runtime failure)

Once compilation was restored, the tests ran but backend->cluster cases still failed (e.g. TC01: configmaps "test" not found). The refactor also added a self-loop guard — the reader skips messages where messaging.IsSelfProducedMessage is true — and BuildProducerProperties unconditionally stamps x-producer-source: synchronizer-server on every message it builds. Since NewProducerMessage is also used by external producers (event-ingester), their messages were tagged as self-produced and silently dropped by the server, so objects never landed in the cluster.

Fix: only stamp the self-produced source header when the caller is the synchronizer server itself (identified by SynchronizerServerProducerKey); strip it for any other producer key. Added a unit test covering both directions.

Verification

  • go build ./..., go test ./adapters/backend/v1/, go test ./messaging/ — all pass locally.
  • New unit test TestNewProducerMessage_SelfLoopTagging asserts external-producer messages are not tagged self-produced and are not filtered.
  • CI: all 17 component-tests pass on this branch (previously all failing).

Once merged to main, other open PRs (e.g. #163) will pass component-tests after a rebase.

Generated with Claude Code

The "extract shared MQ handler" refactor dropped the producerMessageKey
argument from the exported adapters/backend/v1.NewProducerMessage and
hardcoded the synchronizer server key. That silently broke external
consumers of this exported helper -- notably
armosec/event-ingester-service, whose synchronizer_producer passes its
own "eventIngesterProducer" key -- so the integration `tests` module
(which compiles that consumer against local synchronizer via a replace
directive) failed to build, and every component-test in CI errored
before running.

Restore the producerMessageKey parameter and pass
messaging.SynchronizerServerProducerKey from the synchronizer's own two
callers. Behavior is unchanged; the public signature external producers
depend on is preserved.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx matthyx added the ai-assisted PR created with AI assistance label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

NewProducerMessage now accepts an explicit Pulsar message key and assigns it to the produced message. ProduceMessage passes messaging.SynchronizerServerProducerKey when constructing messages.

Changes

Pulsar message key handling

Layer / File(s) Summary
Explicit key propagation
adapters/backend/v1/pulsar.go
NewProducerMessage accepts and assigns the provided producer key, while ProduceMessage supplies the synchronizer server producer key.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the signature fix and caller key-tagging change, and it matches the PR’s main purpose.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/restore-producer-message-key

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: failure
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: failure

The MQ refactor added a self-loop guard: the reader skips messages where
IsSelfProducedMessage is true, and BuildProducerProperties unconditionally
stamps the x-producer-source=synchronizer-server header on every message it
builds. Because NewProducerMessage is also used by external producers
(event-ingester-service via adapters/backend/v1), their backend->cluster
messages were tagged as self-produced and silently dropped by the server --
so objects never landed in the cluster and every backend-direction
component-test failed at runtime (e.g. TC01: configmaps "test" not found).

Only stamp the self-produced source when the caller is the synchronizer
server itself (identified by SynchronizerServerProducerKey); strip it for
any other producer key. Add a unit test covering both directions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@github-actions

Copy link
Copy Markdown

Summary:

  • License scan: success
  • Credentials scan: failure
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: failure

@matthyx matthyx changed the title fix(backend): restore producer-message key param to NewProducerMessage (unblocks component-tests CI) fix(backend): repair NewProducerMessage signature + self-loop tagging (unblocks component-tests) Jul 16, 2026
@matthyx
matthyx merged commit 5edc675 into main Jul 16, 2026
24 checks passed
@matthyx
matthyx deleted the fix/restore-producer-message-key branch July 16, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted PR created with AI assistance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant