Status

Current state: Under Discussion

Discussion thread: here

JIRA: KAFKA-20297

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

The Time interface and Timer class in org.apache.kafka.common.utils are currently exposed through public APIs but not officially designated as public. Following KIP-1247 (Make Bytes public), these should be made officially public.

// multiple KafkaStreams constructors (test-only usage)
public KafkaStreams(Topology topology, Properties props, Time time)

// couple of examples from multiple "org.apache.kafka.common.metrics.Metrics.java" constructors
public Metrics(Time time) {}
public Metrics(MetricConfig defaultConfig, Time time) {}

// in package "org.apache.kafka.common.security.oauthbearer"
public JwtBearerJwtRetriever(Time time) {}
public ClientCredentialsJwtRetriever(Time time) {}


However, KafkaStreams exposes constructors accepting Time parameters that are only useful for testing, not production use. As noted in the KIP-1247 discussion, these test-only constructors should be deprecated before making Time the official public API.

Timer is returned by Time interface methods and users might interact with Timer's public methods. If Time becomes officially public, Timer must also be public as it is part of Time's contract.

Public Interfaces

New public APIs (4.4):

  • org.apache.kafka.common.utils.Time (officially public)
  • org.apache.kafka.common.utils.Timer (officially public)
  • org.apache.kafka.streams.test.KafkaStreamsMock (test utility)

Deprecated (4.4, removed in 5.0):

  • KafkaStreams(Topology, Properties, Time) constructor
  • KafkaStreams(Topology, Properties, KafkaClientSupplier, Time) constructor

These are only used for testing and pollute the public API.

Proposed Changes

Make Time and Timer officially public (4.4):

Include Time and Timer in public API Javadocs with enhanced documentation.

Deprecate KafkaStreams test constructors (4.4):

Deprecate the following constructors (removal in 5.0):

  • KafkaStreams(Topology, Properties, Time)
  • KafkaStreams(Topology, Properties, KafkaClientSupplier, Time)

Provide Test Utility (4.4):

Create org.apache.kafka.streams.test.KafkaStreamsMock with static factory methods for creating KafkaStreams instances with custom Time implementations.

Example:

MockTime mockTime = new MockTime();
KafkaStreams streams = KafkaStreamsMock.create(topology, props, mockTime);

Compatibility, Deprecation, and Migration Plan

  • Version 4.4: Time and Timer become officially public. KafkaStreams Time constructors will be deprecated but functional.
  • Versions 4.4-4.9: Deprecation period for test migration.
  • Version 5.0: Deprecated constructors removed (become package-private, accessible via KafkaStreamsMock).

Test migration:

// Before
KafkaStreams streams = new KafkaStreams(topology, props, mockTime);

// After
KafkaStreams streams = KafkaStreamsMock.create(topology, props, mockTime);

No changes required for production code.

Test Plan

This KIP primarily involves API designation and deprecation rather than functional changes. Testing will focus on:

  • Javadoc generation: Verify Time and Timer appear correctly in public API documentation
  • KafkaStreamsMock Utility: Unit tests confirming the utility creates functional KafkaStreams instances with custom Time implementations
  • Backward Compatibility: Existing tests using deprecated constructors continue to pass unchanged
  • Deprecation Warnings: Build verification that deprecated constructors produce appropriate warnings

No new system tests required. Time and Timer functionality remains unchanged, only their API designation and test access patterns are updated.

Rejected Alternatives

Keep test constructors public: Continues to pollute the public API with test-only functionality.

  • No labels