health

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthPropertiesPrefix = "management.endpoint.health"
)

Variables

View Source
var DefaultStaticStatusCodeMapper = StaticStatusCodeMapper{
	StatusUp:           http.StatusOK,
	StatusDown:         http.StatusServiceUnavailable,
	StatusOutOfService: http.StatusServiceUnavailable,
	StatusUnknown:      http.StatusInternalServerError,
}
View Source
var (
	DefaultStatusOrders = []Status{
		StatusDown, StatusOutOfService, StatusUp, StatusDown,
	}
)
View Source
var Module = &bootstrap.Module{
	Name:       "actuator-health",
	Precedence: bootstrap.ActuatorPrecedence,
	Options: []fx.Option{
		fx.Provide(
			BindHealthProperties,
			NewSystemHealthRegistrar,
			provideInterfaces,
		),
	},
}

Functions

func Use

func Use()

Types

type AggregateOption

type AggregateOption struct {
	StatusOrders []Status
}

type AggregateOptions

type AggregateOptions func(opt *AggregateOption)

type ComponentsDisclosureControl

type ComponentsDisclosureControl interface {
	ShouldShowComponents(ctx context.Context) bool
}

type CompositeHealth

type CompositeHealth struct {
	SimpleHealth
	Components map[string]Health `json:"components,omitempty"`
}

CompositeHealth implement Health

func NewCompositeHealth

func NewCompositeHealth(status Status, description string, components map[string]Health) *CompositeHealth

type CompositeIndicator

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

CompositeIndicator implement Indicator and SystemHealthRegistrar

func NewCompositeIndicator

func NewCompositeIndicator(opts ...IndicatorOptions) *CompositeIndicator

func (*CompositeIndicator) Add

func (c *CompositeIndicator) Add(contributors ...Indicator)

func (*CompositeIndicator) Health

func (c *CompositeIndicator) Health(ctx context.Context, options Options) Health

func (*CompositeIndicator) Name

func (c *CompositeIndicator) Name() string

type DetailedHealth

type DetailedHealth struct {
	SimpleHealth
	Details map[string]interface{} `json:"details,omitempty"`
}

DetailedHealth implement Health

func NewDetailedHealth

func NewDetailedHealth(status Status, description string, details map[string]interface{}) *DetailedHealth

type DetailsDisclosureControl

type DetailsDisclosureControl interface {
	ShouldShowDetails(ctx context.Context) bool
}

type DisclosureControl

type DisclosureControl interface {
	DetailsDisclosureControl
	ComponentsDisclosureControl
}

type DisclosureControlFunc

type DisclosureControlFunc func(ctx context.Context) bool

DisclosureControlFunc convert function to DisclosureControl This type can be registered via Registrar.Register

func (DisclosureControlFunc) ShouldShowComponents

func (fn DisclosureControlFunc) ShouldShowComponents(ctx context.Context) bool

func (DisclosureControlFunc) ShouldShowDetails

func (fn DisclosureControlFunc) ShouldShowDetails(ctx context.Context) bool

type Health

type Health interface {
	Status() Status
	Description() string
}

type HealthProperties

type HealthProperties struct {
	Status StatusProperties `json:"status"`

	// When to show components. If not specified the 'show-details' setting will be used.
	ShowComponents *ShowMode `json:"show-components"`

	// When to show full health details.
	ShowDetails ShowMode `json:"show-details"`

	// Permisions used to determine whether or not a user is authorized to be shown details.
	// When empty, all authenticated users are authorized.
	Permissions utils.CommaSeparatedSlice `json:"permissions"`
}

func BindHealthProperties

func BindHealthProperties(ctx *bootstrap.ApplicationContext) HealthProperties

BindHealthProperties create and bind SessionProperties, with a optional prefix

func NewHealthProperties

func NewHealthProperties() *HealthProperties

NewSessionProperties create a SessionProperties with default values

type Indicator

type Indicator interface {
	Name() string
	Health(context.Context, Options) Health
}

type IndicatorOption

type IndicatorOption struct {
	Name         string
	Contributors []Indicator
	Aggregator   StatusAggregator
}

type IndicatorOptions

type IndicatorOptions func(opt *IndicatorOption)

type Options

type Options struct {
	ShowDetails    bool
	ShowComponents bool
}

type PingIndicator

type PingIndicator struct {
}

func (PingIndicator) Health

