diff --git a/docs/assets/images/webhook_modal.png b/docs/assets/images/webhook_modal.png index fd403979f03..311fb181854 100644 Binary files a/docs/assets/images/webhook_modal.png and b/docs/assets/images/webhook_modal.png differ diff --git a/docs/integrations/notification/_index.rst b/docs/integrations/notification/_index.rst index 4c6223b099d..0f81fde2cbd 100644 --- a/docs/integrations/notification/_index.rst +++ b/docs/integrations/notification/_index.rst @@ -122,6 +122,31 @@ Below is an example of handling a signed payload in Python. signed payload. For example "{"key_one": "value_one"}" will fail authentication, while "{"key_one":"value_one"}" will yield the correct signed payload value. +.. _supported-webhook-triggers: + +Supported Triggers +================== + +``Completed`` or ``Error`` will be triggered when an experiment in scope is completed or errored. + +``Tasklog`` will be triggered when a task matching regex is detected. + +``Custom`` will only be triggered from experiment code. + +.. code:: + + # Here is an example code to trigger a custom trigger. + + # config.yaml + integrations: + webhooks: + webhook_name: + - + + # code.py + with det.core.init() as core_context: + core_context.alert(title="some title", description="some description", level="info") + ******************* Creating Webhooks ******************* @@ -140,11 +165,24 @@ To create a webhook: If you do not have sufficient permissions to view and create webhooks, consult with a systems admin. +- Workspace: You can only select from workspaces you have the permission to create webhook in. +- Name: Identifier to reference webhook in experiment configuration. - URL: Supply the webhook URL. - Type: Select a type, either ``Default`` or ``Slack``. The ``Slack`` type can automatically format message content for better readability on Slack. -- Trigger: Select the experiment state change you want to monitor, either ``Completed``, ``Error``, - or ``Tasklog``. +- Trigger: Select the event you want to monitor, see :ref:`supported-webhook-triggers`. +- Trigger by: Select whether you want to monitor all experiments within the workspace. ``Custom`` + trigger can only be triggered by specific experiments. + +.. code:: + + # Here is an example experiment config associated with specific webhooks + + integrations: + webhooks: + webhook_name: + - + - Regex: If the webhook is configured to trigger on Tasklog, define a regex using `Golang Regex Syntax `_. @@ -152,7 +190,8 @@ To create a webhook: :width: 100% :alt: Webhook user interface showing the fields you will interact with. -Once created, your webhook will begin executing for the selected events. +Once created, your webhook will begin executing for the selected events for experiments within +scope. ****************** Testing Webhooks @@ -189,10 +228,17 @@ payload as stated below: To delete a webhook, select the more-options menu to the right of the webhook record to expand available actions. +****************** + Editing Webhooks +****************** + +To edit a webhook, select the more-options menu to the right of the webhook record to expand +available actions. + .. note:: - Determined does not support editing webhooks. Instead, you should delete and recreate the - webhook. + Determined only support editing the URL of webhooks. To edit other attributes, you should delete + and recreate the webhook. .. toctree:: :caption: Notification diff --git a/docs/release-notes/workload-alerting.rst b/docs/release-notes/workload-alerting.rst new file mode 100644 index 00000000000..82aae733604 --- /dev/null +++ b/docs/release-notes/workload-alerting.rst @@ -0,0 +1,6 @@ +:orphan: + +**New Features** + +- Webhooks: Add support for monitoring experiment by workspaces, editing webhook URL and triggering webhook from code. For more details, refer to :ref:`supported-webhook-triggers`. + diff --git a/master/internal/webhooks/postgres_webhook.go b/master/internal/webhooks/postgres_webhook.go index 375f7aba4ea..7555a3878d6 100644 --- a/master/internal/webhooks/postgres_webhook.go +++ b/master/internal/webhooks/postgres_webhook.go @@ -409,7 +409,7 @@ func getWebhookByName(ctx context.Context, webhookName string, workspaceID int) Model(&webhook). Relation("Triggers"). Where("name = ?", webhookName). - Where("workspace_id = ?", workspaceID). + Where("workspace_id = ? OR workspace_id IS NULL", workspaceID). Scan(ctx) if err != nil { if err == sql.ErrNoRows { @@ -780,6 +780,7 @@ func generateSlackPayload( } else { eURL = fmt.Sprintf("%v (#%v)", activeConfig.Name(), e.ID) } + c = "#009bde" mStatus = string(e.State) } @@ -863,7 +864,7 @@ func generateSlackPayload( } messageBlock = SlackBlock{ Text: SlackField{ - Text: "Event Data", + Text: status, Type: "plain_text", }, Type: "section", diff --git a/webui/react/src/components/WebhookCreateModal.tsx b/webui/react/src/components/WebhookCreateModal.tsx index 5ccaf42dfdc..64f23b13fe6 100644 --- a/webui/react/src/components/WebhookCreateModal.tsx +++ b/webui/react/src/components/WebhookCreateModal.tsx @@ -5,6 +5,7 @@ import Select, { Option } from 'hew/Select'; import { useToast } from 'hew/Toast'; import React, { useCallback, useEffect, useId, useMemo, useState } from 'react'; +import Link from 'components/Link'; import useFeature from 'hooks/useFeature'; import usePermissions from 'hooks/usePermissions'; import { paths } from 'routes/utils'; @@ -15,6 +16,7 @@ import { RunState, Workspace } from 'types'; import handleError, { DetError, ErrorLevel, ErrorType } from 'utils/error'; import { useObservable } from 'utils/observable'; import { routeToReactUrl } from 'utils/routes'; + interface Props { onSuccess?: () => void; } @@ -68,7 +70,7 @@ const triggerOptions = [ ]; const modeOptions = [ { - label: 'All experiments in Workspace', + label: 'All experiments', value: V1WebhookMode.WORKSPACE, }, { @@ -188,11 +190,8 @@ const WebhookCreateModalComponent: React.FC = ({ onSuccess }: Props) => { onFieldsChange={onChange}> {f_webhook && ( <> - - {permWorkspace.map((workspace: Workspace) => ( )} + + Learn more + ); diff --git a/webui/react/src/hooks/useFeature.ts b/webui/react/src/hooks/useFeature.ts index 2dc68ae8707..5b87cd7707d 100644 --- a/webui/react/src/hooks/useFeature.ts +++ b/webui/react/src/hooks/useFeature.ts @@ -57,7 +57,7 @@ export const FEATURES: Record = { friendlyName: 'Manage Templates', }, webhook_improvement: { - defaultValue: false, + defaultValue: true, description: 'Allow webhooks to monitor experiments by workspace', friendlyName: 'Webhook Improvement', },