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 ¶
const ( // EvaluationTimeout bounds one evaluation of a script. EvaluationTimeout = 2 * time.Second )
Variables ¶
var ErrInvalidScript = errors.New("invalid script")
ErrInvalidScript means the script can not be compiled, or does not define evaluate.
Functions ¶
Types ¶
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 (*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.
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 ¶
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.