func (b PingIndicator) Health(ctx context.Context, options Options) Health

func (PingIndicator) Name

func (b PingIndicator) Name() string

type Registrar

type Registrar interface {
	// Register configure SystemHealthRegistrar and HealthEndpoint
	// supported input parameters are:
	// 	- Indicator
	// 	- StatusAggregator
	// 	- DetailsDisclosureControl
	// 	- ComponentsDisclosureControl
	//  - DisclosureControl
	Register(items ...interface{}) error

	// MustRegister same as Register, but panic if there is error
	MustRegister(items ...interface{})
}

type ShowMode

type ShowMode int

ShowMode is options for showing items in responses from the HealthEndpoint web extensions.

const (
	// ShowModeNever Never show the item in the response.
	ShowModeNever ShowMode = iota
	// ShowModeAuthorized Show the item in the response when accessed by an authorized user.
	ShowModeAuthorized
	// ShowModeAlways Always show the item in the response.
	ShowModeAlways
	// ShowModeCustom Shows the item in response with a customized rule.
	ShowModeCustom
)

func (ShowMode) MarshalText

func (m ShowMode) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (ShowMode) String

func (m ShowMode) String() string

fmt.Stringer

func (*ShowMode) UnmarshalText

func (m *ShowMode) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type SimpleHealth

type SimpleHealth struct {
	Stat Status `json:"status"`
	Desc string `json:"description,omitempty"`
}

SimpleHealth implements Health

func (SimpleHealth) Description

func (h SimpleHealth) Description() string

func (SimpleHealth) Status

func (h SimpleHealth) Status() Status

type SimpleStatusAggregator

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

SimpleStatusAggregator implements StatusAggregator

func NewSimpleStatusAggregator

func NewSimpleStatusAggregator(opts ...AggregateOptions) *SimpleStatusAggregator

func (SimpleStatusAggregator) Aggregate

func (a SimpleStatusAggregator) Aggregate(_ context.Context, statuses ...Status) Status

type StaticStatusCodeMapper

type StaticStatusCodeMapper map[Status]int

func (StaticStatusCodeMapper) StatusCode

func (m StaticStatusCodeMapper) StatusCode(_ context.Context, status Status) int

type Status

type Status int
const (
	StatusUnknown Status = iota
	StatusUp
	StatusOutOfService
	StatusDown
)

func (Status) MarshalText

func (s Status) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Status) String

func (s Status) String() string

fmt.Stringer

func (*Status) UnmarshalText

func (s *Status) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type StatusAggregator

type StatusAggregator interface {
	Aggregate(context.Context, ...Status) Status
}

type StatusCodeMapper

type StatusCodeMapper interface {
	StatusCode(context.Context, Status) int
}

type StatusOrders

type StatusOrders []Status

func (*StatusOrders) UnmarshalText

func (o *StatusOrders) UnmarshalText(data []byte) error

encoding.TextUnmarshaler

type StatusProperties

type StatusProperties struct {
	// Comma-separated list of health statuses in order of severity.
	Orders StatusOrders `json:"order"`

	// Mapping of health statuses to HTTP status codes. By default, registered health
	// statuses map to sensible defaults (for example, UP maps to 200).
	ScMapping map[Status]int `json:"http-mapping"`
}

type SystemHealthRegistrar

type SystemHealthRegistrar struct {
	Indicator            *CompositeIndicator
	DetailsDisclosure    DetailsDisclosureControl
	ComponentsDisclosure ComponentsDisclosureControl
}

SystemHealthRegistrar implements Registrar

func NewSystemHealthRegistrar

func NewSystemHealthRegistrar(di regDI) *SystemHealthRegistrar

func (*SystemHealthRegistrar) MustRegister

func (i *SystemHealthRegistrar) MustRegister(items ...interface{})

func (*SystemHealthRegistrar) Register

func (i *SystemHealthRegistrar) Register(items ...interface{}) error

Register configure SystemHealthRegistrar supported input parameters are:

  • Indicator
  • StatusAggregator
  • DetailsDisclosureControl
  • ComponentsDisclosureControl
  • DisclosureControl

Directories

Path Synopsis
Package healthep Contains implementation of health endpoint as a separate package to avoid cyclic package dependency.
Package healthep Contains implementation of health endpoint as a separate package to avoid cyclic package dependency.

Jump to

Keyboard shortcuts

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