detek

package
v0.0.0-...-4fef4b3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(cause error, reason ErrorType) error

func TypeOf

func TypeOf(v interface{}) reflect.Type

func Typing

func Typing[T any](s *Stored, err error) (T, error)

Typing a result of (c *DetekContext).Get Just a Syntactic Sugar.

Types

type Collector

type Collector interface {
	GetMeta() CollectorInfo
	Do(ctx DetekContext) error
}

type CollectorInfo

type CollectorInfo struct {
	MetaInfo
	Required  DependencyMeta
	Producing DependencyMeta
}

Collector Definitions

type DependencyInfo

type DependencyInfo struct {
	Type reflect.Type
}

type DependencyMeta

type DependencyMeta map[string]DependencyInfo

map[name] default initialized interface for type hint.

type Description

type Description struct {
	// Show what current situation is
	Explanation string `json:"explanation"`
	// Show how to solve this
	Solution string `json:"solution,omitempty"`
}
var (
	NormalStatus Description = Description{
		Explanation: "Everything is normal",
	}
	NoDepStatus Description = Description{
		Explanation: "Not executed, some of required data is not provided",
		Solution:    "Check if every Collectors are executed properly",
	}
	ErrOnDetectorStatus Description = Description{
		Explanation: "Detector is failed with an error",
		Solution:    "This may be a bug in this program. Check an error message",
	}
)

type Detector

type Detector interface {
	GetMeta() DetectorInfo
	Do(ctx DetekContext) (*ReportSpec, error)
}

Detector Definitions

type DetectorInfo

type DetectorInfo struct {
	MetaInfo
	Required DependencyMeta

	// Show how severe this case is when the thing has happened.
	Level SeverityLevel

	// Show what user can do when the thing has happened.
	IfHappened Description `json:"-"`
}

type DetekContext

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

func (*DetekContext) Context

func (c *DetekContext) Context() context.Context

func (*DetekContext) Get

func (c *DetekContext) Get(key string, v any) (*Stored, error)

Get will return data which was "Set" with specifed "key" if "v" is nil, it will just return "Stored" data. (if exists) if "v" is NOT a pointer type of the original data, it will return error, saying that type is incorrect. if "v" is a pointer type of the original data, it will attempts to copy the original data to a given pointer.

example 1:

var data string
c.Set("some_key", "some_string_data")
c.Get("some_key", &data)
fmt.Println(data) // will print "some_string_data"

example 2:

c.Set("some_key", "some_string_data")
data, err := Typing[string](c.Get("some_key", nil))
fmt.Println(data) // will print "some_string_data"

func (*DetekContext) Set

func (c *DetekContext) Set(key string, val interface{}) error

type DetekError

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

func (*DetekError) Error

func (d *DetekError) Error() string

func (*DetekError) Unwrap

func (d *DetekError) Unwrap() error

type ErrorType

type ErrorType string
const (
	ErrNotEnoughConfig ErrorType = "not enough config provided for producer"
	ErrKeyNotFound     ErrorType = "requested key not found"
)

type JSONableData

type JSONableData struct {
	Description string `json:"description"`

	// You can set any "JSON-Marshal-able" data in here
	// one depth JSON (object or array) is recommended, but not required.
	Data any `json:"data"`
}

func (*JSONableData) String

func (j *JSONableData) String() string

type Manager

type Manager struct {
	Detector  []Detector
	Collector []Collector
	// contains filtered or unexported fields
}

func NewManager

func NewManager(collector []Collector, detector []Detector) *Manager

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, opts *MangerRunOptions) (*ReportList, error)

Work Flow (for now) 1. Do Collector Things Synchronously (for now) 2. Check Any Error is Returned (if error, creating reports in here) 3. Do Detector Things Synchronously (for now) 4. Aggregate Reports 5. Return

func (*Manager) ShowPlan

func (m *Manager) ShowPlan() ([]Collector, []Detector)

