kang

package
v0.0.0-...-fc9199a Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID extracts the request ID from context

func IsDebugEnabled

func IsDebugEnabled(ctx context.Context) bool

IsDebugEnabled checks if debug logging is enabled for the request

func RegisterLoggingHandlers

func RegisterLoggingHandlers(mux *http.ServeMux, loggerManager *LoggerManager, basePath string)

RegisterLoggingHandlers registers logging control handlers

func RegisterPprofHandlers

func RegisterPprofHandlers(mux *http.ServeMux)

RegisterPprofHandlers mounts Go's standard net/http/pprof debug endpoints (heap/goroutine/CPU profiles, etc.) on mux at the conventional /debug/pprof path. This path is not configurable: pprof.Index resolves profile names (heap, goroutine, ...) by trimming a literal "/debug/pprof/" prefix internally, so mounting elsewhere breaks lookups for anything but cmdline/profile/symbol/trace.

These endpoints can leak sensitive information (command-line arguments, memory contents, source file paths), and CPU profiling pins CPU usage for the requested duration. Treat them with at least as much care as /kang/snapshot -- do not expose them on a public listener.

Types

type Config

type Config struct {
	Service       ServiceMetadata
	TypeLister    TypeLister
	ObjectLister  ObjectLister
	ObjectGetter  ObjectGetter
	StatsProvider StatsProvider
	URIBase       string // default: "/kang"
}

Config contains configuration for the Kang server

type DebugContextKey

type DebugContextKey string

DebugContextKey is used to store debug flag in request context

type DebugLogger

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

DebugLogger wraps a logrus logger to respect per-request and global debug settings

func GetDebugLogger

func GetDebugLogger(logger *logrus.Logger, r *http.Request) *DebugLogger

GetDebugLogger returns a DebugLogger for the given request context

func GetDebugLoggerWithManager

func GetDebugLoggerWithManager(logger *logrus.Logger, r *http.Request, manager *LoggerManager, loggerName string) *DebugLogger

GetDebugLoggerWithManager returns a DebugLogger with manager support

func NewDebugLogger

func NewDebugLogger(logger *logrus.Logger, ctx context.Context) *DebugLogger

NewDebugLogger creates a logger that respects per-request debug settings

func NewDebugLoggerWithManager

func NewDebugLoggerWithManager(logger *logrus.Logger, ctx context.Context, manager *LoggerManager, name string) *DebugLogger

NewDebugLoggerWithManager creates a logger that respects both global and per-request debug

func (*DebugLogger) Debug

func (dl *DebugLogger) Debug(args ...interface{})

Debug logs at debug level

func (*DebugLogger) Debugf

func (dl *DebugLogger) Debugf(format string, args ...interface{})

Debugf logs at debug level with format

func (*DebugLogger) Error

func (dl *DebugLogger) Error(args ...interface{})

func (*DebugLogger) Errorf

func (dl *DebugLogger) Errorf(format string, args ...interface{})

func (*DebugLogger) Info

func (dl *DebugLogger) Info(args ...interface{})

Pass-through methods (not affected by debug toggle)

func (*DebugLogger) Infof

func (dl *DebugLogger) Infof(format string, args ...interface{})

func (*DebugLogger) Warn

func (dl *DebugLogger) Warn(args ...interface{})

func (*DebugLogger) Warnf

func (dl *DebugLogger) Warnf(format string, args ...interface{})

func (*DebugLogger) WithFields

func (dl *DebugLogger) WithFields(fields logrus.Fields) *logrus.Entry

WithFields returns an entry with fields

type DebugMiddleware

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

DebugMiddleware is HTTP middleware that enables per-request debug logging

func NewDebugMiddleware

func NewDebugMiddleware() *DebugMiddleware

NewDebugMiddleware creates a new debug middleware

func (*DebugMiddleware) Handler

func (dm *DebugMiddleware) Handler(next http.Handler) http.Handler

Handler wraps an HTTP handler with debug logging support

type LoggerInfo

type LoggerInfo struct {
	Name  string `json:"name"`
	Level string `json:"level"`
}

LoggerInfo represents information about a logger

type LoggerManager

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

LoggerManager manages logrus loggers and allows dynamic level changes

func NewLoggerManager

func NewLoggerManager() *LoggerManager

NewLoggerManager creates a new LoggerManager

func (*LoggerManager) GetLogger

func (lm *LoggerManager) GetLogger(name string) (*logrus.Logger, error)

GetLogger retrieves a logger by name

func (*LoggerManager) GetObject

func (lm *LoggerManager) GetObject(typeName, id string) (interface{}, error)

GetObject implements ObjectGetter

func (*LoggerManager) HandleSetLogLevel

func (lm *LoggerManager) HandleSetLogLevel(w http.ResponseWriter, r *http.Request)

HandleSetLogLevel handles POST requests to change log levels

func (*LoggerManager) ListObjects

func (lm *LoggerManager) ListObjects(typeName string) []string

