Documentation ¶
Index ¶
- Variables
- func AddWebhook(ctx context.Context, w *Webhook) error
- func Deinit()
- func DeleteWebhook(ctx context.Context, id WebhookID) error
- func Init()
- func ReportExperimentStateChanged(ctx context.Context, e model.Experiment, activeConfig expconf.ExperimentConfig) error
- func ScanLogs(ctx context.Context, logs []*model.TaskLog, workspaceID model.AccessScopeID, ...) error
- func SetDefault(w *WebhookManager)
- func UpdateWebhook(ctx context.Context, id int32, p *webhookv1.PatchWebhook) error
- type Condition
- type CustomTriggerData
- type Event
- type EventData
- type EventPayload
- type ExperimentPayload
- type SlackAttachment
- type SlackBlock
- type SlackField
- type SlackMessageBody
- type TaskLogPayload
- type Trigger
- type TriggerID
- type TriggerType
- type Triggers
- type Webhook
- type WebhookAuthZ
- type WebhookAuthZBasic
- type WebhookAuthZPermissive
- type WebhookAuthZRBAC
- type WebhookEventID
- type WebhookID
- type WebhookManager
- type WebhookMode
- type WebhookType
- type Webhooks
- type WebhooksAPIServer
- func (a *WebhooksAPIServer) DeleteWebhook(ctx context.Context, req *apiv1.DeleteWebhookRequest) (*apiv1.DeleteWebhookResponse, error)
- func (a *WebhooksAPIServer) GetWebhooks(ctx context.Context, req *apiv1.GetWebhooksRequest) (*apiv1.GetWebhooksResponse, error)
- func (a *WebhooksAPIServer) PatchWebhook(ctx context.Context, req *apiv1.PatchWebhookRequest) (*apiv1.PatchWebhookResponse, error)
- func (a *WebhooksAPIServer) PostWebhook(ctx context.Context, req *apiv1.PostWebhookRequest) (*apiv1.PostWebhookResponse, error)
- func (a *WebhooksAPIServer) PostWebhookEventData(ctx context.Context, req *apiv1.PostWebhookEventDataRequest) (*apiv1.PostWebhookEventDataResponse, error)
- func (a *WebhooksAPIServer) TestWebhook(ctx context.Context, req *apiv1.TestWebhookRequest) (*apiv1.TestWebhookResponse, error)
Constants ¶
This section is empty.
Variables ¶
var AuthZProvider authz.AuthZProviderType[WebhookAuthZ]
AuthZProvider is the authz registry for experiments.
Functions ¶
func AddWebhook ¶
AddWebhook adds a Webhook and its Triggers to the DB.
func DeleteWebhook ¶
DeleteWebhook deletes a Webhook and its Triggers from the DB.
func ReportExperimentStateChanged ¶
func ReportExperimentStateChanged( ctx context.Context, e model.Experiment, activeConfig expconf.ExperimentConfig, ) error
ReportExperimentStateChanged adds webhook events to the queue. This function assumes ID presents in e. TODO(DET-8577): Remove unnecessary active config usage (remove the activeConfig parameter).
func ScanLogs ¶
func ScanLogs(ctx context.Context, logs []*model.TaskLog, workspaceID model.AccessScopeID, expID *int) error
ScanLogs sends webhooks for task logs. This should be called wherever we add task logs.
func SetDefault ¶
func SetDefault(w *WebhookManager)
SetDefault sets the default webhook manager singleton.
func UpdateWebhook ¶
UpdateWebhook updates a Webhook in the DB.
Types ¶
type Condition ¶
type Condition struct { State model.State `json:"state,omitempty"` Regex string `json:"regex,omitempty"` }
Condition represents a trigger condition.
type CustomTriggerData ¶
type CustomTriggerData struct { Title string `json:"title"` Description string `json:"description"` Level string `json:"level"` }
CustomTriggerData is the data for custom trigger.
type Event ¶
type Event struct { bun.BaseModel `bun:"table:webhook_events_queue"` ID WebhookEventID `bun:"id,pk,autoincrement"` URL string `bun:"url,notnull"` Payload []byte `bun:"payload,notnull"` }
Event corresponds to a row in the "webhook_events" DB table.
type EventData ¶
type EventData struct { TestData *string `json:"data,omitempty"` Experiment *ExperimentPayload `json:"experiment,omitempty"` TaskLog *TaskLogPayload `json:"task_log,omitempty"` CustomData *CustomTriggerData `json:"custom_data,omitempty"` }
EventData represents the event_data for a webhook event.
type EventPayload ¶
type EventPayload struct { ID uuid.UUID `json:"event_id"` Type TriggerType `json:"event_type"` Timestamp int64 `json:"timestamp"` Condition Condition `json:"condition"` Data EventData `json:"event_data"` }
EventPayload respresents a webhook event.
type ExperimentPayload ¶
type ExperimentPayload struct { ID int `json:"id"` State model.State `json:"state"` Name expconf.Name `json:"name"` Duration int `json:"duration"` ResourcePool string `json:"resource_pool"` SlotsPerTrial int `json:"slots_per_trial"` WorkspaceName string `json:"workspace"` ProjectName string `json:"project"` TrialID int `json:"trial_id,omitempty"` }
ExperimentPayload is the webhook request representation of an experiment.
type SlackAttachment ¶
type SlackAttachment struct { Color string `json:"color,omitempty"` Blocks []SlackBlock `json:"blocks,omitempty"` }
SlackAttachment corresponds to an Attachment Slack Block element.
type SlackBlock ¶
type SlackBlock struct { Type string `json:"type,omitempty"` Text SlackField `json:"text,omitempty"` Fields *[]SlackField `json:"fields,omitempty"` }
SlackBlock corresponds to a Slack Block element.
type SlackField ¶
SlackField corresponds to a field in a Slack Block element.
type SlackMessageBody ¶
type SlackMessageBody struct { Blocks []SlackBlock `json:"blocks,omitempty"` Attachments *[]SlackAttachment `json:"attachments,omitempty"` }
SlackMessageBody corresponds to an entire message as a Slack Block.
type TaskLogPayload ¶
type TaskLogPayload struct { TaskID model.TaskID `json:"task_id"` NodeName string `json:"node_name"` TriggeringLog string `json:"triggering_log"` }
TaskLogPayload is the webhook request representation of a trigger of a task log.
type Trigger ¶
type Trigger struct { bun.BaseModel `bun:"table:webhook_triggers"` ID TriggerID `bun:"id,pk,autoincrement"` TriggerType TriggerType `bun:"trigger_type,notnull"` Condition map[string]interface{} `bun:"condition,notnull"` WebhookID WebhookID `bun:"webhook_id,notnull"` Webhook *Webhook `bun:"rel:belongs-to,join:webhook_id=id"` }
Trigger corresponds to a row in the "webhook_triggers" DB table.
func TriggerFromProto ¶
TriggerFromProto returns a Trigger from a proto definition.
type TriggerType ¶
type TriggerType string
TriggerType is type for the TriggerType enum.
const ( // TriggerTypeStateChange represents a change in experiment state. TriggerTypeStateChange TriggerType = "EXPERIMENT_STATE_CHANGE" // TriggerTypeMetricThresholdExceeded represents a threshold for a training metric value. TriggerTypeMetricThresholdExceeded TriggerType = "METRIC_THRESHOLD_EXCEEDED" // TriggerTypeTaskLog represents a trigger for a task logs. TriggerTypeTaskLog TriggerType = "TASK_LOG" // TriggerTypeCustom represents a custom trigger. TriggerTypeCustom TriggerType = "CUSTOM" )
func TriggerTypeFromProto ¶
func TriggerTypeFromProto(t webhookv1.TriggerType) TriggerType
TriggerTypeFromProto returns a TriggerType from a proto.
func (TriggerType) Proto ¶
func (t TriggerType) Proto() webhookv1.TriggerType
Proto returns a proto from a TriggerType.
type Triggers ¶
type Triggers []*Trigger
Triggers is a slice of Trigger objects—primarily useful for its methods.
func TriggersFromProto ¶
TriggersFromProto returns a slice of model Triggers from a proto definition.
type Webhook ¶
type Webhook struct { bun.BaseModel `bun:"table:webhooks"` ID WebhookID `bun:"id,pk,autoincrement"` WebhookType WebhookType `bun:"webhook_type,notnull"` URL string `bun:"url,notnull"` Mode WebhookMode `bun:"mode,notnull"` WorkspaceID *int32 `bun:"workspace_id"` Name string `bun:"name,notnull"` Triggers Triggers `bun:"rel:has-many,join:id=webhook_id"` }
Webhook corresponds to a row in the "webhooks" DB table.
func GetWebhook ¶
GetWebhook returns a single Webhooks from the DB.
func WebhookFromProto ¶
WebhookFromProto returns a model Webhook from a proto definition.
type WebhookAuthZ ¶
type WebhookAuthZ interface { // GET /api/v1/webhooks WebhookAvailableWorkspaces( ctx context.Context, curUser *model.User) (workspaceIDsWithPermsFilter []int32, serverError error) // POST /api/v1/webhooks // DELETE /api/v1/webhooks/:webhook_id // POST /api/v1/webhooks/test/:webhook_id CanEditWebhooks(ctx context.Context, curUser *model.User, workspace *model.Workspace) (serverError error) }
WebhookAuthZ describes authz methods for experiments.
type WebhookAuthZBasic ¶
type WebhookAuthZBasic struct{}
WebhookAuthZBasic is basic OSS controls.
func (*WebhookAuthZBasic) CanEditWebhooks ¶
func (a *WebhookAuthZBasic) CanEditWebhooks( ctx context.Context, curUser *model.User, workspace *model.Workspace, ) (serverError error)
CanEditWebhooks always returns true and a nil error. workspace being nil means the webhook is globally scoped.
func (*WebhookAuthZBasic) WebhookAvailableWorkspaces ¶
func (a *WebhookAuthZBasic) WebhookAvailableWorkspaces( ctx context.Context, curUser *model.User, ) (workspaceIDsWithPermsFilter []int32, serverError error)
WebhookAvailableWorkspaces returns a list of workspaces that user can get webhooks from.
type WebhookAuthZPermissive ¶
type WebhookAuthZPermissive struct{}
WebhookAuthZPermissive is the permission implementation.
func (*WebhookAuthZPermissive) CanEditWebhooks ¶
func (p *WebhookAuthZPermissive) CanEditWebhooks( ctx context.Context, curUser *model.User, workspace *model.Workspace, ) error
CanEditWebhooks calls RBAC authz but enforces basic authz.
func (*WebhookAuthZPermissive) WebhookAvailableWorkspaces ¶
func (p *WebhookAuthZPermissive) WebhookAvailableWorkspaces( ctx context.Context, curUser *model.User, ) (workspaceIDsWithPermsFilter []int32, serverError error)
WebhookAvailableWorkspaces calls RBAC authz but enforces basic authz.
type WebhookAuthZRBAC ¶
type WebhookAuthZRBAC struct{}
WebhookAuthZRBAC is RBAC webhook access controls.
func (*WebhookAuthZRBAC) CanEditWebhooks ¶
func (a *WebhookAuthZRBAC) CanEditWebhooks( ctx context.Context, curUser *model.User, workspace *model.Workspace, ) error
CanEditWebhooks checks if a user can edit webhooks. workspace being nil means the webhook is globally scoped.
func (*WebhookAuthZRBAC) WebhookAvailableWorkspaces ¶
func (a *WebhookAuthZRBAC) WebhookAvailableWorkspaces( ctx context.Context, curUser *model.User, ) (workspaceIDsWithPermsFilter []int32, serverError error)
WebhookAvailableWorkspaces returns a list of workspaces that user can get webhooks from.
type WebhookManager ¶
type WebhookManager struct {
// contains filtered or unexported fields
}
WebhookManager manages webhooks.
type WebhookMode ¶
type WebhookMode string
WebhookMode is mode for the WebhookMode enum.
const ( // WebhookModeWorkspace represents the webhook will be triggered by all experiment in the workspace. WebhookModeWorkspace WebhookMode = "WORKSPACE" // WebhookModeSpecific represents the webhook will only be triggered by experiment with // matching configuration in the same workspace as the web hook. WebhookModeSpecific WebhookMode = "SPECIFIC" )
func WebhookModeFromProto ¶
func WebhookModeFromProto(w webhookv1.WebhookMode) WebhookMode
WebhookModeFromProto returns a WebhookMode from a proto.
func (WebhookMode) Proto ¶
func (w WebhookMode) Proto() webhookv1.WebhookMode
Proto returns a proto from a WebhookMode.
type WebhookType ¶
type WebhookType string
WebhookType is type for the WebhookType enum.
const ( // WebhookTypeDefault represents a default webhook. WebhookTypeDefault WebhookType = "DEFAULT" // WebhookTypeSlack represents a slack webhook. WebhookTypeSlack WebhookType = "SLACK" )
func WebhookTypeFromProto ¶
func WebhookTypeFromProto(w webhookv1.WebhookType) WebhookType
WebhookTypeFromProto returns a WebhookType from a proto.
func (WebhookType) Proto ¶
func (w WebhookType) Proto() webhookv1.WebhookType
Proto returns a proto from a WebhookType.
type WebhooksAPIServer ¶
type WebhooksAPIServer struct{}
WebhooksAPIServer is an embedded api server struct.
func (*WebhooksAPIServer) DeleteWebhook ¶
func (a *WebhooksAPIServer) DeleteWebhook( ctx context.Context, req *apiv1.DeleteWebhookRequest, ) (*apiv1.DeleteWebhookResponse, error)
DeleteWebhook deletes a Webhook.
func (*WebhooksAPIServer) GetWebhooks ¶
func (a *WebhooksAPIServer) GetWebhooks( ctx context.Context, req *apiv1.GetWebhooksRequest, ) (*apiv1.GetWebhooksResponse, error)
GetWebhooks returns all Webhooks.
func (*WebhooksAPIServer) PatchWebhook ¶
func (a *WebhooksAPIServer) PatchWebhook( ctx context.Context, req *apiv1.PatchWebhookRequest, ) (*apiv1.PatchWebhookResponse, error)
PatchWebhook updates a webhook.
func (*WebhooksAPIServer) PostWebhook ¶
func (a *WebhooksAPIServer) PostWebhook( ctx context.Context, req *apiv1.PostWebhookRequest, ) (*apiv1.PostWebhookResponse, error)
PostWebhook creates a new Webhook.
func (*WebhooksAPIServer) PostWebhookEventData ¶
func (a *WebhooksAPIServer) PostWebhookEventData( ctx context.Context, req *apiv1.PostWebhookEventDataRequest, ) (*apiv1.PostWebhookEventDataResponse, error)
PostWebhookEventData handles data for custom trigger.
func (*WebhooksAPIServer) TestWebhook ¶
func (a *WebhooksAPIServer) TestWebhook( ctx context.Context, req *apiv1.TestWebhookRequest, ) (*apiv1.TestWebhookResponse, error)
TestWebhook sends a test event for a Webhook.