Skip to content

Chipingress publish batch#1862

Open
thomaska wants to merge 4 commits intomainfrom
infoplat-3436-chipingress-publishBatch
Open

Chipingress publish batch#1862
thomaska wants to merge 4 commits intomainfrom
infoplat-3436-chipingress-publishBatch

Conversation

@thomaska
Copy link

@thomaska thomaska commented Feb 27, 2026

Ticket: https://smartcontract-it.atlassian.net/browse/INFOPLAT-3436

Summary

Replace the per-event ChipIngressEmitter with ChipIngressBatchEmitter to
batch events sent to ChIP Ingress via PublishBatch.

  • New ChipIngressBatchEmitter: buffers events per (domain, entity) pair
    and flushes them periodically via a single PublishBatch gRPC call. Reduces
    N gRPC calls + N Kafka transactions to 1 call + 1 transaction per flush.
  • New chipIngressEmitterWorker: per-(domain, entity) worker that drains
    its channel, builds a CloudEventBatch, and sends it with a configurable
    timeout. Drops events with exponential backoff logging when the buffer is full.
  • Simplified DualSourceEmitter: removed the goroutine wrapper around chip
    ingress emit since ChipIngressBatchEmitter.Emit is non-blocking (channel send).
  • Config: 4 new tuning knobs with sane defaults:
    • ChipIngressBufferSize (default 100)
    • ChipIngressMaxBatchSize (default 50)
    • ChipIngressSendInterval (default 500ms)
    • ChipIngressSendTimeout (default 10s)
  • Tests: 10 tests covering batch assembly, max batch size, per-domain
    isolation, buffer-full drops, lifecycle, CloudEvent format, PublishBatch
    errors, context cancellation, and default config fallbacks.

Why

The old ChipIngressEmitter called Publish per event, meaning each workflow
event triggered a separate gRPC call and Kafka transaction. Under load (e.g.
many concurrent workflow executions), this creates unnecessary overhead.
ChIP Ingress supports transactional PublishBatch -- batching amortizes the
cost and aligns with how the service is designed to be used.

Supports

smartcontractkit/chainlink#21327

Copilot AI review requested due to automatic review settings February 27, 2026 14:43
@thomaska thomaska requested a review from a team as a code owner February 27, 2026 14:43
@github-actions
Copy link

👋 thomaska, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request replaces the per-event ChIP Ingress emission with a batched approach to reduce overhead from N gRPC calls + N Kafka transactions to 1 call + 1 transaction per flush interval. The implementation introduces a new ChipIngressBatchEmitter that buffers events per (domain, entity) pair and flushes them periodically using PublishBatch.

Changes:

  • Introduced ChipIngressBatchEmitter with per-(domain, entity) worker goroutines for batching events
  • Added chipIngressEmitterWorker to handle batch assembly and sending with configurable timeouts
  • Removed goroutine wrapper from DualSourceEmitter.Emit() since batching is now non-blocking (channel send)
  • Added 4 new configuration parameters with sensible defaults (BufferSize: 100, MaxBatchSize: 50, SendInterval: 500ms, SendTimeout: 10s)

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/beholder/chip_ingress_batch_emitter.go New batch emitter with per-worker buffering and periodic flushing via PublishBatch
pkg/beholder/chip_ingress_emitter_worker.go Worker implementation handling batch assembly, channel draining, and exponential backoff logging for drops
pkg/beholder/chip_ingress_batch_emitter_test.go Comprehensive test coverage (10 tests) for batching, max batch size, isolation, buffer overflow, lifecycle, errors, and defaults
pkg/beholder/dual_source_emitter.go Simplified Emit() by removing goroutine wrapper since ChipIngressBatchEmitter.Emit() is non-blocking
pkg/beholder/client.go Updated to create and start ChipIngressBatchEmitter instead of ChipIngressEmitter; added comment about closure ordering
pkg/beholder/config.go Added 4 new config fields with inline documentation and default values
pkg/beholder/config_test.go Updated expected output to include new config fields
Comments suppressed due to low confidence (2)

pkg/beholder/config.go:50

  • The comment states "Zero disables batching" but the implementation in NewChipIngressBatchEmitter treats zero as "use default" and sets it to 500ms. The comment should be corrected to match the actual behavior, e.g., "Flush interval per worker (default 500ms when zero or unset)".
	ChipIngressSendInterval time.Duration // Flush interval per worker (default 500ms). Zero disables batching.

pkg/beholder/client.go:248

  • The messageLoggerProvider appears twice in the shutdowner slice. This will cause it to be shut down twice, which could lead to errors or undefined behavior. Remove one of the duplicate entries.
		for _, provider := range []shutdowner{messageLoggerProvider, loggerProvider, tracerProvider, meterProvider, messageLoggerProvider} {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

✅ API Diff Results - github.com/smartcontractkit/chainlink-common

✅ Compatible Changes (10)

pkg/beholder (2)
  • ChipIngressBatchEmitter — ➕ Added

  • NewChipIngressBatchEmitter — ➕ Added

pkg/beholder.Config (4)
  • ChipIngressBufferSize — ➕ Added

  • ChipIngressMaxBatchSize — ➕ Added

  • ChipIngressSendInterval — ➕ Added

  • ChipIngressSendTimeout — ➕ Added

pkg/beholder.writerClientConfig (4)
  • ChipIngressBufferSize — ➕ Added

  • ChipIngressMaxBatchSize — ➕ Added

  • ChipIngressSendInterval — ➕ Added

  • ChipIngressSendTimeout — ➕ Added


📄 View full apidiff report

@smartcontractkit smartcontractkit deleted a comment from github-actions bot Feb 27, 2026
return nil, err
}

chipIngressEmitter, err := NewChipIngressEmitter(chipIngressClient)
Copy link
Author

Choose a reason for hiding this comment

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

add a feature flag

// via chipingress.Client.PublishBatch on a periodic interval.
// It satisfies the Emitter interface so it can be used as a drop-in replacement
// for ChipIngressEmitter.
type ChipIngressBatchEmitter struct {
Copy link
Author

Choose a reason for hiding this comment

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

name it Service

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.

2 participants