base

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckContext

type CheckContext interface {
	// ShouldCheck validate the process with policy item should be checked or ignore
	// Usually if the process already start profiling with specific process, the check should be ignored
	ShouldCheck(p api.ProcessInterface, item *PolicyItem) bool
}

type CheckType

type CheckType string
const (
	CheckTypeProcessCPU          CheckType = "PROCESS_CPU"
	CheckTypeProcessThreadCount  CheckType = "PROCESS_THREAD_COUNT"
	CheckTypeSystemLoad          CheckType = "SYSTEM_LOAD"
	CheckTypeHTTPErrorRate       CheckType = "HTTP_ERROR_RATE"
	CheckTypeHTTPAvgResponseTime CheckType = "HTTP_AVG_RESPONSE_TIME"
)

type Checker

type Checker interface {
	// Init the checker with basic configs
	Init(config *ContinuousConfig) error
	// SyncPolicies from all service policies and processes
	SyncPolicies(policies []*SyncPolicyWithProcesses)
	// Fetch the policies data and save to the time windows
	Fetch() error
	// Check the policies are reached
	// Each policy with process should use CheckContext.ShouldCheck to validate the policy should be checked or not
	Check(ctx CheckContext, metricsAppender *MetricsAppender) []ThresholdCause
	// Close the checker
	Close() error
}

type ContinuousConfig

type ContinuousConfig struct {
	MeterPrefix string `mapstructure:"meter_prefix"` // continuous related meters prefix name

	FetchInterval string        `mapstructure:"fetch_interval"` // The interval of fetch metrics from the system
	CheckInterval string        `mapstructure:"check_interval"` // The interval of check metrics is reach the thresholds
	Trigger       TriggerConfig `mapstructure:"trigger"`
}

type LatestWindowData

type LatestWindowData[D comparable] struct {
	Value D
}

LatestWindowData only save the last data in one slot

func (*LatestWindowData[D]) Accept

func (t *LatestWindowData[D]) Accept(data D)

func (*LatestWindowData[D]) Get

func (t *LatestWindowData[D]) Get() D

func (*LatestWindowData[D]) Reset

func (t *LatestWindowData[D]) Reset()

type MetricsAppender

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

func NewMetricsAppender

func NewMetricsAppender(prefix string) *MetricsAppender

func (*MetricsAppender) AppendProcessSingleValue

func (m *MetricsAppender) AppendProcessSingleValue(name string, p api.ProcessInterface, labels map[string]string, value float64)

func (*MetricsAppender) Flush

type Policy

type Policy struct {
	TargetProfilingType TargetProfilingType
	Items               map[CheckType]*PolicyItem

	ServicePolicy *ServicePolicy
}

type PolicyItem

type PolicyItem struct {
	Threshold string
	Period    int
	Count     int
	URIList   []string
	URIRegex  string

	Policy *Policy
}

func (*PolicyItem) SameURIFilter

func (p *PolicyItem) SameURIFilter(other *PolicyItem) bool

type ServicePolicy

type ServicePolicy struct {
	Service string
	UUID    string

	Policies  []*Policy
	Processes map[string]api.ProcessInterface
}

type SyncPolicyWithProcesses

type SyncPolicyWithProcesses struct {
	Policy    *Policy
	Processes map[string]api.ProcessInterface
}

type TargetProfilingType

type TargetProfilingType string
const (
	TargetProfilingTypeOnCPU   TargetProfilingType = "ON_CPU"
	TargetProfilingTypeOffCPU  TargetProfilingType = "OFF_CPU"
	TargetProfilingTypeNetwork TargetProfilingType = "NETWORK"
)

type ThresholdCause

type ThresholdCause interface {
	// Process is over threshold
	Process() api.ProcessInterface
	// FromPolicy current from which policy
	FromPolicy() *PolicyItem
	// GenerateTransferCause transmit to the backend
	GenerateTransferCause() *v3.ContinuousProfilingCause
}

type TimeWindows

type TimeWindows[V any, R any] struct {
	// contains filtered or unexported fields
}

func NewTimeWindows

func NewTimeWindows[V any, R any](items []*PolicyItem, generator func() WindowData[V, R]) *TimeWindows[V, R]

func (*TimeWindows[D, R]) Add

func (t *TimeWindows[D, R]) Add(tm time.Time, val D)

func (*TimeWindows[D, R]) FlushMostRecentData

func (t *TimeWindows[D, R]) FlushMostRecentData() (R, bool)

func (*TimeWindows[D, R]) FlushMultipleRecentData

func (t *TimeWindows[D, R]) FlushMultipleRecentData() ([]R, bool)

func (*TimeWindows[V, R]) MatchRule

func (t *TimeWindows[V, R]) MatchRule(policy *PolicyItem, check func(slot R) bool) (lastMatch R, isMatch bool)

func (*TimeWindows[V, R]) ScalePeriod

func (t *TimeWindows[V, R]) ScalePeriod(items []*PolicyItem)

type Trigger

type Trigger interface {
	// Init trigger
	Init(moduleMgr *module.Manager, conf *ContinuousConfig) error
	// ShouldTrigger validate the process should be trigger task
	ShouldTrigger(p api.ProcessInterface) bool
	// TriggerTasks generate task and execute that policy could be trigger
	TriggerTasks(reporter TriggerReporter, causes []ThresholdCause) int
}

type TriggerConfig

type TriggerConfig struct {
	ExecuteDuration string `mapstructure:"execute_duration"` // the duration of the profiling task
	SilenceDuration string `mapstructure:"silence_duration"` // the duration between the execution of the same profiling task.
}

type TriggerReporter

type TriggerReporter interface {
	ReportProcesses(causeProcess api.ProcessInterface, profilingProcesses []api.ProcessInterface, cases []ThresholdCause,
		taskSetter func(task *taskBase.ProfilingTask),
		reportSetter func(report *v3.ContinuousProfilingReport)) (*task.Context, error)
}

type URIChecker

type URIChecker struct {
	FixedURIList []string
	URIRegexList []*regexp.Regexp
}

type URIResponseDurationTimeoutRate

type URIResponseDurationTimeoutRate struct {
	Timeout int // Define how long(ms) is considered a timeout
	Rate    int // Response timeout rate
}

type WindowData

type WindowData[D any, R any] interface {
	// Reset the data content
	Reset()
	// Accept add data
	Accept(data D)
	// Get calculate the result
	Get() R
}

WindowData the slot data under TimeWindows

func NewLatestWindowData

func NewLatestWindowData[D comparable]() WindowData[D, D]

Jump to

Keyboard shortcuts

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