Documentation ¶
Overview ¶
Package diag contains a mechanism for Replicator components to report structured diagnostic information.
Index ¶
- Variables
- type Diagnostic
- type DiagnosticFn
- type Diagnostics
- func (d *Diagnostics) Handler(auth types.Authenticator) http.Handler
- func (d *Diagnostics) Payload(ctx context.Context) map[string]any
- func (d *Diagnostics) Register(name string, intf Diagnostic) error
- func (d *Diagnostics) Unregister(name string)
- func (d *Diagnostics) Wrap(name string) (*Diagnostics, error)
- func (d *Diagnostics) Write(ctx context.Context, w io.Writer, pretty bool) error
Constants ¶
This section is empty.
Variables ¶
var Schema = ident.MustSchema(ident.New("_"), ident.New("diag"))
Schema is passed to the authenticator.
Functions ¶
This section is empty.
Types ¶
type Diagnostic ¶
type Diagnostic interface { // Diagnostic returns a json-serializable value that represent the // reportable state of the component. Diagnostic(context.Context) any }
Diagnostic is implemented by any type that can provide structured diagnostic data for use in a support engagement.
type DiagnosticFn ¶
A DiagnosticFn is passed to Diagnostics.Register. This type is use similarly to http.HandlerFunc.
func (DiagnosticFn) Diagnostic ¶
func (c DiagnosticFn) Diagnostic(ctx context.Context) any
Diagnostic implements Diagnostic.
type Diagnostics ¶
type Diagnostics struct {
// contains filtered or unexported fields
}
Diagnostics serves as a registry for Diagnostic implementations.
func New ¶
func New(ctx *stopper.Context) *Diagnostics
New constructs a Diagnostics. The instance will write itself to the log stream if the process receives a SIGUSR1.
func (*Diagnostics) Handler ¶
func (d *Diagnostics) Handler(auth types.Authenticator) http.Handler
Handler returns an http.Handler to provide a summary report. The Schema value will be passed to the Authenticator.
func (*Diagnostics) Payload ¶
func (d *Diagnostics) Payload(ctx context.Context) map[string]any
Payload returns the diagnostic payload.
func (*Diagnostics) Register ¶
func (d *Diagnostics) Register(name string, intf Diagnostic) error
Register adds a callback to generate a portion of the diagnostics output. The name will be used as the key in the emitted JSON literal, and the value will be the serialized form of the callback's return value. This method will return an error if the same name is registered twice.
Note that the callback may be called at any time (possibly concurrently), so implementations should be written in a thread-safe manner.
func (*Diagnostics) Unregister ¶
func (d *Diagnostics) Unregister(name string)
Unregister removes a registration.
func (*Diagnostics) Wrap ¶
func (d *Diagnostics) Wrap(name string) (*Diagnostics, error)
Wrap returns a new instance of Diagnostics that will report its values as an embedded value.