rules

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Index

Constants

View Source
const (
	QRContinue = Action(iota)
	QRFail
	QRFailRetry
	QRBuffer
)

These are actions.

View Source
const (
	QRNoOp = Operator(iota)
	QREqual
	QRNotEqual
	QRLessThan
	QRGreaterEqual
	QRGreaterThan
	QRLessEqual
	QRMatch
	QRNoMatch
	QRNumOp
)

These are comparison operators.

View Source
const (
	QROK = iota
	QRMismatch
	QROutOfRange
)

These are return states.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int

Action specifies the list of actions to perform when a Rule is triggered.

func (Action) MarshalJSON

func (act Action) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON.

type BindVarCond

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

BindVarCond represents a bind var condition.

func (*BindVarCond) CachedSize added in v0.10.0

func (cached *BindVarCond) CachedSize(alloc bool) int64

func (BindVarCond) MarshalJSON

func (bvc BindVarCond) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON.

type Map

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

Map is the maintainer of Rules from multiple sources

func NewMap

func NewMap() *Map

NewMap returns an empty Map object.

func (*Map) FilterByPlan

func (qri *Map) FilterByPlan(query string, planid planbuilder.PlanType, tableNames ...string) (newqrs *Rules)

FilterByPlan creates a new Rules by prefiltering on all query rules that are contained in internal Rules structures, in other words, query rules from all predefined sources will be applied.

func (*Map) Get

func (qri *Map) Get(ruleSource string) (*Rules, error)

Get returns the corresponding Rules as designated by ruleSource parameter.

func (*Map) MarshalJSON

func (qri *Map) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON.

func (*Map) RegisterSource

func (qri *Map) RegisterSource(ruleSource string)

RegisterSource registers a query rule source name with Map.

func (*Map) SetRules

func (qri *Map) SetRules(ruleSource string, newRules *Rules) error

SetRules takes an external Rules structure and overwrite one of the internal Rules as designated by ruleSource parameter.

func (*Map) UnRegisterSource

func (qri *Map) UnRegisterSource(ruleSource string)

UnRegisterSource removes a registered query rule source name.

type Operator

type Operator int

Operator represents the list of operators.

func MapStrOperator

func MapStrOperator(strop string) (op Operator, err error)

MapStrOperator maps a string representation to an Operator.

func (Operator) MarshalJSON

func (op Operator) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON.

type Rule

type Rule struct {
	Description string
	Name        string
	// contains filtered or unexported fields
}

Rule represents one rule (conditions-action). Name is meant to uniquely identify a rule. Description is a human readable comment that describes the rule. For a Rule to fire, all conditions of the Rule have to match. For example, an empty Rule will match all requests. Every Rule has an associated Action. If all the conditions of the Rule are met, then the Action is triggerred.

func BuildQueryRule

func BuildQueryRule(ruleInfo map[string]any) (qr *Rule, err error)

BuildQueryRule builds a query rule from a ruleInfo.

func NewBufferedTableQueryRule added in v0.14.0

func NewBufferedTableQueryRule(cancelCtx context.Context, tableName string, bufferTimeout time.Duration, description string) (qr *Rule)

NewBufferedTableQueryRule creates a new buffer Rule.

func NewQueryRule

func NewQueryRule(description, name string, act Action) (qr *Rule)

NewQueryRule creates a new Rule.

func (*Rule) AddBindVarCond

func (qr *Rule) AddBindVarCond(name string, onAbsent, onMismatch bool, op Operator, value any) error

AddBindVarCond adds a bind variable restriction to the Rule. All bind var conditions have to be satisfied for the Rule to be a match. name represents the name (not regexp) of the bind variable. onAbsent specifies the value of the condition if the bind variable is absent. onMismatch specifies the value of the condition if there's a type mismatch on the condition. For inequalities, the bindvar is the left operand and the value in the condition is the right operand: bindVar Operator value. Value & operator rules Type Operators Bindvar nil "" any type uint64 ==, !=, <, >=, >, <= whole numbers int64 ==, !=, <, >=, >, <= whole numbers string ==, !=, <, >=, >, <=, MATCH, NOMATCH []byte, string whole numbers can be: int, int8, int16, int32, int64, uint64

func (*Rule) AddPlanCond

func (qr *Rule) AddPlanCond(planType planbuilder.PlanType)

AddPlanCond adds to the list of plans that can be matched for the rule to fire. This function acts as an OR: Any plan id match is considered a match.

func (*Rule) AddTableCond

