Skip to content

feat(function): expose producer configuration on pulsar_function - #223

Merged
freeznet merged 2 commits into
streamnative:masterfrom
david-streamlio:feat/function-producer-config
Aug 26, 2026
Merged

feat(function): expose producer configuration on pulsar_function#223
freeznet merged 2 commits into
streamnative:masterfrom
david-streamlio:feat/function-producer-config

Conversation

@david-streamlio

Copy link
Copy Markdown
Contributor

Master Issue: #220

Covers the part of #220 that has no upstream dependency. The batching_config block is deliberately out of scope — see below.

Motivation

pulsar_source exposes its producer configuration as top-level attributes (resource_pulsar_source.go): max_pending_messages, max_pending_messages_across_partitions, use_thread_local_producers, batch_builder, compression_type.

pulsar_function exposes none of it. utils.FunctionConfig carries the same ProducerConfig *ProducerConfig field, but marshalFunctionConfig never populated it, so it was always sent nil — a function's output producer could not be configured from Terraform at all, including its compression.

Modifications

  • Add the five attributes to pulsar_function, reusing pulsar_source's names and description strings verbatim so the two resources read the same way.
  • Populate FunctionConfig.ProducerConfig in marshalFunctionConfig via a new marshalFunctionProducerConfig, following the shape pulsar_source uses.
  • Read them back in unmarshalFunctionProducerConfig, surfacing each field only when the server returned something for it so a function that configures none of them does not gain a diff.
  • Regenerate docs/resources/function.md.

marshalFunctionProducerConfig returns nil when none of the attributes are set, so the request for a function that does not configure a producer is byte-identical to before.

Out of scope, deliberately: batching_config. Two independent reasons, either of which alone would block it:

  1. PIP-401's batchingConfig is absent from utils.ProducerConfig in the pinned admin client, so there is nothing to serialize into. Tracked as pulsaradmin: ProducerConfig cannot express PIP-401 batchingConfig apache/pulsar-client-go#1528, with a fix open at feat(pulsaradmin): add PIP-401 batchingConfig to ProducerConfig apache/pulsar-client-go#1530.
  2. It requires a broker running Pulsar 4.1.0 or laterBatchingConfig.java does not exist on the v4.0.x tags. The acceptance tests here run against 4.0.3 (hack/pulsarimage/Dockerfile), so it could not be acceptance-tested on the current baseline without bumping the image or scoping those tests around it. Worth deciding separately.

Worth knowing about runtime support. compression_type and batch_builder are honoured by the Python function runtime; max_pending_messages is not (the Python runtime reads only compressionType and batchBuilder from the ProducerSpec). The provider should still send all of them — the broker stores them and the Java runtime applies them — but a Python function author should not expect max_pending_messages to take effect today. The Go runtime has the same gap, tracked at apache/pulsar#26391.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • pulsar/testdata/function/main.tf sets all five attributes, and TestFunction asserts each one round-trips through a real broker.
  • Confirmed the assertions are not vacuous: disabling the functionConfig.ProducerConfig = ... assignment and re-running fails five assertions.
  • Acceptance tests pass against Pulsar 4.0.3; make test and golangci-lint are clean; go generate ./... reproduces the committed docs.

Documentation

Check the box below.

Need to update docs?

  • doc-required

  • no-need-doc

  • doc

    docs/resources/function.md regenerated with the five new attributes.

david-streamlio and others added 2 commits August 26, 2026 16:28
pulsar_source exposes its producer configuration as top-level attributes -
max_pending_messages, max_pending_messages_across_partitions,
use_thread_local_producers, batch_builder and compression_type.
pulsar_function exposes none of it: utils.FunctionConfig carries the same
ProducerConfig field, but marshalFunctionConfig never populated it, so it
was always sent nil and a function's output producer was stuck on
defaults.

Add the same five attributes, using the names pulsar_source already uses
so the two resources read the same way, and populate FunctionConfig's
ProducerConfig from them.

The producer config is omitted entirely when none of the attributes are
set, so requests for functions that do not configure a producer are
unchanged.

This is the part of streamnative#220 that needs nothing upstream. The batching_config
block is deliberately not included: PIP-401's batchingConfig is absent
from utils.ProducerConfig in the pinned admin client - tracked in
apache/pulsar-client-go#1528, with a fix open at
apache/pulsar-client-go#1530 - and it exists only on Pulsar 4.1.0 and
later, whereas the acceptance tests here run against 4.0.3.

Master Issue: streamnative#220

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@freeznet
freeznet force-pushed the feat/function-producer-config branch from 3059867 to 3447080 Compare August 26, 2026 08:53
@freeznet

Copy link
Copy Markdown
Member

Rebased this branch onto current master (including #219 and #226) and pushed the producer update/read-back fixes in 3447080.

Changes:

  • resolve the function schema, test, and fixture conflicts with feat(function): expose input_specs for per-topic consumer config #219;
  • write zero, false, and empty producer values back to Terraform state so removed or externally reset settings do not leave stale state;
  • send the Function default producer config when the final producer override is removed on update, instead of sending nil and letting Pulsar preserve the old config;
  • correct the documented Function compression default to LZ4;
  • extend TestFunction to verify the producer settings are cleared in place, plus add a focused zero-value state regression test.

Validation:

  • GOTOOLCHAIN=go1.25.14+auto GOWORK=off go test ./...
  • GOTOOLCHAIN=go1.25.14+auto GOWORK=off go vet ./...
  • go generate ./...
  • Pulsar 4.0.3: TF_ACC=1 ... go test ./pulsar -run '^TestFunction$' -count=1 -timeout=20m -v

batching_config intentionally remains outside this PR; it needs a separate, version-scoped change that can be verified across the supported broker and runtime paths.

@freeznet
freeznet merged commit ba514b0 into streamnative:master Aug 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc This pr contains a document

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants