delivery

package
v0.0.0-...-944c6a5 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const NoMaxRequestInsertions = 0

NoMaxRequestInsertions means we don't trim the number of request insertions when cloning delivery requests.

Variables

This section is empty.

Functions

func NewPaging

func NewPaging(size, offset int32) *delivery.Paging

NewPaging creats a paging instance with start and offset since proto is overly complicated.

Types

type APIFactory

type APIFactory interface {
	CreateSDKDelivery() DeliveryAPI
	CreateDeliveryAPI(endpoint, apiKey string, timeoutMillis int64, maxRequestInsertions int, acceptGzip, warmup bool) DeliveryAPI
	CreateMetricsAPI(endpoint, apiKey string, timeoutMillis int64) MetricsAPI
}

APIFactory is a factory interface for creating API clients.

type ApplyTreatmentChecker

type ApplyTreatmentChecker interface {
	ShouldApplyTreatment(cohortMembership *event.CohortMembership) bool
}

ApplyTreatmentChecker provides a method to determine whether treatment should be applied.

type DefaultAPIFactory

type DefaultAPIFactory struct{}

DefaultAPIFactory is the default implementation of ApiFactory.

func (*DefaultAPIFactory) CreateDeliveryAPI

func (f *DefaultAPIFactory) CreateDeliveryAPI(
	endpoint,
	apiKey string,
	timeoutMillis int64,
	maxRequestInsertions int,
	acceptGzip,
	warmup bool) DeliveryAPI

CreateDeliveryAPI creates an API delivery instance.

func (*DefaultAPIFactory) CreateMetricsAPI

func (f *DefaultAPIFactory) CreateMetricsAPI(endpoint, apiKey string, timeoutMillis int64) MetricsAPI

CreateMetricsAPI creates an API metrics instance.

func (*DefaultAPIFactory) CreateSDKDelivery

func (f *DefaultAPIFactory) CreateSDKDelivery() DeliveryAPI

CreateSDKDelivery creates an SDK delivery instance.

type DefaultDeliveryRequestValidator

type DefaultDeliveryRequestValidator struct{}

DefaultDeliveryRequestValidator implements the default delivery request validation logic.

func (*DefaultDeliveryRequestValidator) Validate

func (v *DefaultDeliveryRequestValidator) Validate(request *DeliveryRequest) []string

Validate performs validation on the DeliveryRequest and returns any validation errors.

type DefaultSampler

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

DefaultSampler is a basic implementation of a random sampler.

func NewDefaultSampler

func NewDefaultSampler() *DefaultSampler

NewDefaultSampler creates a new instance of SamplerImpl.

func (*DefaultSampler) SampleRandom

func (s *DefaultSampler) SampleRandom(threshold float32) bool

SampleRandom samples random values based on the given threshold.

type DeliveryAPI

type DeliveryAPI interface {
	RunDelivery(deliveryRequest *DeliveryRequest) (*delivery.Response, error)
}

DeliveryAPI runs the main delivery workflow.

type DeliveryPlan

type DeliveryPlan struct {
	ClientRequestID string
	UseAPIResponse  bool
}

DeliveryPlan represents a plan object that indicates how to execute delivery.

func NewDeliveryPlan

func NewDeliveryPlan(clientRequestID string, useAPIResponse bool) *DeliveryPlan

NewDeliveryPlan is a factory method for DeliveryPlan.

type DeliveryRequest

type DeliveryRequest struct {
	// Request is the underlying request for ranked content.
	Request *delivery.Request

	// OnlyLog indicates whether only logs should be sent to Metrics API.
	OnlyLog bool

	// RetrievalInsertionOffset is the start index in the request insertions in the list of ALL insertions.
	RetrievalInsertionOffset int

	// Experiment is the experiment that the user is in, may be nil, which means apply the treatment.
	Experiment *event.CohortMembership
	// contains filtered or unexported fields
}

DeliveryRequest represents the input into delivery.

func NewDeliveryRequest

func NewDeliveryRequest(
	req *delivery.Request,
	experiment *event.CohortMembership,
	onlyLog bool,
	retrievalInsertionOffset int,
	validator DeliveryRequestValidator) *DeliveryRequest

NewDeliveryRequest is a factory method for DeliveryRequest.

func (*DeliveryRequest) Clone

