hookexecution

package
v0.275.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointAuction = "/openrtb2/auction"
	EndpointAmp     = "/openrtb2/amp"
)

Variables

This section is empty.

Functions

func AssertEqualModulesData added in v0.238.0

func AssertEqualModulesData(t *testing.T, expectedData, actualData json.RawMessage)

AssertEqualModulesData is the test helper function which asserts that expected modules data fully corresponds the actual modules data. Dynamic data for execution time is calculated from actual modules data.

func EnrichExtBidResponse added in v0.238.0

func EnrichExtBidResponse(
	ext json.RawMessage,
	stageOutcomes []StageOutcome,
	bidRequest *openrtb2.BidRequest,
	account *config.Account,
) (json.RawMessage, []error, error)

EnrichExtBidResponse adds debug and trace information returned from executing hooks to the ext argument. In response the outcome is visible under the key response.ext.prebid.modules.

Debug information is added only if the debug mode is enabled by request and allowed by account (if provided). The details of the trace output depends on the value in the bidRequest.ext.prebid.trace field. Warnings returned if bidRequest contains unexpected types for debug fields controlling debug output.

func GetModulesJSON added in v0.238.0

func GetModulesJSON(
	stageOutcomes []StageOutcome,
	bidRequest *openrtb2.BidRequest,
	account *config.Account,
) (json.RawMessage, []error, error)

GetModulesJSON returns debug and trace information produced from executing hooks. Debug information is returned only if the debug mode is enabled by request and allowed by account (if provided). The details of the trace output depends on the value in the bidRequest.ext.prebid.trace field. Warnings returned if bidRequest contains unexpected types for debug fields controlling debug output.

func NewHookExecutor

func NewHookExecutor(builder hooks.ExecutionPlanBuilder, endpoint string, me metrics.MetricsEngine) *hookExecutor

Types

type Action

type Action string

Action indicates the type of taken behaviour after the successful hook execution.

const (
	ActionUpdate Action = "update"    // the hook returned mutations that were successfully applied
	ActionReject Action = "reject"    // the hook decided to reject the stage
	ActionNone   Action = "no_action" // the hook does not want to take any action
)

type EmptyHookExecutor

type EmptyHookExecutor struct{}

func (EmptyHookExecutor) ExecuteAllProcessedBidResponsesStage added in v0.237.0

func (executor EmptyHookExecutor) ExecuteAllProcessedBidResponsesStage(_ map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid)

func (EmptyHookExecutor) ExecuteAuctionResponseStage added in v0.237.0

func (executor EmptyHookExecutor) ExecuteAuctionResponseStage(_ *openrtb2.BidResponse)

func (EmptyHookExecutor) ExecuteBidderRequestStage added in v0.237.0

func (executor EmptyHookExecutor) ExecuteBidderRequestStage(_ *openrtb2.BidRequest, bidder string) *RejectError

func (EmptyHookExecutor) ExecuteEntrypointStage

func (executor EmptyHookExecutor) ExecuteEntrypointStage(_ *http.Request, body []byte) ([]byte, *RejectError)

func (EmptyHookExecutor) ExecuteProcessedAuctionStage added in v0.237.0

func (executor EmptyHookExecutor) ExecuteProcessedAuctionStage(_ *openrtb_ext.RequestWrapper) error

func (EmptyHookExecutor) ExecuteRawAuctionStage added in v0.236.0

func (executor EmptyHookExecutor) ExecuteRawAuctionStage(body []byte) ([]byte, *RejectError)

func (EmptyHookExecutor) ExecuteRawBidderResponseStage added in v0.237.0

func (executor EmptyHookExecutor) ExecuteRawBidderResponseStage(_ *adapters.BidderResponse, _ string) *RejectError

func (EmptyHookExecutor) GetOutcomes

func (executor EmptyHookExecutor) GetOutcomes() []StageOutcome

func (EmptyHookExecutor) SetAccount

func (executor EmptyHookExecutor) SetAccount(_ *config.Account)

type ExecutionTime

type ExecutionTime struct {
	ExecutionTimeMillis time.Duration `json:"execution_time_millis,omitempty"`
}

type FailureError

type FailureError struct {
	Message string
}

FailureError indicates expected error occurred during hook execution on the module-side. A moduleFailed metric will be sent in such case.

func NewFailure added in v0.238.0

func NewFailure(format string, a ...any) FailureError

func (FailureError) Error

func (e FailureError) Error() string

type GroupOutcome

type GroupOutcome struct {
	// ExecutionTime is set to the longest ExecutionTime of its children.
	ExecutionTime
	InvocationResults []HookOutcome `json:"invocation_results"`
}

