admin

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package admin is Murmur's read-only control plane. It implements the AdminService defined in proto/murmur/admin/v1/admin.proto via Connect-RPC, which means the same endpoint speaks gRPC (for Go/JVM/Rust clients), gRPC-Web (for browsers without a proxy), and the Connect protocol (the browser UI's default — plain HTTP+JSON, no special transport).

The .proto is the contract. Anyone is welcome to point a different UI at the same endpoint, or generate a client in another language with `buf generate`. The Go server below is one implementation among many.

Pipelines register themselves with Server.Register; Server.Handler returns an http.Handler that serves the AdminService routes. Pair it with FullHandler if you also want the embedded UI on the same port.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UIHandler

func UIHandler() http.Handler

UIHandler returns an http.Handler that serves the embedded Vite build (web/dist copied into pkg/admin/dist by the build pipeline). Falls back to index.html for unknown paths so client-side routing works (refresh on /pipelines/foo).

If the embedded FS is empty (build wasn't run), the handler returns 503 with a pointer to the build instructions.

Types

type Option

type Option func(*Server)

Option configures a Server. Apply via NewServer(rec, opts...).

func WithAllowedOrigins

func WithAllowedOrigins(origins ...string) Option

WithAllowedOrigins sets the list of origins the admin server will respond to from cross-origin browsers. Pass exact origins ("https://dashboard.example") or the wildcard "*". Default is no CORS headers — same-origin only — which is the right default for the embedded UI in cmd/murmur-ui. Use "*" for local development against the Vite dev server (it proxies /api so cross-origin only matters when the UI is served by some other origin).

type PipelineInfo

type PipelineInfo struct {
	Name          string
	MonoidKind    string
	Windowed      bool
	WindowGranSec int64
	WindowRetSec  int64
	StoreType     string
	CacheType     string
	SourceType    string
}

PipelineInfo is the Go-friendly form of murmur.admin.v1.PipelineInfo. We keep a separate struct so package consumers don't have to import generated code, and so JSON tags work for any caller that wants to log it.

type QueryFn

type QueryFn func(op string, params map[string]string) (data []byte, present bool, err error)

QueryFn is the read-side closure each registered pipeline supplies. The op argument is one of "get" / "window" / "range"; params carries the per-op arguments (entity, bucket, duration_s, start, end, decode). Returns the raw stored bytes plus a `present` flag.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the admin control surface. Concurrent-safe.

func NewServer

func NewServer(recorder *metrics.InMemory, opts ...Option) *Server

NewServer constructs an admin Server. The recorder is shared with whatever runtime you've installed it on (typically streaming.Run via WithMetrics).

CORS is closed by default — pass WithAllowedOrigins(…) to open it up to the origins that should be able to talk to this server.

func (*Server) FullHandler

func (s *Server) FullHandler() http.Handler

FullHandler combines the admin Connect-RPC service and the embedded UI on a single mux. Requests under "/api/" are stripped of the prefix and forwarded to the AdminService handler (which expects paths of the form "/murmur.admin.v1.AdminService/<RPC>"); everything else is served by the SPA handler.

The "/api" prefix is a UI-side convention so the same dist works under `npm run dev` (Vite proxy: /api → :8080) and in production (embedded). Other non-browser clients can speak directly to the Connect service at "/" by pointing at <host>:<port>/murmur.admin.v1.AdminService/<RPC> if the API is the only thing on the port.

func (*Server) GetPipelineMetrics

GetPipelineMetrics implements murmur.admin.v1.AdminService/GetPipelineMetrics. Returns the in-memory metrics snapshot for one pipeline (events / errors / latency percentiles). Returns CodeNotFound for unknown pipeline names so clients can distinguish "no metrics yet" from "wrong name."

func (*Server) GetRange

GetRange implements murmur.admin.v1.AdminService/GetRange. Merges every bucket whose ID falls in [start_unix, end_unix] inclusive. Same error-code conventions as GetState plus CodeInvalidArgument when end < start.

func (*Server) GetState

GetState implements murmur.admin.v1.AdminService/GetState. Reads one (entity[, bucket]) tuple from the registered pipeline's store. Honors `decode=true` to populate StateValue.decoded with a monoid-typed view (see decodeForKind). Returns CodeInvalidArgument for missing entity, CodeNotFound for unknown pipeline, CodeInternal for store-side failures.

func (*Server) GetWindow

GetWindow implements murmur.admin.v1.AdminService/GetWindow. Merges the N most-recent buckets covering `duration_seconds` ending at the server's now via the pipeline's monoid. Same error-code conventions as GetState plus CodeInvalidArgument for non-positive durations.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns an http.Handler implementing the AdminService routes. Mount at "/" or under a subpath via http.StripPrefix.

func (*Server) Health

Health implements murmur.admin.v1.AdminService/Health. Always returns {status: "ok"}; the response is generated synchronously without touching pipeline state, so a slow store cannot make the health endpoint flap.

func (*Server) ListPipelines

ListPipelines implements murmur.admin.v1.AdminService/ListPipelines. Returns every registered pipeline's metadata, sorted by name for stable client-side rendering. Cheap (RAM-only) so the dashboard polls it every few seconds without coordination.

func (*Server) Register

func (s *Server) Register(info PipelineInfo, query QueryFn)

Register installs a pipeline's metadata and query closure. Idempotent — re-registering the same name overwrites.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL