activity

package
v3.13.0 Latest Latest
Warning

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

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

Documentation

Overview

Package activity tracks one service instance's request activity: how many requests are in flight right now, how many have been served, and when the last one started. A Counter is created per service per server in the runtime and shared by reference between the request-handling choke points that feed it (the gRPC appctx interceptor, the HTTP router) and the built-in `activity` invocation that reports it — no process-global state, and one counter per listener means the granularity matches a node id (per instance). The signal backs the "is this instance still serving requests?" question during a drain and restart: in-flight zero, plus an idle window, means quiesced.

This is a leaf with no reva dependencies, so every layer that touches a Counter can do so without an import cycle. All methods are nil-safe: a nil *Counter (a service with no counter wired, e.g. serverless) reads as idle and silently drops writes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter accumulates one service instance's request activity: an aggregate (lock-free atomics, so the quiescence check stays cheap) plus a lazily-built per-method breakdown.

func New

func New() *Counter

New returns a fresh Counter.

func (*Counter) Enter

func (c *Counter) Enter(method string) func()

Enter records the start of a request and returns the function to call when it finishes. method is the RPC method name for the per-method breakdown; an empty method (e.g. HTTP) counts toward the aggregate only. Typical use: `defer counter.Enter(m)()`.

func (*Counter) Snapshot

func (c *Counter) Snapshot() Stat

Snapshot returns the counter's current stats — aggregate plus per-method breakdown (a zero Stat for a nil counter or one that has served nothing).

type Stat

type Stat struct {
	InFlight    int64     // requests currently being served
	Total       int64     // requests served since the process started
	LastRequest time.Time // start of the most recent request (zero if none)
	Methods     map[string]Stat
}

Stat is a point-in-time view of one service's request activity. Methods holds the per-RPC-method breakdown on the aggregate snapshot (nil on a per-method entry).

Jump to

Keyboard shortcuts

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