type MangerRunOptions

type MangerRunOptions struct{}

TODO(@scotty.scott): Labels, etc....

type MetaInfo

type MetaInfo struct {
	// Naming Convention (for Dectector)
	//   (the cluster has) abnormal_pod
	//   (the cluster has) not_ready_node
	//   (the cluster has) deployment_without_pdb
	//   (the cluster has) obsolete_dns_mode
	// omit "it has" and "/^kubernetes/g".
	ID          string   `json:"id"`
	Description string   `json:"description"`
	Labels      []string `json:"labels,omitempty"`
}

type Report

type Report struct {
	MetaInfo
	CreatedAt time.Time     `json:"created_at"`
	Level     SeverityLevel `json:"level"`

	CurrentState Description `json:"-"`
	ReportSpec
}

type ReportExportingFormat

type ReportExportingFormat struct {
	ID          string    `json:"id"`
	Description string    `json:"description"`
	Labels      []string  `json:"labels"`
	CreatedAt   time.Time `json:"created_at"`

	Level            SeverityLevel            `json:"level"`
	LevelDescription SeverityLevelDescription `json:"level_description"`

	CurrentState string       `json:"current_state"`
	Solution     string       `json:"solution"`
	Problem      JSONableData `json:"problem"`

	Attachments []JSONableData `json:"attachments"`
}

type ReportList

type ReportList struct {
	StartedAt  time.Time `json:"started_at"`
	FinishedAt time.Time `json:"finished_at"`

	Reports []Report `json:"reports"`
}

type ReportSpec

type ReportSpec struct {
	// Is this Passed?
	HasPassed bool `json:"-"`

	// Attachment to show the causes of problem.
	Problem JSONableData `json:"problem,omitempty"`

	// Attachment for debugging purpose
	Attachment []JSONableData `json:"attachment,omitempty"`
}

type SeverityLevel

type SeverityLevel string
const (
	// Fatal if some feature or statuses are 100% fully not functional.
	// It is likely that the cluster already in catastrophic situation.
	Fatal SeverityLevel = "Fatal"

	// Error if some feature or statuses are partially worked.
	// Somehow Kubernetes magic makes services work, but need some fix.
	Error SeverityLevel = "Error"

	// Warn if some features or statuses are fully works, but there's something not recommended there.
	// e.g, not setting limits in pod spec is not recommended, but doesn't harm your service.
	Warn SeverityLevel = "Warn"

	// Normal if everything is fine
	Normal SeverityLevel = "Normal"

	// Something unexpected occur, can not examine severity
	Unknown SeverityLevel = "Unknown"
)

func (*SeverityLevel) ToInt

func (s *SeverityLevel) ToInt() int

type SeverityLevelDescription

type SeverityLevelDescription struct {
	// Fatal if some feature or statuses are 100% fully not functional.
	// It is likely that the cluster already in catastrophic situation.
	Fatal *Description `json:"fatal,omitempty"`

	// Error if some feature or statuses are partially worked.
	// Somehow kubernetes magic makes some services works, but need some fix.
	Error *Description `json:"error,omitempty"`

	// Warn if some features or statuses are fully workes, but there's something not recommended there.
	// e.g, not setting limits in pod spec is not recommended, but doesn't harm your service.
	Warn *Description `json:"warn,omitempty"`

	// Normal if everything is fine
	Normal *Description `json:"normal,omitempty"`
}

SeverityLevelDescription is a definition of descriptions that show what is the meaning of each level.

type Store

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

func (*Store) Get

func (s *Store) Get(key string) (interface{}, *Stored, error)

func (*Store) Set

func (s *Store) Set(key string, val *Stored) error

type Stored

type Stored struct {
	Value      interface{}
	Type       reflect.Type
	ProducedBy *MetaInfo
}

type TypedStored

type TypedStored[T any] struct {
	Value T
	Stored
}

Jump to

Keyboard shortcuts

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