serverdiag

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package serverdiag is the server's bounded, value-free stderr boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackgroundCallback added in v1.2.0

func BackgroundCallback(work func()) func()

BackgroundCallback guards a one-shot callback launched by another API.

func BackgroundErrorCallback added in v1.2.0

func BackgroundErrorCallback(work func() error) func() error

BackgroundErrorCallback preserves ordinary errors for errgroup-style APIs.

func CanonicalRoute added in v1.2.0

func CanonicalRoute(route string) string

func DrainBy added in v1.2.0

func DrainBy(deadline time.Time)

func Emit

func Emit(e Event)

func ErrorLog

func ErrorLog() *log.Logger

ErrorLog discards net/http's raw text, including unknown formats.

func ProcessStartedAt added in v1.2.0

func ProcessStartedAt() string

func RegisterBackgroundDrain added in v1.2.0

func RegisterBackgroundDrain(drain func(context.Context)) func()

RegisterBackgroundDrain avoids a dependency from diagnostics to the file logger.

func RegisterRoutes

func RegisterRoutes(routes ...string)

RegisterRoutes is called with the static dispatch inventory during package init.

func Shutdown

func Shutdown(ctx context.Context)

func StartBackground added in v1.2.0

func StartBackground(policy BackgroundPolicy, stop <-chan struct{}, work, finished func())

StartBackground owns the panic boundary and completion callback. Restart is only for idempotent work; finished runs once, after all restart attempts.

func Use

func Use(s *Sink) func()

Use installs the process diagnostic sink. The caller owns its bounded shutdown.

Types

type BackgroundPolicy added in v1.2.0

type BackgroundPolicy uint8
const (
	BackgroundStop BackgroundPolicy = iota
	BackgroundRestart
)

type Event

type Event struct {
	RestartCount     uint64  `json:"restart_count,omitempty"`
	AccessLogEnabled *bool   `json:"access_log_enabled,omitempty"`
	MaxSizeBytes     int64   `json:"max_size_bytes,omitempty"`
	MaxFiles         int     `json:"max_files,omitempty"`
	MaxAgeDays       int     `json:"max_age_days,omitempty"`
	AccessDropped    uint64  `json:"dropped_total,omitempty"`
	WriteErrors      uint64  `json:"write_errors_total,omitempty"`
	RotationErrors   uint64  `json:"rotation_errors_total,omitempty"`
	PruneErrors      uint64  `json:"prune_errors_total,omitempty"`
	Reopens          uint64  `json:"reopens_total,omitempty"`
	Bind             string  `json:"bind,omitempty"`
	Detail           string  `json:"detail,omitempty"`
	Flag             string  `json:"flag,omitempty"`
	ForwardedHint    bool    `json:"-"`
	Status           string  `json:"status,omitempty"`
	Message          string  `json:"message,omitempty"`
	Type             string  `json:"type"`
	Reason           string  `json:"reason,omitempty"`
	Route            string  `json:"route,omitempty"`
	Peer             string  `json:"peer,omitempty"`
	Count            uint64  `json:"count,omitempty"`
	Targets          int     `json:"targets,omitempty"`
	Accepted         int     `json:"accepted,omitempty"`
	Failed           int     `json:"failed,omitempty"`
	Bytes            int64   `json:"bytes,omitempty"`
	PanicType        string  `json:"panic_type,omitempty"`
	Stack            []Frame `json:"stack,omitempty"`
	ProcessStartedAt string  `json:"process_started_at"`
	DroppedTotal     uint64  `json:"diagnostics_dropped_total"`
}

Event contains only classified fields; it never holds requests or errors. Route must already be a registered constant template (controlpanel.AccessRoute).

func Panic

func Panic(v any) Event

Panic never invokes Error/String or reflect.Type.String on a dynamic type.

type Frame

type Frame struct {
	Function string `json:"function"`
	File     string `json:"file"`
	Line     int    `json:"line"`
}

type Sink

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

Sink owns one writer and a fixed-size queue. A blocked writer never blocks Emit.

func New

func New(w io.Writer) *Sink

func (*Sink) Close

func (s *Sink) Close(ctx context.Context)

func (*Sink) Emit

func (s *Sink) Emit(e Event)

func (*Sink) Flush

func (s *Sink) Flush(ctx context.Context) bool

Flush waits for earlier events without creating an I/O goroutine per caller.

Jump to

Keyboard shortcuts

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