func (qr *Rule) AddTableCond(tableName string)

AddTableCond adds to the list of tableNames that can be matched for the rule to fire. This function acts as an OR: Any tableName match is considered a match.

func (*Rule) CachedSize added in v0.10.0

func (cached *Rule) CachedSize(alloc bool) int64

func (*Rule) Copy

func (qr *Rule) Copy() (newqr *Rule)

Copy performs a deep copy of a Rule.

func (*Rule) Equal

func (qr *Rule) Equal(other *Rule) bool

Equal returns true if other is equal to this Rule, otherwise false.

func (*Rule) FilterByPlan

func (qr *Rule) FilterByPlan(query string, planid planbuilder.PlanType, tableNames []string) (newqr *Rule)

FilterByPlan returns a new Rule if the query and planid match. The new Rule will contain all the original constraints other than the plan and query. If the plan and query don't match the Rule, then it returns nil.

func (*Rule) GetAction

func (qr *Rule) GetAction(
	ip,
	user string,
	bindVars map[string]*querypb.BindVariable,
	marginComments sqlparser.MarginComments,
) Action

GetAction returns the action for a single rule.

func (*Rule) MarshalJSON

func (qr *Rule) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON.

func (*Rule) SetIPCond

func (qr *Rule) SetIPCond(pattern string) (err error)

SetIPCond adds a regular expression condition for the client IP. It has to be a full match (not substring).

func (*Rule) SetLeadingCommentCond added in v0.12.0

func (qr *Rule) SetLeadingCommentCond(pattern string) (err error)

SetLeadingCommentCond adds a regular expression condition for a leading query comment.

func (*Rule) SetQueryCond

func (qr *Rule) SetQueryCond(pattern string) (err error)

SetQueryCond adds a regular expression condition for the query.

func (*Rule) SetTrailingCommentCond added in v0.12.0

func (qr *Rule) SetTrailingCommentCond(pattern string) (err error)

SetTrailingCommentCond adds a regular expression condition for a trailing query comment.

func (*Rule) SetUserCond

func (qr *Rule) SetUserCond(pattern string) (err error)

SetUserCond adds a regular expression condition for the user name used by the client.

type Rules

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

Rules is used to store and execute rules for the tabletserver.

func New

func New() *Rules

New creates a new Rules.

func (*Rules) Add

func (qrs *Rules) Add(qr *Rule)

Add adds a Rule to Rules. It does not check for duplicates.

func (*Rules) Append

func (qrs *Rules) Append(otherqrs *Rules)

Append merges the rules from another Rules into the receiver

func (*Rules) CachedSize added in v0.10.0

func (cached *Rules) CachedSize(alloc bool) int64

func (*Rules) Copy

func (qrs *Rules) Copy() (newqrs *Rules)

Copy performs a deep copy of Rules. A nil input produces a nil output.

func (*Rules) CopyUnderlying added in v0.10.0

func (qrs *Rules) CopyUnderlying() []*Rule

CopyUnderlying makes a copy of the underlying rule array and returns it to the caller.

func (*Rules) Delete

func (qrs *Rules) Delete(name string) (qr *Rule)

Delete deletes a Rule by name and returns the rule that was deleted. It returns nil if the rule was not found.

func (*Rules) Equal

func (qrs *Rules) Equal(other *Rules) bool

Equal returns true if other is equal to this object, otherwise false.

func (*Rules) FilterByPlan

func (qrs *Rules) FilterByPlan(query string, planid planbuilder.PlanType, tableNames ...string) (newqrs *Rules)

FilterByPlan creates a new Rules by prefiltering on the query and planId. This allows us to create query plan specific Rules out of the original Rules. In the new rules, query, plans and tableNames predicates are empty.

func (*Rules) Find

func (qrs *Rules) Find(name string) (qr *Rule)

Find finds the first occurrence of a Rule by matching the Name field. It returns nil if the rule was not found.

func (*Rules) GetAction

func (qrs *Rules) GetAction(
	ip,
	user string,
	bindVars map[string]*querypb.BindVariable,
	marginComments sqlparser.MarginComments,
) (
	action Action,
	cancelCtx context.Context,
	timeout time.Duration,
	desc string)

GetAction runs the input against the rules engine and returns the action to be performed.

func (*Rules) MarshalJSON

func (qrs *Rules) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON.

func (*Rules) UnmarshalJSON

func (qrs *Rules) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON unmarshals Rules.

Jump to

Keyboard shortcuts

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