GroupOutcome represents the result of executing specific group of hooks.

type HookID

type HookID struct {
	ModuleCode   string `json:"module_code"`
	HookImplCode string `json:"hook_impl_code"`
}

HookID points to the specific hook defined by the hook execution plan.

type HookOutcome

type HookOutcome struct {
	// ExecutionTime is the execution time of a specific hook without applying its result.
	ExecutionTime
	AnalyticsTags hookanalytics.Analytics `json:"analytics_tags"`
	HookID        HookID                  `json:"hook_id"`
	Status        Status                  `json:"status"`
	Action        Action                  `json:"action"`
	Message       string                  `json:"message"` // arbitrary string value returned from hook execution
	DebugMessages []string                `json:"debug_messages,omitempty"`
	Errors        []string                `json:"-"`
	Warnings      []string                `json:"-"`
}

HookOutcome represents the result of executing specific hook.

type HookStageExecutor

type HookStageExecutor interface {
	StageExecutor
	SetAccount(account *config.Account)
	GetOutcomes() []StageOutcome
}

type Messages added in v0.238.0

type Messages map[string]map[string][]string

Messages in format: {"module": {"hook": ["msg1", "msg2"]}}

type ModulesOutcome added in v0.238.0

type ModulesOutcome struct {
	Errors   Messages      `json:"errors,omitempty"`
	Warnings Messages      `json:"warnings,omitempty"`
	Trace    *TraceOutcome `json:"trace,omitempty"`
}

ModulesOutcome represents result of hooks execution ready to be added to BidResponse.

Errors and Warnings hold the error and warning messages returned from executing individual hooks.

type RejectError

type RejectError struct {
	NBR   int
	Hook  HookID
	Stage string
}

RejectError indicates stage rejection requested by specific hook. Implements errortypes.Coder interface for compatibility only, so as not to be recognized as a fatal error

func CastRejectErr

func CastRejectErr(err error) (*RejectError, bool)

func FindFirstRejectOrNil

func FindFirstRejectOrNil(errors []error) *RejectError

func (RejectError) Code

func (e RejectError) Code() int

func (RejectError) Error

func (e RejectError) Error() string

func (RejectError) Severity

func (e RejectError) Severity() errortypes.Severity

type Stage added in v0.238.0

type Stage struct {
	// ExecutionTime is set to the longest ExecutionTime of its children.
	ExecutionTime
	Stage    string         `json:"stage"`
	Outcomes []StageOutcome `json:"outcomes"`
}

Stage holds the result of executing hooks at specific stage. May contain multiple StageOutcome results for stages executed multiple times (ex. for each bidder-request/response stages).

type StageExecutor

type StageExecutor interface {
	ExecuteEntrypointStage(req *http.Request, body []byte) ([]byte, *RejectError)
	ExecuteRawAuctionStage(body []byte) ([]byte, *RejectError)
	ExecuteProcessedAuctionStage(req *openrtb_ext.RequestWrapper) error
	ExecuteBidderRequestStage(req *openrtb2.BidRequest, bidder string) *RejectError
	ExecuteRawBidderResponseStage(response *adapters.BidderResponse, bidder string) *RejectError
	ExecuteAllProcessedBidResponsesStage(adapterBids map[openrtb_ext.BidderName]*entities.PbsOrtbSeatBid)
	ExecuteAuctionResponseStage(response *openrtb2.BidResponse)
}

type StageOutcome

type StageOutcome struct {
	// ExecutionTime is the sum of ExecutionTime of all its groups
	ExecutionTime
	// An Entity specifies the type of object that was processed during the execution of the stage.
	Entity entity         `json:"entity"`
	Groups []GroupOutcome `json:"groups"`
	Stage  string         `json:"-"`
}

StageOutcome represents the result of executing specific stage.

type Status

type Status string

Status indicates the result of hook execution.

const (
	StatusSuccess          Status = "success"           // successful hook execution
	StatusTimeout          Status = "timeout"           // hook was not completed in the allotted time
	StatusFailure          Status = "failure"           // expected module-side failure occurred during hook execution
	StatusExecutionFailure Status = "execution_failure" // unexpected failure occurred during hook execution
)

type TimeoutError

type TimeoutError struct{}

TimeoutError indicates exceeding of the max execution time allotted for hook.

func (TimeoutError) Error

func (e TimeoutError) Error() string

type TraceOutcome added in v0.238.0

type TraceOutcome struct {
	// ExecutionTime is the sum of ExecutionTime of all stages.
	ExecutionTime
	Stages []Stage `json:"stages"`
}

TraceOutcome holds the result of executing hooks at all stages.

Jump to

Keyboard shortcuts

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