func (d *DeliveryRequest) Clone(maxRequestInsertions int) *DeliveryRequest

Clone creates a copy of the DeliveryRequest, optionally trimming to maximum request insertions.

func (*DeliveryRequest) Validate

func (d *DeliveryRequest) Validate() []string

Validate checks the state of the DeliveryRequest and returns any validation errors.

type DeliveryRequestValidator

type DeliveryRequestValidator interface {
	// Validate checks the state of the delivery request and collects/returns any validation errors as strings.
	Validate(request *DeliveryRequest) []string
}

DeliveryRequestValidator performs validation on delivery requests during a deliver call when performChecks is true in the client.

type DeliveryResponse

type DeliveryResponse struct {
	// The response from Delivery.
	Response *delivery.Response

	// ClientRequestID is for tracking purposes, auto-generated if not supplied on the request.
	ClientRequestID string

	// ExecutionServer indicates if delivery happened in the SDK or via Delivery API.
	ExecutionServer delivery.ExecutionServer
}

DeliveryResponse is the output from delivery.

type MetricsAPI

type MetricsAPI interface {
	RunMetricsLogging(logRequest *event.LogRequest) error
}

type PromotedDeliveryAPI

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

PromotedDeliveryAPI is the API client for Promoted.ai's Delivery API.

func NewPromotedDeliveryAPI

func NewPromotedDeliveryAPI(
	endpoint,
	apiKey string,
	timeoutMillis int64,
	maxRequestInsertions int,
	acceptGzip,
	warmup bool) *PromotedDeliveryAPI

NewPromotedDeliveryAPI instantiates a new Delivery API client.

func (*PromotedDeliveryAPI) RunDelivery

func (d *PromotedDeliveryAPI) RunDelivery(deliveryRequest *DeliveryRequest) (*delivery.Response, error)

RunDelivery performs delivery.

type PromotedDeliveryClient

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

PromotedDeliveryClient is a client for interacting with the Promoted.ai Delivery API.

func (*PromotedDeliveryClient) CallDeliveryAPI

func (client *PromotedDeliveryClient) CallDeliveryAPI(apiResponse *delivery.Response, err error, deliveryRequest *DeliveryRequest) (*delivery.Response, error)

func (*PromotedDeliveryClient) Deliver

func (client *PromotedDeliveryClient) Deliver(deliveryRequest *DeliveryRequest) (*DeliveryResponse, error)

Deliver sends a delivery request and returns the response.

func (*PromotedDeliveryClient) HandleSDKAndLog

func (client *PromotedDeliveryClient) HandleSDKAndLog(deliveryRequest *DeliveryRequest, plan *DeliveryPlan, apiResponse *delivery.Response) (*DeliveryResponse, error)

HandleSDKAndLog handles SDK delivery, logs, and shadow traffic.

func (*PromotedDeliveryClient) Plan

func (client *PromotedDeliveryClient) Plan(onlyLog bool, experiment *event.CohortMembership) *DeliveryPlan

Plan returns a DeliveryPlan that determines SDK execution, always using SDK if we are only logging, and otherwise checking the experiment to decide.

func (*PromotedDeliveryClient) PrepareRequest

func (client *PromotedDeliveryClient) PrepareRequest(deliveryRequest *DeliveryRequest, plan *DeliveryPlan)

PrepareRequest prepares the delivery request using the plan.

type PromotedDeliveryClientBuilder

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

func NewPromotedDeliveryClientBuilder

func NewPromotedDeliveryClientBuilder() *PromotedDeliveryClientBuilder

NewPromotedDeliveryClientBuilder implements a builder interface for PromotedDeliveryClient.

func (*PromotedDeliveryClientBuilder) Build

func (*PromotedDeliveryClientBuilder) WithAPIFactory

func (*PromotedDeliveryClientBuilder) WithAcceptsGzip

func (b *PromotedDeliveryClientBuilder) WithAcceptsGzip(acceptsGzip bool) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithApplyTreatmentChecker

func (b *PromotedDeliveryClientBuilder) WithApplyTreatmentChecker(applyTreatmentChecker ApplyTreatmentChecker) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithBlockingShadowTraffic

func (b *PromotedDeliveryClientBuilder) WithBlockingShadowTraffic(blockingShadowTraffic bool) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithDeliveryAPIKey

