Help us shape the future of Go! Take the 2026 Go Developer Survey

gnmiserver

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package gnmiserver implements the gNMI RPC handlers shared by the `subscribe` and `collect` commands' northbound gNMI servers:

  • Subscribe and Get RPCs are served from a cache kept in sync with the configured subscriptions.
  • Set RPCs are relayed to the target(s) selected via the request Prefix.Target field. Target resolution is command specific and is provided by the caller as a TargetSelectFn. Relaying every RPC to the targets is what the `proxy` command does.
  • Get requests with paths under the `gnmic` origin are served by the caller provided InternalGetFn, typically from the command's own configuration.

The handlers are meant to be registered on a pkg/api/server gRPC server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DefaultSampleInterval is used when a stream/sample
	// subscription requests a zero sample interval.
	DefaultSampleInterval time.Duration
	// MinSampleInterval is used when a stream/sample subscription
	// requests a non-zero sample interval lower than this value.
	MinSampleInterval time.Duration
	// MinHeartbeatInterval is used when a subscription requests a
	// non-zero heartbeat interval lower than this value.
	MinHeartbeatInterval time.Duration
	// Debug enables additional debug logs.
	Debug bool
}

Config holds the handlers' behavioral knobs, taken from the `gnmi-server` configuration section.

type Handlers

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

Handlers implements the gNMI Get, Set and Subscribe RPC handlers.

func New

func New(cfg Config, c cache.Cache, logger *slog.Logger, selectTargets TargetSelectFn, internalGet InternalGetFn) *Handlers

New creates gNMI RPC handlers. c may be nil, in which case Subscribe RPCs and Get RPCs outside the `gnmic` origin are rejected with an `Unimplemented` status code.

func (*Handlers) Capabilities

func (h *Handlers) Capabilities(ctx context.Context, req *gnmi.CapabilityRequest) (*gnmi.CapabilityResponse, error)

Capabilities handles a gNMI Capabilities RPC, advertising the gNMI version and the encodings the server can carry (relayed unary RPCs and cache-served subscriptions pass values through in the encoding produced by the targets).

func (*Handlers) Get

func (h *Handlers) Get(ctx context.Context, req *gnmi.GetRequest) (*gnmi.GetResponse, error)

Get handles a gNMI Get RPC.

Requests with paths under the `gnmic` origin are served by the internal Get handler. Every other path is answered from the cache: the notifications stored for the selected target(s) under the requested path(s) are returned as they were received from the targets, with their timestamps and encoding. The request `type` and `encoding` fields are accepted and ignored. A path with no cached data yields an empty response, not an error.

The target is taken from Prefix.Target: empty or `*` selects every target, a comma separated list selects several. Relaying a Get to the targets is the job of `gnmic proxy`.

func (*Handlers) Set

func (h *Handlers) Set(ctx context.Context, req *gnmi.SetRequest) (*gnmi.SetResponse, error)

Set handles a gNMI Set RPC, relaying it to the target(s) selected via the request Prefix.Target field.

func (*Handlers) Subscribe

func (h *Handlers) Subscribe(req *gnmi.SubscribeRequest, stream gnmi.GNMI_SubscribeServer) error

Subscribe handles a gNMI Subscribe RPC, serving it from the cache.

type InternalGetFn

type InternalGetFn func(ctx context.Context, req *gnmi.GetRequest) (*gnmi.GetResponse, error)

InternalGetFn serves Get requests with paths under the `gnmic` origin.

type TargetSelectFn

type TargetSelectFn func(ctx context.Context, target string) (map[string]*target.Target, func(), error)

TargetSelectFn resolves the request Prefix.Target value into a set of gNMI targets. The returned cleanup function is called once the RPC is done; it is used to release connections dialed on demand.

Jump to

Keyboard shortcuts

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