insightpriority

package
v0.6.74 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Overview

Package insightpriority evaluates the CustomInsightPriority scripts that override the built-in priority of failing objects in the cluster insights and the cluster health score.

Scripts are sandboxed Python run by Monty. Unlike the Helm templating runtime they get no host callbacks, no OS access and no clock: everything a script can see is in its input, so the same input always gives the same priorities.

Index

Constants

View Source
const (

	// EvaluationTimeout bounds one evaluation of a script.
	EvaluationTimeout = 2 * time.Second
)

Variables

View Source
var ErrInvalidScript = errors.New("invalid script")

ErrInvalidScript means the script can not be compiled, or does not define evaluate.

Functions

func Compile

func Compile(ctx context.Context, script string) (err error)

Compile loads the script and checks that it defines evaluate. It does not call it.

func Run

func Run(ctx context.Context, script string, input any) (_ json.RawMessage, err error)

Run calls evaluate with the input and returns what it returned, as JSON.

Types

type Cluster

type Cluster struct {
	Nodes      int64
	Namespaces int64
}

Cluster is what scripts are told about the cluster as a whole.

type Evaluator

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

Evaluator runs the registered scripts over the failing roots of a ping.

func NewEvaluator

func NewEvaluator(registry *Registry) *Evaluator

func (*Evaluator) Overrides

func (e *Evaluator) Overrides(ctx context.Context, roots []insights.Root, cluster Cluster, now time.Time) map[string]insights.Override

Overrides gives every failing root to the script that owns it, and returns the priorities the scripts decided.

A root is owned by at most one script, the matching one with the highest precedence, scripts are not chained and a script never sees a root that is decided by its annotation. A script that fails only loses its own roots to the built-in priority. The result is the same for the same input, nothing time or state dependent reaches a script.

type Registry

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

Registry holds the scripts that compiled, and the results of their evaluations. It is safe for concurrent use.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Events

func (r *Registry) Events() <-chan event.GenericEvent

Events emits the scripts whose result changed, to be reconciled so their status follows.

func (*Registry) Remove

func (r *Registry) Remove(key types.NamespacedName)

Remove forgets a script and its result.

func (*Registry) Result

func (r *Registry) Result(key types.NamespacedName) (Result, bool)

Result returns the result of the last evaluation of a script.

func (*Registry) Scripts

func (r *Registry) Scripts() []Script

Scripts returns the registered scripts, the ones that own contested objects first.

func (*Registry) Set

func (r *Registry) Set(script Script)

Set registers a script, replacing the one with the same key. The result of a previous version of the script is dropped.

type Result

type Result struct {
	// Generation of the script that produced the result, a result of another generation is not recorded.
	Generation int64
	Time       time.Time
	Matched    int
	Overridden int
	Ignored    int
	Duration   time.Duration
	// Err is why the script failed, its objects then keep their built-in priority.
	Err string
	// LostTo are the scripts that took objects away from this one because of their precedence.
	LostTo []types.NamespacedName
}

Result is the outcome of the last evaluation of a script.

type RunFunc

type RunFunc func(ctx context.Context, script string, input any) (json.RawMessage, error)

RunFunc calls the evaluate function of a script with an input and returns what it returned, as JSON.

type Script

type Script struct {
	Key        types.NamespacedName
	Precedence int
	Source     string
	// Generation of the CustomInsightPriority, a result of an older generation is stale.
	Generation int64
	// contains filtered or unexported fields
}

Script is a validated CustomInsightPriority.

func NewScript

func NewScript(cr *v1alpha1.CustomInsightPriority) (Script, error)

NewScript validates the target of a CustomInsightPriority. The script itself is checked by Compile.

func (Script) Matches

func (s Script) Matches(r insights.Root) bool

Matches reports whether the script is responsible for the root: it has to match every field of the target that is set.

Jump to

Keyboard shortcuts

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