Skip to content

chore: dedupe TeeSink typed writes and tidy logging/redaction helpers#188

Merged
OmarAlJarrah merged 2 commits into
mainfrom
chore/178-io-instrumentation-simplifications
Jun 28, 2026
Merged

chore: dedupe TeeSink typed writes and tidy logging/redaction helpers#188
OmarAlJarrah merged 2 commits into
mainfrom
chore/178-io-instrumentation-simplifications

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Trims a handful of small, self-contained duplications in the io and instrumentation packages of sdk-core. Every change is behavior-preserving and touches only internal or private members, so there is no public-API change and no apiDump.

Changes

TeeSink

  • tapAllowance now uses the standard minOf clamp instead of a hand-rolled if/else min — identical result, clearer intent. The remaining-budget coerceAtLeast(0L) is preserved.
  • The five typed-write overrides (write(ByteArray), write(ByteArray, off, len), writeUtf8, writeUtf8(range), writeString) shared the same stage → drain → return this triple. They now route through a single private inline fun staged(...). The helper takes the staging buffer as an explicit lambda argument (it) rather than a Buffer receiver, so an unqualified write(...) can never resolve back to the TeeSink's own overrides and self-recurse. writeAll's per-chunk pump loop and write(Buffer, Long) are left untouched.

ClientLogger

  • Removed the pass-through toSlf4j and inlined its LogLevel → Level mapping into slf4jLevel, whose only other caller is LoggingEvent. canLog now calls slf4jLevel directly. One redundant forwarding hop removed; canLog's public signature is unchanged.

UrlRedactor

  • appendRedactedPair collapses its three-local conditional block (encodedName / hasValue / encodedValue) into a single early return for the bare-name (eq < 0) case. The value substring and the allow-list decode are now computed only when a value is actually present; the bare-name path emits the name verbatim and returns. Redacted output is byte-for-byte identical.

Verification

  • :sdk-core:compileKotlin and ktlint pass.
  • Tests for TeeSink, ClientLogger, UrlRedactor, and LoggableRequestBody pass.

Closes #178

Trim a few self-contained duplications in the io and instrumentation
packages. All changes are behavior-preserving and touch only internal
or private members.

- TeeSink: replace the hand-rolled if/else min in tapAllowance with the
  standard minOf clamp, and fold the five typed-write overrides
  (write/writeUtf8/writeString) onto a single private inline `staged`
  helper that stages into the scratch buffer, tees, and drains. The
  helper takes the staging buffer as an explicit lambda argument rather
  than a Buffer receiver, so an unqualified write can never resolve back
  to the TeeSink itself and self-recurse.
- ClientLogger: drop the pass-through toSlf4j and inline its level
  mapping into slf4jLevel; point canLog at slf4jLevel directly. Removes
  one redundant forwarding hop; canLog's signature is unchanged.
- UrlRedactor: collapse appendRedactedPair's three-local conditional
  block to a single eq < 0 early return for the bare-name case, so the
  value substring and allow-list decode are computed only when a value
  is actually present. Output is byte-for-byte identical.

Closes #178
@OmarAlJarrah OmarAlJarrah merged commit b4239df into main Jun 28, 2026
1 check passed
@OmarAlJarrah OmarAlJarrah deleted the chore/178-io-instrumentation-simplifications branch June 28, 2026 00:30
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.

io + instrumentation: simplify TeeSink staging and logging/redaction helpers

1 participant