ListObjects implements ObjectLister

func (*LoggerManager) ListTypes

func (lm *LoggerManager) ListTypes() []string

ListTypes implements TypeLister

func (*LoggerManager) Register

func (lm *LoggerManager) Register(name string, logger *logrus.Logger)

Register adds a logger to the manager

func (*LoggerManager) SetLevel

func (lm *LoggerManager) SetLevel(name, levelStr string) error

SetLevel changes the log level for a logger

type ObjectGetter

type ObjectGetter interface {
	GetObject(typeName, id string) (interface{}, error)
}

ObjectGetter retrieves a specific object by type and ID

type ObjectLister

type ObjectLister interface {
	ListObjects(typeName string) []string
}

ObjectLister lists all objects of a given type

type RuntimeStats

type RuntimeStats struct {
	Goroutines      int    `json:"goroutines"`
	NumCPU          int    `json:"num_cpu"`
	HeapAllocBytes  uint64 `json:"heap_alloc_bytes"`
	HeapSysBytes    uint64 `json:"heap_sys_bytes"`
	HeapObjects     uint64 `json:"heap_objects"`
	StackInUseBytes uint64 `json:"stack_in_use_bytes"`
	GCCount         uint32 `json:"gc_count"`
	GCPauseTotalNs  uint64 `json:"gc_pause_total_ns"`
	LastGCPauseNs   uint64 `json:"last_gc_pause_ns"`
}

RuntimeStats captures a point-in-time snapshot of the current process's Go runtime metrics -- goroutines, heap usage, and GC activity.

func CollectRuntimeStats

func CollectRuntimeStats() RuntimeStats

CollectRuntimeStats gathers RuntimeStats for the calling process. Safe to call from any StatsProvider implementation, not just SimpleStats.

type Server

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

Server provides introspection via HTTP

func NewServer

func NewServer(config Config) *Server

NewServer creates a new Kang introspection server

func (*Server) RegisterHandlers

func (s *Server) RegisterHandlers(mux *http.ServeMux, uriBase string)

RegisterHandlers registers HTTP handlers for the given mux

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for standalone use

type ServiceMetadata

type ServiceMetadata struct {
	Name      string `json:"name"`
	Component string `json:"component,omitempty"`
	Ident     string `json:"ident"`
	Version   string `json:"version"`
	GoVersion string `json:"go_version"`
	GOOS      string `json:"goos"`
	GOARCH    string `json:"goarch"`
}

Service describes the service being debugged

type SetLevelRequest

type SetLevelRequest struct {
	Level string `json:"level"`
}

SetLevelRequest is the request format for changing log levels

type SimpleRegistry

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

SimpleRegistry is a simple in-memory implementation of TypeLister, ObjectLister, and ObjectGetter

func NewSimpleRegistry

func NewSimpleRegistry() *SimpleRegistry

NewSimpleRegistry creates a new SimpleRegistry

func (*SimpleRegistry) GetObject

func (r *SimpleRegistry) GetObject(typeName, id string) (interface{}, error)

GetObject implements ObjectGetter

func (*SimpleRegistry) ListObjects

func (r *SimpleRegistry) ListObjects(typeName string) []string

ListObjects implements ObjectLister

func (*SimpleRegistry) ListTypes

func (r *SimpleRegistry) ListTypes() []string

ListTypes implements TypeLister

func (*SimpleRegistry) Register

func (r *SimpleRegistry) Register(typeName, id string, obj interface{})

Register adds an object to the registry

func (*SimpleRegistry) Unregister

func (r *SimpleRegistry) Unregister(typeName, id string)

Unregister removes an object from the registry

type SimpleStats

type SimpleStats struct {
	StartTime time.Time `json:"start_time"`
	// contains filtered or unexported fields
}

SimpleStats is a simple statistics tracker

func NewSimpleStats

func NewSimpleStats() *SimpleStats

NewSimpleStats creates a new SimpleStats

func (*SimpleStats) GetStats

func (s *SimpleStats) GetStats() interface{}

GetStats implements StatsProvider

func (*SimpleStats) Increment

func (s *SimpleStats) Increment(key string)

Increment increments a numeric stat

func (*SimpleStats) Set

func (s *SimpleStats) Set(key string, value interface{})

Set sets a stat value

type Snapshot

type Snapshot struct {
	Service ServiceMetadata        `json:"service"`
	Stats   interface{}            `json:"stats,omitempty"`
	Types   []string               `json:"types"`
	Objects map[string]interface{} `json:"-"`
}

Snapshot represents a point-in-time view of service state

func (*Snapshot) MarshalJSON

func (s *Snapshot) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Snapshot

type StatsProvider

type StatsProvider interface {
	GetStats() interface{}
}

StatsProvider provides service statistics

type TypeLister

type TypeLister interface {
	ListTypes() []string
}

TypeLister lists all object types available in the service

Jump to

Keyboard shortcuts

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