github.com/prebid/prebid-server/v2@v2.18.0/hooks/hookexecution/outcome.go (about)

     1  package hookexecution
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/prebid/prebid-server/v2/hooks/hookanalytics"
     7  )
     8  
     9  // Status indicates the result of hook execution.
    10  type Status string
    11  
    12  const (
    13  	StatusSuccess          Status = "success"           // successful hook execution
    14  	StatusTimeout          Status = "timeout"           // hook was not completed in the allotted time
    15  	StatusFailure          Status = "failure"           // expected module-side failure occurred during hook execution
    16  	StatusExecutionFailure Status = "execution_failure" // unexpected failure occurred during hook execution
    17  )
    18  
    19  // Action indicates the type of taken behaviour after the successful hook execution.
    20  type Action string
    21  
    22  const (
    23  	ActionUpdate Action = "update"    // the hook returned mutations that were successfully applied
    24  	ActionReject Action = "reject"    // the hook decided to reject the stage
    25  	ActionNone   Action = "no_action" // the hook does not want to take any action
    26  )
    27  
    28  // Messages in format: {"module": {"hook": ["msg1", "msg2"]}}
    29  type Messages map[string]map[string][]string
    30  
    31  // ModulesOutcome represents result of hooks execution
    32  // ready to be added to BidResponse.
    33  //
    34  // Errors and Warnings hold the error and warning
    35  // messages returned from executing individual hooks.
    36  type ModulesOutcome struct {
    37  	Errors   Messages      `json:"errors,omitempty"`
    38  	Warnings Messages      `json:"warnings,omitempty"`
    39  	Trace    *TraceOutcome `json:"trace,omitempty"`
    40  }
    41  
    42  // TraceOutcome holds the result of executing hooks at all stages.
    43  type TraceOutcome struct {
    44  	// ExecutionTime is the sum of ExecutionTime of all stages.
    45  	ExecutionTime
    46  	Stages []Stage `json:"stages"`
    47  }
    48  
    49  // Stage holds the result of executing hooks at specific stage.
    50  // May contain multiple StageOutcome results for stages executed
    51  // multiple times (ex. for each bidder-request/response stages).
    52  type Stage struct {
    53  	// ExecutionTime is set to the longest ExecutionTime of its children.
    54  	ExecutionTime
    55  	Stage    string         `json:"stage"`
    56  	Outcomes []StageOutcome `json:"outcomes"`
    57  }
    58  
    59  // StageOutcome represents the result of executing specific stage.
    60  type StageOutcome struct {
    61  	// ExecutionTime is the sum of ExecutionTime of all its groups
    62  	ExecutionTime
    63  	// An Entity specifies the type of object that was processed during the execution of the stage.
    64  	Entity entity         `json:"entity"`
    65  	Groups []GroupOutcome `json:"groups"`
    66  	Stage  string         `json:"-"`
    67  }
    68  
    69  // GroupOutcome represents the result of executing specific group of hooks.
    70  type GroupOutcome struct {
    71  	// ExecutionTime is set to the longest ExecutionTime of its children.
    72  	ExecutionTime
    73  	InvocationResults []HookOutcome `json:"invocation_results"`
    74  }
    75  
    76  // HookOutcome represents the result of executing specific hook.
    77  type HookOutcome struct {
    78  	// ExecutionTime is the execution time of a specific hook without applying its result.
    79  	ExecutionTime
    80  	AnalyticsTags hookanalytics.Analytics `json:"analytics_tags"`
    81  	HookID        HookID                  `json:"hook_id"`
    82  	Status        Status                  `json:"status"`
    83  	Action        Action                  `json:"action"`
    84  	Message       string                  `json:"message"` // arbitrary string value returned from hook execution
    85  	DebugMessages []string                `json:"debug_messages,omitempty"`
    86  	Errors        []string                `json:"-"`
    87  	Warnings      []string                `json:"-"`
    88  }
    89  
    90  // HookID points to the specific hook defined by the hook execution plan.
    91  type HookID struct {
    92  	ModuleCode   string `json:"module_code"`
    93  	HookImplCode string `json:"hook_impl_code"`
    94  }
    95  
    96  type ExecutionTime struct {
    97  	ExecutionTimeMillis time.Duration `json:"execution_time_millis,omitempty"`
    98  }