Skip to content

Commit 475f857

Browse files
authored
Update how-to-use-event-grid.md
1 parent 1f4bf84 commit 475f857

File tree

1 file changed

+92
-22
lines changed

1 file changed

+92
-22
lines changed

articles/machine-learning/how-to-use-event-grid.md

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,101 @@ ms.reviewer: larryfr
1212
ms.date: 03/11/2020
1313
---
1414

15-
1615
# Create event driven machine learning workflows (Preview)
1716

18-
[Azure Event Grid](https://docs.microsoft.com/azure/event-grid/) supports Azure Machine Learning events. You can subscribe and consume events such as run status changed, run completion, model registration, model deployment, and data drift detection within a workspace.
19-
20-
For more information on event types, see [Azure Machine Learning integration with Event Grid](concept-event-grid-integration.md) and the [Azure Machine Learning event grid schema](/azure/event-grid/event-schema-machine-learning).
17+
In this article, you learn how to define machine learning actions, such as failure notification emails or ML pipeline runs when events or conditions are detected by [Azure Event Grid](https://docs.microsoft.com/azure/event-grid/).
2118

22-
Use Event Grid to enable common scenarios such as:
19+
Azure Machine Learning manages the entire lifecycle of machine learning process, including model training, model deployment, and monitoring. You can use Event Grid to react to Azure Machine Learning events, such as the completion of training runs, the registration and deployment of models, and the detection of data drift, by using modern serverless architectures. You can then subscribe and consume events such as run status changed, run completion, model registration, model deployment, and data drift detection within a workspace.
2320

21+
When to use Event Grid for event driven actions:
2422
* Send emails on run failure and run completion
2523
* Use an Azure function after a model is registered
2624
* Streaming events from Azure Machine Learning to various of endpoints
2725
* Trigger an ML pipeline when drift is detected
2826

2927
> [!NOTE]
3028
> Currently, runStatusChanged events only trigger when the run status is **failed**
31-
>
3229
3330
## Prerequisites
34-
* Contributor or owner access to the Azure Machine Learning workspace you will create events for.
31+
To use Event Grid, you need contributor or owner access to the Azure Machine Learning workspace you will create events for.
32+
33+
## The event model & types
34+
35+
Azure Event Grid reads events from sources, such as Azure Machine Learning and other Azure services. These events are then sent to event handlers such as Azure Event Hubs, Azure Functions, Logic Apps, and others. The following diagram shows how Event Grid connects sources and handlers, but is not a comprehensive list of supported integrations.
36+
37+
![Azure Event Grid functional model](./media/concept-event-grid-integration/azure-event-grid-functional-model.png)
38+
39+
For more information on event sources and event handlers, see [What is Event Grid?](/azure/event-grid/overview).
40+
41+
### Event types for Azure Machine Learning
42+
43+
Azure Machine Learning provides events in the various points of machine learning lifecycle:
44+
45+
| Event type | Description |
46+
| ---------- | ----------- |
47+
| `Microsoft.MachineLearningServices.RunCompleted` | Raised when a machine learning experiment run is completed |
48+
| `Microsoft.MachineLearningServices.ModelRegistered` | Raised when a machine learning model is registered in the workspace |
49+
| `Microsoft.MachineLearningServices.ModelDeployed` | Raised when a deployment of inference service with one or more models is completed |
50+
| `Microsoft.MachineLearningServices.DatasetDriftDetected` | Raised when a data drift detection job for two datasets is completed |
51+
| `Microsoft.MachineLearningServices.RunStatusChanged` | Raised when a run status changed, currently only raised when a run status is 'failed' |
52+
53+
### Filter & subscribe to events
54+
55+
These events are published through Azure Event Grid. Using Azure portal, Powershell or Azure CLI, customers can easily subscribe to events by [specifying one or more event types, and filtering conditions](/azure/event-grid/event-filtering).
56+
57+
When setting up your events, you can apply filters to only trigger on specific event data. In the example below, for run status changed events, you can filter by run types. The event only triggers when the criteria is met. Refer to the [Azure Machine Learning event grid schema](/azure/event-grid/event-schema-machine-learning) to learn about event data you can filter by.
58+
59+
Subscriptions for Azure Machine Learning events are protected by role-based access control (RBAC). Only [contributor or owner](how-to-assign-roles.md#default-roles) of a workspace can create, update, and delete event subscriptions. Filters can be applied to event subscriptions either during the [creation](/cli/azure/eventgrid/event-subscription?view=azure-cli-latest) of the event subscription or at a later time.
60+
61+
62+
1. Go to the Azure portal, select a new subscription or an existing one.
63+
64+
1. Select the filters tab and scroll down to Advanced filters. For the **Key** and **Value**, provide the property types you want to filter by. Here you can see the event will only trigger when the run type is a pipeline run or pipeline step run.
65+
66+
:::image type="content" source="media/how-to-use-event-grid/select-event-filters.png" alt-text="filter events":::
67+
3568

36-
### Configure EventGrid using the Azure portal
69+
+ **Filter by event type:** An event subscription can specify one or more Azure Machine Learning event types.
70+
71+
+ **Filter by event subject:** Azure Event Grid supports subject filters based on __begins with__ and __ends with__ matches, so that events with a matching subject are delivered to the subscriber. Different machine learning events have different subject format.
72+
73+
| Event type | Subject format | Sample subject |
74+
| ---------- | ----------- | ----------- |
75+
| `Microsoft.MachineLearningServices.RunCompleted` | `experiments/{ExperimentId}/runs/{RunId}` | `experiments/b1d7966c-f73a-4c68-b846-992ace89551f/runs/my_exp1_1554835758_38dbaa94` |
76+
| `Microsoft.MachineLearningServices.ModelRegistered` | `models/{modelName}:{modelVersion}` | `models/sklearn_regression_model:3` |
77+
| `Microsoft.MachineLearningServices.ModelDeployed` | `endpoints/{serviceId}` | `endpoints/my_sklearn_aks` |
78+
| `Microsoft.MachineLearningServices.DatasetDriftDetected` | `datadrift/{data.DataDriftId}/run/{data.RunId}` | `datadrift/4e694bf5-712e-4e40-b06a-d2a2755212d4/run/my_driftrun1_1550564444_fbbcdc0f` |
79+
| `Microsoft.MachineLearningServices.RunStatusChanged` | `experiments/{ExperimentId}/runs/{RunId}` | `experiments/b1d7966c-f73a-4c68-b846-992ace89551f/runs/my_exp1_1554835758_38dbaa94` |
80+
81+
+ **Advanced filtering**: Azure Event Grid also supports advanced filtering based on published event schema. Azure Machine Learning event schema details can be found in [Azure Event Grid event schema for Azure Machine Learning](../event-grid/event-schema-machine-learning.md). Some sample advanced filterings you can perform include:
82+
83+
For `Microsoft.MachineLearningServices.ModelRegistered` event, to filter model's tag value:
84+
85+
```
86+
--advanced-filter data.ModelTags.key1 StringIn ('value1')
87+
```
88+
89+
To learn more about how to apply filters, see [Filter events for Event Grid](https://docs.microsoft.com/azure/event-grid/how-to-filter-events).
90+
91+
## Consume Machine Learning events
92+
93+
Applications that handle Machine Learning events should follow a few recommended practices:
94+
95+
> [!div class="checklist"]
96+
> * As multiple subscriptions can be configured to route events to the same event handler, it is important not to assume events are from a particular source, but to check the topic of the message to ensure that it comes from the machine learning workspace you are expecting.
97+
> * Similarly, check that the eventType is one you are prepared to process, and do not assume that all events you receive will be the types you expect.
98+
> * As messages can arrive out of order and after some delay, use the etag fields to understand if your information about objects is still up-to-date. Also, use the sequencer fields to understand the order of events on any particular object.
99+
> * Ignore fields you don't understand. This practice will help keep you resilient to new features that might be added in the future.
100+
> * Failed or cancelled Azure Machine Learning operations will not trigger an event. For example, if a model deployment fails Microsoft.MachineLearningServices.ModelDeployed won't be triggered. Consider such failure mode when design your applications. You can always use Azure Machine Learning SDK, CLI or portal to check the status of an operation and understand the detailed failure reasons.
101+
102+
Azure Event Grid allows customers to build de-coupled message handlers, which can be triggered by Azure Machine Learning events. Some notable examples of message handlers are:
103+
* Azure Functions
104+
* Azure Logic Apps
105+
* Azure Event Hubs
106+
* Azure Data Factory Pipeline
107+
* Generic webhooks, which may be hosted on the Azure platform or elsewhere
108+
109+
## Set up in Azure portal
37110

38111
1. Open the [Azure portal](https://portal.azure.com) and go to your Azure Machine Learning workspace.
39112

@@ -52,7 +125,7 @@ Use Event Grid to enable common scenarios such as:
52125
Once you have confirmed your selection, click __Create__. After configuration, these events will be pushed to your endpoint.
53126

54127

55-
### Configure EventGrid using the CLI
128+
### Set up with the CLI
56129

57130
You can either install the latest [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest), or use the Azure Cloud Shell that is provided as part of your Azure subscription.
58131

@@ -77,17 +150,9 @@ az eventgrid event-subscription create \
77150
--subject-begins-with "models/mymodelname"
78151
```
79152

80-
## Filter Events
153+
## Examples
81154

82-
When setting up your events, you can apply filters to only trigger on specific event data. In the example below, for run status changed events, you can filter by run types. The event only triggers when the criteria is met. Refer to the [Azure Machine Learning event grid schema](/azure/event-grid/event-schema-machine-learning) to learn about event data you can filter by.
83-
84-
1. Go to the Azure portal, select a new subscription or an existing one.
85-
86-
1. Select the filters tab and scroll down to Advanced filters. For the **Key** and **Value**, provide the property types you want to filter by. Here you can see the event will only trigger when the run type is a pipeline run or pipeline step run.
87-
88-
:::image type="content" source="media/how-to-use-event-grid/select-event-filters.png" alt-text="filter events":::
89-
90-
## Sample: Send email alerts
155+
### Example: Send email alerts
91156

92157
Use [Azure Logic Apps](https://docs.microsoft.com/azure/logic-apps/) to configure emails for all your events. Customize with conditions and specify recipients to enable collaboration and awareness across teams working together.
93158

@@ -120,7 +185,7 @@ Use [Azure Logic Apps](https://docs.microsoft.com/azure/logic-apps/) to configur
120185
![confirm-logic-app-create](./media/how-to-use-event-grid/confirm-logic-app-create.png)
121186

122187

123-
## Sample: Trigger retraining when data drift occurs
188+
### Example: Data drift triggers retraining
124189

125190
Models go stale over time, and not remain useful in the context it is running in. One way to tell if it's time to retrain the model is detecting data drift.
126191

@@ -167,12 +232,17 @@ Now the data factory pipeline is triggered when drift occurs. View details on yo
167232

168233
![view-in-workspace](./media/how-to-use-event-grid/view-in-workspace.png)
169234

170-
## Sample: Deploy a model based on tags
235+
### Example: Deploy a model based on tags
171236

172237
An Azure Machine Learning model object contains parameters you can pivot deployments on such as model name, version, tag, and property. The model registration event can trigger an endpoint and you can use an Azure Function to deploy a model based on the value of those parameters.
173238

174239
For an example, see the [https://github.com/Azure-Samples/MachineLearningSamples-NoCodeDeploymentTriggeredByEventGrid](https://github.com/Azure-Samples/MachineLearningSamples-NoCodeDeploymentTriggeredByEventGrid) repository and follow the steps in the **readme** file.
175240

176241
## Next steps
177242

178-
* To learn more about available events, see the [Azure Machine Learning event schema](/azure/event-grid/event-schema-machine-learning)
243+
Learn more about Event Grid and give Azure Machine Learning events a try:
244+
245+
- [About Event Grid](../event-grid/overview.md)
246+
247+
- [Event schema for Azure Machine Learning](../event-grid/event-schema-machine-learning.md)
248+

0 commit comments

Comments
 (0)