Skip to content

Commit 5b4930c

Browse files
authored
Merge pull request #114352 from MicrosoftDocs/j-martens-patch-27-1
Update how-to-use-event-grid.md
2 parents 5a09a07 + 70af4de commit 5b4930c

File tree

1 file changed

+95
-24
lines changed

1 file changed

+95
-24
lines changed

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

Lines changed: 95 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Create event driven machine learning workflows
2+
title: Trigger events in ML workflows
33
titleSuffix: Azure Machine Learning
4-
description: Learn how to use event grid with Azure Machine Learning to enable event driven solutions.
4+
description: Learn how to trigger event-driven applications, processes, or CI/CD workflows based on Azure Machine Learning events to simplify your ML lifecycle.
55
services: machine-learning
66
ms.service: machine-learning
77
ms.subservice: core
@@ -12,27 +12,101 @@ ms.reviewer: larryfr
1212
ms.date: 03/11/2020
1313
---
1414

15+
# Trigger event-driven applications, processes, or CI/CD workflows based on Azure Machine Learning events (Preview)
1516

16-
# Create event driven machine learning workflows (Preview)
17+
In this article, you learn how to set up event-driven applications, processes, or CI/CD workflows based on Azure Machine Learning events, such as failure notification emails or ML pipeline runs, when certain conditions are detected by [Azure Event Grid](https://docs.microsoft.com/azure/event-grid/).
1718

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-
21-
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.
2220

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

2827
> [!NOTE]
2928
> Currently, runStatusChanged events only trigger when the run status is **failed**
30-
>
3129
3230
## Prerequisites
33-
* 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+
3468

35-
### 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
36110

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

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

53127

54-
### Configure EventGrid using the CLI
128+
### Set up with the CLI
55129

56130
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.
57131

@@ -76,17 +150,9 @@ az eventgrid event-subscription create \
76150
--subject-begins-with "models/mymodelname"
77151
```
78152

79-
## Filter Events
153+
## Examples
80154

81-
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.
82-
83-
1. Go to the Azure portal, select a new subscription or an existing one.
84-
85-
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.
86-
87-
:::image type="content" source="media/how-to-use-event-grid/select-event-filters.png" alt-text="filter events":::
88-
89-
## Sample: Send email alerts
155+
### Example: Send email alerts
90156

91157
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.
92158

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

121187

122-
## Sample: Trigger retraining when data drift occurs
188+
### Example: Data drift triggers retraining
123189

124190
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.
125191

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

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

169-
## Sample: Deploy a model based on tags
235+
### Example: Deploy a model based on tags
170236

171237
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.
172238

173239
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.
174240

175241
## Next steps
176242

177-
* 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)