cache

package
v0.0.0-...-c2c6062 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StrongRead = time.Unix(0, 0).In(time.FixedZone("RuleCache StrongRead", 0xDB))

StrongRead is a special time used to request the read of a ruleset that contains all rule changes committed prior to the start of the read. (Rule changes made after the start of the read may also be returned.) Under the covers, this results in a Spanner Strong Read. See https://cloud.google.com/spanner/docs/reads for more.

Functions

This section is empty.

Types

type CachedRule

type CachedRule struct {
	// The failure association rule.
	Rule rules.Entry
	// The parsed and compiled failure association rule.
	Expr *lang.Expr
}

CachedRule represents a "compiled" version of a failure association rule. It should be treated as immutable, and is therefore safe to share across multiple threads.

func NewCachedRule

func NewCachedRule(rule *rules.Entry) (*CachedRule, error)

NewCachedRule initialises a new CachedRule from the given failure association rule.

type RulesCache

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

RulesCache is an in-process cache of failure association rules used by LUCI projects.

func NewRulesCache

func NewRulesCache(c caching.LRUHandle[string, *Ruleset]) *RulesCache

NewRulesCache initialises a new RulesCache.

func (*RulesCache) Ruleset

func (c *RulesCache) Ruleset(ctx context.Context, project string, minimumPredicatesVersion time.Time) (*Ruleset, error)

Ruleset obtains the Ruleset for a particular project from the cache, or if it does not exist, retrieves it from Spanner. MinimumPredicatesVersion specifies the minimum version of rule predicates that must be incorporated in the given Ruleset. If no particular version is desired, pass rules.StartingEpoch. If a strong read is required, pass StrongRead. Otherwise, pass the particular (minimum) version required.

type Ruleset

type Ruleset struct {
	// The LUCI Project.
	Project string
	// ActiveRulesSorted is the set of active failure association rules
	// (should be used by LUCI Analysis for matching), sorted in descending
	// PredicateLastUpdated time order.
	ActiveRulesSorted []*CachedRule
	// ActiveRulesByID stores active failure association
	// rules by their Rule ID.
	ActiveRulesByID map[string]*CachedRule
	// Version versions the contents of the Ruleset. These timestamps only
	// change if a rule is modified.
	Version rules.Version
	// LastRefresh contains the monotonic clock reading when the last ruleset
	// refresh was initiated. The refresh is guaranteed to contain all rules
	// changes made prior to this timestamp.
	LastRefresh time.Time
}

Ruleset represents a version of the set of failure association rules in use by a LUCI Project. It should be treated as immutable, and therefore safe to share across multiple threads.

func NewRuleset

func NewRuleset(project string, activeRules []*CachedRule, version rules.Version, lastRefresh time.Time) *Ruleset

NewRuleset creates a new ruleset with the given project, active rules, rules last updated and last refresh time.

func (*Ruleset) ActiveRulesWithPredicateUpdatedSince

func (r *Ruleset) ActiveRulesWithPredicateUpdatedSince(t time.Time) []*CachedRule

ActiveRulesWithPredicateUpdatedSince returns the set of rules that are active and whose predicates have been updated since (but not including) the given time. Rules which have been made inactive since the given time will NOT be returned. To check if a previous rule has been made inactive, consider using IsRuleActive instead. The returned slice must not be mutated.

func (*Ruleset) IsRuleActive

func (r *Ruleset) IsRuleActive(ruleID string) bool

Returns whether the given ruleID is an active rule.

Jump to

Keyboard shortcuts

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