func (b *PromotedDeliveryClientBuilder) WithDeliveryAPIKey(deliveryAPIKey string) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithDeliveryEndpoint

func (b *PromotedDeliveryClientBuilder) WithDeliveryEndpoint(deliveryEndpoint string) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithDeliveryTimeoutMillis

func (b *PromotedDeliveryClientBuilder) WithDeliveryTimeoutMillis(deliveryTimeoutMillis int64) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithMaxRequestInsertions

func (b *PromotedDeliveryClientBuilder) WithMaxRequestInsertions(maxRequestInsertions int) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithMetricsAPIKey

func (b *PromotedDeliveryClientBuilder) WithMetricsAPIKey(metricsAPIKey string) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithMetricsEndpoint

func (b *PromotedDeliveryClientBuilder) WithMetricsEndpoint(metricsEndpoint string) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithMetricsTimeoutMillis

func (b *PromotedDeliveryClientBuilder) WithMetricsTimeoutMillis(metricsTimeoutMillis int64) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithPerformChecks

func (b *PromotedDeliveryClientBuilder) WithPerformChecks(performChecks bool) *PromotedDeliveryClientBuilder

func (*PromotedDeliveryClientBuilder) WithSampler

func (*PromotedDeliveryClientBuilder) WithShadowTrafficDeliveryRate

func (b *PromotedDeliveryClientBuilder) WithShadowTrafficDeliveryRate(shadowTrafficDeliveryRate float32) *PromotedDeliveryClientBuilder

type PromotedMetricsAPI

type PromotedMetricsAPI struct {
	// Endpoint is the metrics API endpoint.
	Endpoint string

	// APIKey needed to access the metrics endpoint.
	APIKey string

	// HTTPClient used for making RPCs.
	HTTPClient *http.Client

	// TimeoutDuration is used for the http client as well as the overall metrics processing.
	TimeoutDuration time.Duration
}

PromotedMetricsAPI is an API client for Promoted.ai's Metrics API.

func NewPromotedMetricsAPI

func NewPromotedMetricsAPI(endpoint, apiKey string, timeoutMillis int64) *PromotedMetricsAPI

NewPromotedMetricsAPI instantiates a new Metrics API client.

func (*PromotedMetricsAPI) RunMetricsLogging

func (m *PromotedMetricsAPI) RunMetricsLogging(logRequest *event.LogRequest) error

RunMetricsLogging performs metrics logging.

type SDKDelivery

type SDKDelivery struct{}

SDKDelivery implements SDK-side delivery.

func NewSDKDelivery

func NewSDKDelivery() *SDKDelivery

NewSDKDelivery is a factory method for SDKDelivery.

func (*SDKDelivery) RunDelivery

func (sdk *SDKDelivery) RunDelivery(deliveryRequest *DeliveryRequest) (*delivery.Response, error)

RunDelivery performs delivery.

type Sampler

type Sampler interface {
	SampleRandom(threshold float32) bool
}

type TwoArmExperiment

type TwoArmExperiment struct {
	// Name of cohort.
	CohortID string

	// Hash of cohort ID.
	CohortIDHash int

	// Number of the numControlBuckets that are active.
	NumActiveControlBuckets int

	// Number of control buckets.
	NumControlBuckets int

	// Number of the numTreatmentBuckets that are active.
	NumActiveTreatmentBuckets int

	// Number of treatment buckets.
	NumTreatmentBuckets int

	// Total number of buckets.
	NumTotalBuckets int
}

TwoArmExperiment represents a two arm Experiment configuration.

func Create5050TwoArmExperimentConfig

func Create5050TwoArmExperimentConfig(cohortID string, controlPercent, treatmentPercent int) (*TwoArmExperiment, error)

Create5050TwoArmExperimentConfig is a factory method for a 50/50 experiment.

func NewTwoArmExperiment

func NewTwoArmExperiment(cohortID string, numActiveControlBuckets, numControlBuckets, numActiveTreatmentBuckets, numTreatmentBuckets int) (*TwoArmExperiment, error)

NewTwoArmExperiment creates a two-arm experiment config with the given parameters.

func (*TwoArmExperiment) CheckMembership

func (e *TwoArmExperiment) CheckMembership(userID string) *event.CohortMembership

CheckMembership evaluates the experiment membership for a given user.

Jump to

Keyboard shortcuts

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