rule

package
v0.0.0-...-65e2f22 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHandler

func MakeHandler(svc Service, opts ...kithttp.ServerOption) http.Handler

MakeHandler sets up an http.Handler with all public API endpoints mounted.

Types

type Bucket

type Bucket struct {
	Name       string
	Parameters Parameters
	Percentage int
}

Bucket is a distinct set of parameters that can be used to control segregation by percentage split. Rules which are not of kind experiment will only have one bucket.

type Comparator

type Comparator int8

Comparator defines the type of comparison for a Criterion.

const (
	ComparatorGT Comparator = iota
	ComparatorEQ
	ComparatorNQ
	ComparatorIN
)

Comparators.

func (Comparator) String

func (c Comparator) String() string

type Context

type Context struct {
	User   ContextUser
	Locale ContextLocale
}

Context carries information for rule decisions to match criteria.

type ContextLocale

type ContextLocale struct {
	Locale language.Tag
}

ContextLocale bundles locale information for rule criteria to match.

type ContextUser

type ContextUser struct {
	Age          uint8
	ID           string
	Registered   time.Time
	Subscription int
}

ContextUser bundles user information for rule criteria to match.

type Criteria

type Criteria []Criterion

Criteria is a collection of Criterion.

type Criterion

type Criterion struct {
	Comparator Comparator
	Key        CriterionKey
	Value      interface{}
	Path       string
}

Criterion is a single decision which can be evaluated to decide if a Rule should be applied.

func (Criterion) MarshalJSON

func (c Criterion) MarshalJSON() ([]byte, error)

MarshalJSON to satisfy json.Marshaler.

func (*Criterion) UnmarshalJSON

func (c *Criterion) UnmarshalJSON(raw []byte) error

UnmarshalJSON to satisfy json.Unmarshaler.

type CriterionKey

type CriterionKey int

CriterionKey is the set of possible input to match on.

const (
	DeviceLocationLocale CriterionKey = iota + 101
	DeviceLocationOffset
	DeviceOSPlatform
	DeviceOSVersion
)

Device context keys.

const (
	MetadataBool CriterionKey = iota + 201
	MetadataNumber
	MetadataString
)

Metadata context keys.

const (
	UserAge CriterionKey = iota + 301
	UserRegistered
	UserID
	UserSubscription
)

User context keys.

const (
	AppVersion CriterionKey = iota + 1
)

App context keys.

const (
	ValidDate CriterionKey = iota + 401
)

Date comparison key

func (CriterionKey) String

func (k CriterionKey) String() string

type Decisions

type Decisions map[string][]int

Decisions reflects a matrix of rules applied to a config and if present the results of dice rolls for percenatage based decisions.

type Kind

type Kind uint8

Kind defines the type of rule.

const (
	KindOverride Kind = iota + 1
	KindExperiment
	KindRollout
)

Supported kinds of rules.

type List

type List []Rule

List is a collection of Rule.

type PGRepo

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

PGRepo is a Postgres backed Repo implementation.

func (*PGRepo) Create

func (r *PGRepo) Create(input Rule) (Rule, error)

Create stores a new rule with the given input.

func (*PGRepo) GetByID

func (r *PGRepo) GetByID(id string) (Rule, error)

GetByID returns the rule for the given id.

func (*PGRepo) ListActive

func (r *PGRepo) ListActive(configID string, now time.Time) ([]Rule, error)

ListActive returns all active rules.

func (*PGRepo) ListAll

func (r *PGRepo) ListAll() ([]Rule, error)

ListAll returns all rules.

func (*PGRepo) Setup

func (r *PGRepo) Setup() error

Setup prepares the database by setting up schemas and tables.

func (*PGRepo) Teardown

func (r *PGRepo) Teardown() error

Teardown cascadingly removes all database dependencies.

func (*PGRepo) UpdateWith

func (r *PGRepo) UpdateWith(input Rule) (Rule, error)

UpdateWith takes the input and overrides the rule stored for the id of the input.

type PGRepoOption

type PGRepoOption func(*PGRepo)

PGRepoOption sets an optional parameter on the repo.

func PGRepoSchema

func PGRepoSchema(schema string) PGRepoOption

PGRepoSchema sets the namespacing of the Postgres tables to a non-default schema.

type Parameters

type Parameters map[string]interface{}

Parameters is the set of keys and their new values that an applied rule sets.

type Repo

type Repo interface {
	Create(input Rule) (Rule, error)
	GetByID(string) (Rule, error)
	UpdateWith(input Rule) (Rule, error)
	ListAll() ([]Rule, error)
	ListActive(configID string, now time.Time) ([]Rule, error)
	// contains filtered or unexported methods
}

Repo provides access to rules.

func NewPostgresRepo

func NewPostgresRepo(db *sqlx.DB, options ...PGRepoOption) Repo

NewPostgresRepo returns a Postgres backed Repo implementation.

type RepoMiddleware

type RepoMiddleware func(Repo) Repo

RepoMiddleware is a chainable behaviour modifier for Repo.

func NewRuleRepoInstrumentMiddleware

func NewRuleRepoInstrumentMiddleware(
	opObserve instrument.ObserveRepoFunc,
	store string,
) RepoMiddleware

NewRuleRepoInstrumentMiddleware wraps the next Repo and adds Prometheus instrumentation capabilities.

func NewRuleRepoLogMiddleware

func NewRuleRepoLogMiddleware(logger log.Logger, store string) RepoMiddleware

NewRuleRepoLogMiddleware wraps the next Repo with logging capabilities.

type ResponseParameter

type ResponseParameter struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
}

ResponseParameter used to represent a parameter on the wire.

func (ResponseParameter) MarshalJSON

func (r ResponseParameter) MarshalJSON() ([]byte, error)

MarshalJSON to satisfy json.Marshaler and include the value type of the parameter for clients to make easy decisions when materialising it.

type ResponseParameters

type ResponseParameters []ResponseParameter

ResponseParameters is a collection of ResponseParameter.

func (ResponseParameters) Len

func (r ResponseParameters) Len() int

func (ResponseParameters) Less

func (r ResponseParameters) Less(i, j int) bool

func (ResponseParameters) Swap

func (r ResponseParameters) Swap(i, j int)

type Rule

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

Rule facilitates the overide of base configs with consumer provided parameters.

func New

func New(
	id, configID, name, description string,
	kind Kind,
	active bool,
	criteria Criteria,
	buckets []Bucket,
	rollout *uint8,
) (Rule, error)

New returns a valid rule.

func (Rule) Run

func (r Rule) Run(input Parameters, ctx Context, decisions []int, randInt generate.RandPercentageFunc) (Parameters, []int, error)

Run given an input params and context will try to match based on the rules Criteria and if matched overrides the input params with its own.

type Service

type Service interface {
	Activate(id string) error
	Deactivate(id string) error
	GetByID(id string) (Rule, error)
	List() (List, error)
	UpdateRollout(id string, rollout uint8) error
}

Service for Rule interactions.

func NewService

func NewService(repo Repo) Service

NewService for Rule interactions.

Jump to

Keyboard shortcuts

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