Documentation ¶
Index ¶
- Variables
- func AddWebhook(ctx context.Context, w *Webhook) error
- func AuthorizeRequest(ctx context.Context) 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) error
- func SetDefault(w *WebhookManager)
- type Condition
- 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 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) PostWebhook(ctx context.Context, req *apiv1.PostWebhookRequest) (*apiv1.PostWebhookResponse, 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 AuthorizeRequest ¶
AuthorizeRequest checks if the user has CanEditWebhooks permissions. TODO remove this eventually since authz replaces this We can't yet since we use it else where.
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. TODO(DET-8577): Remove unnecessary active config usage (remove the activeConfig parameter).
func ScanLogs ¶
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.
Types ¶
type Condition ¶
type Condition struct { State model.State `json:"state,omitempty"` Regex string `json:"regex,omitempty"` }
Condition represents a trigger condition.
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"` }
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"` }
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" )
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"` 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 // POST /api/v1/webhooks // DELETE /api/v1/webhooks/:webhook_id // POST /api/v1/webhooks/test/:webhook_id CanEditWebhooks(ctx context.Context, curUser *model.User) (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, ) (serverError error)
CanEditWebhooks always returns true and a nil error.
type WebhookAuthZPermissive ¶
type WebhookAuthZPermissive struct{}
WebhookAuthZPermissive is the permission implementation.
func (*WebhookAuthZPermissive) CanEditWebhooks ¶
CanEditWebhooks calls RBAC authz but enforces basic authz.
type WebhookAuthZRBAC ¶
type WebhookAuthZRBAC struct{}
WebhookAuthZRBAC is RBAC webhook access controls.
func (*WebhookAuthZRBAC) CanEditWebhooks ¶
CanEditWebhooks checks if a user can edit webhooks.
type WebhookManager ¶
type WebhookManager struct {
// contains filtered or unexported fields
}
WebhookManager manages webhooks.
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 Webhooks ¶
type Webhooks []Webhook
Webhooks is a slice of Webhook objects.
func GetWebhooks ¶
GetWebhooks returns all Webhooks from the DB.
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) PostWebhook ¶
func (a *WebhooksAPIServer) PostWebhook( ctx context.Context, req *apiv1.PostWebhookRequest, ) (*apiv1.PostWebhookResponse, error)
PostWebhook creates a new Webhook.
func (*WebhooksAPIServer) TestWebhook ¶
func (a *WebhooksAPIServer) TestWebhook( ctx context.Context, req *apiv1.TestWebhookRequest, ) (*apiv1.TestWebhookResponse, error)
TestWebhook sends a test event for a Webhook.