-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning up MA APIs before GA (#22336)
* API cleanup * Always take ref-type in Options setters, Remove Metric prefix from APIs, using hookIdsToAlert instead of idOfHooksToAlert * updating detection-config apis to be consistent with other languages * adjusting SupressCondition.minNumber given service added a range constraint (1-14) * updating alert tests to use a valid hookid
- Loading branch information
Showing
199 changed files
with
13,323 additions
and
6,150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ You will need two keys to authenticate the client: | |
Once you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows: | ||
|
||
#### Create a Metrics Advisor client using MetricsAdvisorKeyCredential | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L64-L68--> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L65-L69--> | ||
```java | ||
MetricsAdvisorKeyCredential credential = new MetricsAdvisorKeyCredential("subscription_key", "api_key"); | ||
MetricsAdvisorClient metricsAdvisorClient = new MetricsAdvisorClientBuilder() | ||
|
@@ -59,7 +59,7 @@ MetricsAdvisorClient metricsAdvisorClient = new MetricsAdvisorClientBuilder() | |
``` | ||
|
||
#### Create a Metrics Administration client using MetricsAdvisorKeyCredential | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L75-L80 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L76-L81 --> | ||
```java | ||
MetricsAdvisorKeyCredential credential = new MetricsAdvisorKeyCredential("subscription_key", "api_key"); | ||
MetricsAdvisorAdministrationClient metricsAdvisorAdminClient = | ||
|
@@ -97,7 +97,7 @@ Authorization is easiest using [DefaultAzureCredential][wiki_identity]. It finds | |
running environment. For more information about using Azure Active Directory authorization with Metrics Advisor, please | ||
refer to [the associated documentation][aad_authorization]. | ||
#### Create a Metrics Advisor client using AAD authentication | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L87-L91 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L88-L92 --> | ||
```java | ||
TokenCredential credential = new DefaultAzureCredentialBuilder().build(); | ||
MetricsAdvisorClient metricsAdvisorClient = new MetricsAdvisorClientBuilder() | ||
|
@@ -107,7 +107,7 @@ MetricsAdvisorClient metricsAdvisorClient = new MetricsAdvisorClientBuilder() | |
``` | ||
|
||
#### Create a Metrics Administration client using AAD authentication | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L98-L103 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L99-L104 --> | ||
```java | ||
TokenCredential credential = new DefaultAzureCredentialBuilder().build(); | ||
MetricsAdvisorAdministrationClient metricsAdvisorAdminClient = | ||
|
@@ -174,7 +174,7 @@ A notification hook is the entry point that allows the users to subscribe to rea | |
|
||
#### Add a data feed from a sample or data source | ||
This example ingests the user specified `SQLServerDataFeedSource` data feed source data to the service. | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L110-L147 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L111-L148 --> | ||
```java | ||
DataFeed dataFeed = new DataFeed() | ||
.setName("dataFeedName") | ||
|
@@ -212,13 +212,12 @@ System.out.printf("Data feed source type: %s%n", createdSqlDataFeed.getSourceTyp | |
|
||
if (SQL_SERVER_DB == createdSqlDataFeed.getSourceType()) { | ||
System.out.printf("Data feed sql server query: %s%n", | ||
((SQLServerDataFeedSource) createdSqlDataFeed.getSource()).getQuery()); | ||
((SqlServerDataFeedSource) createdSqlDataFeed.getSource()).getQuery()); | ||
} | ||
``` | ||
#### Check ingestion status | ||
This example checks the ingestion status of a previously provided data feed source. | ||
|
||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L154-L165 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L155-L166 --> | ||
```java | ||
String dataFeedId = "3d48er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
|
||
|
@@ -236,8 +235,7 @@ metricsAdvisorAdminClient.listDataFeedIngestionStatus( | |
|
||
#### Configure anomaly detection configuration | ||
This example demonstrates how a user can configure an anomaly detection configuration for their data. | ||
|
||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L172-L202 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L173-L203 --> | ||
```java | ||
String metricId = "3d48er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
|
||
|
@@ -268,17 +266,17 @@ final AnomalyDetectionConfiguration anomalyDetectionConfiguration = | |
.setChangeThresholdCondition(changeThresholdCondition) | ||
.setHardThresholdCondition(hardThresholdCondition) | ||
.setSmartDetectionCondition(smartDetectionCondition) | ||
.setCrossConditionOperator(DetectionConditionsOperator.OR)) | ||
.setConditionOperator(DetectionConditionOperator.OR)) | ||
); | ||
``` | ||
|
||
### Add hooks for receiving anomaly alerts | ||
This example creates an email hook that receives anomaly incident alerts. | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L209-L221 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L210-L222 --> | ||
```java | ||
NotificationHook emailNotificationHook = new EmailNotificationHook("email Hook") | ||
.setDescription("my email Hook") | ||
.addEmailToAlert("[email protected]") | ||
.setEmailsToAlert(new ArrayList<String>() {{ add("[email protected]"); }}) | ||
.setExternalLink("https://adwiki.azurewebsites.net/articles/howto/alerts/create-hooks.html"); | ||
|
||
final NotificationHook notificationHook = metricsAdvisorAdminClient.createHook(emailNotificationHook); | ||
|
@@ -293,23 +291,22 @@ System.out.printf("Email Hook emails to alert: %s%n", | |
|
||
#### Configure an anomaly alert configuration | ||
This example demonstrates how a user can configure an alerting configuration for detected anomalies in their data. | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L228-L248 --> | ||
|
||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L229-L249 --> | ||
```java | ||
String detectionConfigurationId1 = "9ol48er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
String detectionConfigurationId2 = "3e58er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
String hookId1 = "5f48er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
String hookId2 = "8i48er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
|
||
final AnomalyAlertConfiguration anomalyAlertConfiguration | ||
= metricsAdvisorAdminClient.createAnomalyAlertConfig( | ||
= metricsAdvisorAdminClient.createAlertConfig( | ||
new AnomalyAlertConfiguration("My anomaly alert config name") | ||
.setDescription("alert config description") | ||
.setMetricAlertConfigurations( | ||
Arrays.asList( | ||
new MetricAnomalyAlertConfiguration(detectionConfigurationId1, | ||
new MetricAlertConfiguration(detectionConfigurationId1, | ||
MetricAnomalyAlertScope.forWholeSeries()), | ||
new MetricAnomalyAlertConfiguration(detectionConfigurationId2, | ||
new MetricAlertConfiguration(detectionConfigurationId2, | ||
MetricAnomalyAlertScope.forWholeSeries()) | ||
.setAlertConditions(new MetricAnomalyAlertConditions() | ||
.setSeverityRangeCondition(new SeverityCondition() | ||
|
@@ -320,7 +317,7 @@ final AnomalyAlertConfiguration anomalyAlertConfiguration | |
``` | ||
#### Query anomaly detection results | ||
This example demonstrates how a user can query alerts triggered for an anomaly detection configuration and get anomalies for that anomalyAlert. | ||
|
||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L256-L276 --> | ||
```java | ||
String alertConfigurationId = "9ol48er30-6e6e-4391-b78f-b00dfee1e6f5"; | ||
final OffsetDateTime startTime = OffsetDateTime.parse("2020-01-01T00:00:00Z"); | ||
|
@@ -333,7 +330,7 @@ metricsAdvisorClient.listAlerts( | |
System.out.printf("AnomalyAlert created on: %s%n", alert.getCreatedTime()); | ||
|
||
// List anomalies for returned alerts | ||
metricsAdvisorClient.listAnomaliesForAlert( | ||
metricsAdvisorClient.listAnomalies( | ||
alertConfigurationId, | ||
alert.getId()) | ||
.forEach(anomaly -> { | ||
|
@@ -351,7 +348,7 @@ Metrics Advisor clients raises `HttpResponseException` [exceptions][http_respons | |
to provide a non existing feedback Id an `HttpResponseException` would be raised with an error indicating the failure cause. | ||
In the following code snippet, the error is handled | ||
gracefully by catching the exception and display the additional information about the error. | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L282-L286 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L283-L287 --> | ||
```java | ||
try { | ||
metricsAdvisorClient.getFeedback("non_existing_feedback_id"); | ||
|
@@ -376,7 +373,7 @@ For more details see the [samples README][samples_readme]. | |
#### Async APIs | ||
All the examples shown so far have been using synchronous APIs, but we provide full support for async APIs as well. | ||
You'll need to use `MetricsAdvisorAsyncClient` | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L293-L297 --> | ||
<!-- embedme ./src/samples/java/com/azure/ai/metricsadvisor/ReadmeSamples.java#L294-L298 --> | ||
```java | ||
MetricsAdvisorKeyCredential credential = new MetricsAdvisorKeyCredential("subscription_key", "api_key"); | ||
MetricsAdvisorAsyncClient metricsAdvisorAsyncClient = new MetricsAdvisorClientBuilder() | ||
|
Oops, something went wrong.