Skip to content

alpha: add public extensibility hooks for the gRPC server and CLI flags#9742

Open
matthewmcneely wants to merge 1 commit into
mainfrom
oss-alpha-extensibility-hooks
Open

alpha: add public extensibility hooks for the gRPC server and CLI flags#9742
matthewmcneely wants to merge 1 commit into
mainfrom
oss-alpha-extensibility-hooks

Conversation

@matthewmcneely

Copy link
Copy Markdown
Contributor

What

Introduces dgraph/cmd/alpha/hooks.go, declaring package-level function vars with upstream-safe no-op defaults:

  • RegisterFlags(*pflag.FlagSet) — register extra CLI flags
  • RegisterZanzibar(*grpc.Server) — register an extra gRPC service
  • ZanzibarUnaryInterceptor() grpc.UnaryServerInterceptor / ZanzibarStreamInterceptor() grpc.StreamServerInterceptor — optional auth interceptors (returning nil = not installed)

In a stock build the defaults run, so behavior is unchanged.

It also refactors serveGRPC to build its interceptors as slices and install them via grpc.ChainUnaryInterceptor / grpc.ChainStreamInterceptor instead of a single grpc.UnaryInterceptor, so multiple interceptors can compose. The audit interceptor stays first.

Why

Lets a build register an extra gRPC service, CLI flags, and auth interceptors by reassigning the vars from its own init(), with no further changes to run.go — the same extension-hook pattern already used elsewhere in the tree.

Notes for review

  • Hook naming. The service/interceptor hooks are named after their first consumer (Zanzibar). I'm happy to rename to neutral terms (e.g. RegisterExtraService / ServiceUnaryInterceptor) if you'd prefer the public surface not name a specific consumer.
  • Copyright header. hooks.go carries an Apache-2.0 header attributed to the downstream author where the file originated. Flag if you'd rather it use the standard project header.

Introduce dgraph/cmd/alpha/hooks.go declaring package-level function vars with upstream-safe no-op defaults: RegisterFlags(*pflag.FlagSet), RegisterZanzibar(*grpc.Server), and ZanzibarUnary/StreamInterceptor() returning nil. In a stock build the defaults run, so behavior is unchanged.

Refactor serveGRPC to build its interceptors as slices and install them via grpc.ChainUnaryInterceptor / grpc.ChainStreamInterceptor instead of a single grpc.UnaryInterceptor. The audit interceptor stays first; the chain lets additional unary/stream interceptors compose. Wire RegisterFlags(flag) into Alpha's flag setup and RegisterZanzibar(s) into the server registration.

These are extension points: a build can register an extra gRPC service, CLI flags, and auth interceptors by reassigning the vars from its own init(), with no further changes to run.go.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@matthewmcneely matthewmcneely requested a review from a team as a code owner June 11, 2026 18:52
@github-actions github-actions Bot added the go Pull requests that update Go code label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code

Development

Successfully merging this pull request may close these issues.

1 participant