Open-Source Wikis

/

MinIO

/

Packages

/

pubsub and utilities

minio/minio

pubsub and utilities

A grab bag of small internal/ packages: pub/sub for live tracing, time helpers, terminal colour, ARN parsing, init hooks, and utility data structures.

internal/pubsub

In-process publish/subscribe. Used by:

  • cmd/http-tracer.go — every traced event publishes here; the admin trace endpoint subscribes.
  • Bandwidth and metrics — short-lived subscribers that aggregate over a window.

The implementation is lock-free for the common case (single-publisher, many-subscriber). When a subscriber is too slow, events are dropped instead of buffered indefinitely.

internal/cachevalue

Cached[T] — a value with a Get() that takes a TTL and a refresh function. Used heavily by metrics collectors (cmd/metrics-v2.go, the v3 collectors) so a single scrape doesn't trigger N+1 RPCs.

internal/once

Wrappers around sync.Once:

  • Init — one-shot init.
  • Singleton[T] — once-init that returns a typed value.

internal/ringbuffer

A bounded ring buffer with optional blocking semantics. Used inside the trace pubsub to keep the in-memory window of trace events and inside the metrics sub-system for histogram buckets.

internal/init

internal/init/init.go — package-level init() ordering hook. main.go deliberately blank-imports this package first so any tweaks to runtime memory limits or panic handlers happen before any other init runs.

internal/amztime

AWS-compatible time formats: ISO8601 with the AWS-specific quirks (yyyyMMddTHHmmssZ for SigV4, etc.). Tiny but pervasive.

internal/color

Terminal colour helpers used in the startup banner (cmd/server-startup-msg.go) and in mc admin trace output. Detects whether stdout is a TTY.

internal/arn

AWS ARN parsing. Used by replication, notifications, and STS to validate target ARNs.

internal/jwt

JWT helpers used for the embedded console session token and for STS AssumeRoleWithWebIdentity. Built on github.com/golang-jwt/jwt/v4.

Integration points

  • Each package is small enough to be self-contained. Most are imported from one or two places.
  • The exception is internal/cachevalue, which is in nearly every metrics collector.

Entry points for modification

  • New init hook. Add to internal/init/init.go. Don't introduce a side-effecty top-level init() in cmd/.
  • New pubsub topic. internal/pubsub.New[T]() for each topic; don't try to multiplex types in one bus.
  • New time format. internal/amztime is the right home for AWS-flavoured timestamps; standard times use Go's time package.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

pubsub and utilities – MinIO wiki | Factory