Skip to content

fix(consolidation): emit consolidated slug only when aggregated profiles change#341

Open
shanyl9 wants to merge 1 commit into
mainfrom
fix/consolidation-emit-slug-only-on-change
Open

fix(consolidation): emit consolidated slug only when aggregated profiles change#341
shanyl9 wants to merge 1 commit into
mainfrom
fix/consolidation-emit-slug-only-on-change

Conversation

@shanyl9

@shanyl9 shanyl9 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

ContainerProfileProcessor.consolidateKeyTimeSeries emitted a consolidated slug on every consolidation run for every k8s workload — even when the run produced no new data. Each slug drives a downstream AP/NN onFinish message (event-ingester-service) and ultimately a container_statuses upsert.

For idle / already-consolidated workloads this re-emits the same onFinish on every 30s tick. In prod (prod-ap-southeast-2) this flooded the synchronizer-finished-v1 topic and fed a container_statuses deadlock storm downstream: ~97% of one customer's container_statuses rows were rewritten hourly despite averaging ~26 days old.

The aggregated AP/NN are only rewritten when there is new data (updateAggregatedProfiles is already gated on newData), so emitting on a no-new-data run is pure churn.

Change

  • updateProfile and processTimeSeriesInTransaction now return aggregatedUpdated bool, mirroring the existing newData gate on updateAggregatedProfiles.
  • consolidateKeyTimeSeries emits the slug only when HostType == Kubernetes && aggregatedUpdated.
  • Idle / already-consolidated workloads (a has_data=false series with no new entries) now emit nothing instead of re-emitting every tick.

Tests

  • New TestConsolidateKeyTimeSeries_NoEmitWhenNoNewData (written test-first: fails on the old code, which emitted with zero new data; passes after the gate).
  • Full pkg/registry/file suite passes, including the sqlite-backed TestConsolidateData.

Docs

  • Adds docs/features/container-profile-consolidation-emit.md describing the gating.

Notes

This is the source-side half of a broader fix. Downstream, the container_statuses upsert is separately hardened with deadlock retry + deterministic lock ordering in postgres-connector.

🤖 Generated with Claude Code

…les change

consolidateKeyTimeSeries emitted a consolidated slug (which drives a downstream
AP/NN onFinish and ultimately a container_statuses upsert) on every run for every
k8s workload, even when the run produced no new data. For idle/already-consolidated
workloads this re-emits the same onFinish every tick, flooding
synchronizer-finished-v1 and feeding the container_statuses deadlock storm
downstream (the AP/NN aren't rewritten on a no-new-data run, so the emission is
pure churn).

Thread the newData signal out of updateProfile/processTimeSeriesInTransaction as
aggregatedUpdated and gate sendConsolidatedSlugToChannel on it, so a slug is
emitted only when the aggregated AP/NN were actually rewritten this run. This
matches the existing newData gate on updateAggregatedProfiles.

Adds a unit test asserting no emission on a no-new-data consolidation, and a
feature doc describing the gating.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shanyl9 shanyl9 added the ai-assisted Created through Armosec AI tooling (armosec-shared-rules plugin) label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 58d0b463-eb05-48f2-bc0a-75015fb7a4aa

📥 Commits

Reviewing files that changed from the base of the PR and between 1f9c8e3 and dc43491.

📒 Files selected for processing (3)
  • docs/features/container-profile-consolidation-emit.md
  • pkg/registry/file/containerprofile_emit_gate_test.go
  • pkg/registry/file/containerprofile_processor.go
 _________________________________________________________________________________________________________
< A good programmer is someone who always looks both ways before crossing a one-way street. - Doug Linder >
 ---------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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/consolidation-emit-slug-only-on-change

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.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Summary:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Created through Armosec AI tooling (armosec-shared-rules plugin)

Projects

Status: WIP

Development

Successfully merging this pull request may close these issues.

2 participants