redpanda-data / redpanda-data/connect

Setting a batching period policy blocks graceful termination

Open
#1,001 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

annoying feedback wanted outputs
Dominant language
Go
Stars
8.8k
Forks
969
Avg merge
1d 13h
Merged PRs (30d)
64

Description

It appears that configuring batch with a period policy blocks graceful termination of a Benthos process. Configuration and sample output shown below.

When I remove the period policy and only have batch_size, I am able to safely terminate the benthos process and observe the pending batch is flushed correctly.


Config

metrics:
  prometheus:
    prefix: benthos
    path_mapping: ""

input:
  file:
    paths: [${DATA_PATH}/input/pypi/*.jsonl]
    codec: lines
  processors:
    - label: json_to_csv
      bloblang: |
        map escape_csv {
          root = if this.re_match("[\"\n,]+") {
            "\"" + this.replace("\"", "\"\"") + "\""
          } else {
            this
          }
        }

        meta = deleted()

        root = [
          (this.timestamp | "").string().apply("escape_csv"),
          (this.project | "").string().apply("escape_csv"),
          (this.url | "").string().apply("escape_csv"),
          (this.details.installer.name | "").string().apply("escape_csv"),
          (this.details.installer.version | "").string().apply("escape_csv"),
          (this.details.implementation.name | "").string().apply("escape_csv"),
          (this.details.implementation.version | "").string().apply("escape_csv"),
          (this.details.system.name | "").string().apply("escape_csv"),
          (this.details.system.release | "").string().apply("escape_csv")
        ].join(",")
output:
  broker:
    outputs:
      - drop: {}
        processors:
          - log:
              message: "dropping a batch"
    batching:
      period: 1m
      byte_size: 20_000_000
      processors:
        - insert_part:
            index: 0
            content: "timestamp,project,url,installer_name,installer_version,implementation_name,implementation_version,system_name,system_release"
        - archive:
            format: lines
        - bloblang: |
            meta batch_hash = content().hash("xxhash64").encode("hex")

Actual output

{"@timestamp":"2021-12-09T16:50:58Z","@service":"benthos","component":"benthos.input","level":"INFO","message":"Consuming from file '/data/input/pypi/pypi_results_000000000000.jsonl'"}
{"@timestamp":"2021-12-09T16:50:58Z","@service":"benthos","component":"benthos.output","level":"INFO","message":"Dropping messages."}
{"@timestamp":"2021-12-09T16:50:58Z","@service":"benthos","component":"benthos","level":"INFO","message":"Launching a benthos instance, use CTRL+C to close."}
{"@timestamp":"2021-12-09T16:50:58Z","@service":"benthos","component":"benthos","level":"INFO","message":"Listening for HTTP requests at: http://0.0.0.0:4195"}
{"@timestamp":"2021-12-09T16:51:03Z","@service":"benthos","component":"benthos.output.processor.0","level":"INFO","message":"dropping a batch"}
^C{"@timestamp":"2021-12-09T16:51:05Z","@service":"benthos","component":"benthos","level":"INFO","message":"Received SIGTERM, the service is closing."}
{"@timestamp":"2021-12-09T16:51:20Z","@service":"benthos","component":"benthos","level":"INFO","message":"Unable to fully drain buffered messages within target time."}
{"@timestamp":"2021-12-09T16:51:25Z","@service":"benthos","component":"benthos","level":"ERROR","message":"Failed to stop stream gracefully within target time."}

Expected output

(observed when I remove the period policy)

{"@timestamp":"2021-12-09T16:54:50Z","@service":"benthos","component":"benthos.input","level":"INFO","message":"Consuming from file '/data/input/pypi/pypi_results_000000000000.jsonl'"}
{"@timestamp":"2021-12-09T16:54:50Z","@service":"benthos","component":"benthos.output","level":"INFO","message":"Dropping messages."}
{"@timestamp":"2021-12-09T16:54:50Z","@service":"benthos","component":"benthos","level":"INFO","message":"Launching a benthos instance, use CTRL+C to close."}
{"@timestamp":"2021-12-09T16:54:50Z","@service":"benthos","component":"benthos","level":"INFO","message":"Listening for HTTP requests at: http://0.0.0.0:4195"}
{"@timestamp":"2021-12-09T16:54:55Z","@service":"benthos","component":"benthos.output.processor.0","level":"INFO","message":"dropping a batch"}
^C{"@timestamp":"2021-12-09T16:54:56Z","@service":"benthos","component":"benthos","level":"INFO","message":"Received SIGTERM, the service is closing."}
{"@timestamp":"2021-12-09T16:54:56Z","@service":"benthos","component":"benthos.output.processor.0","level":"INFO","message":"dropping a batch"}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided Benthos configuration, comparing shutdown behavior with and without the batching period policy. Trace the batching and graceful-termination paths, then verify that SIGTERM flushes the pending batch and exits within the target time when the period is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, stream-processing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.