Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up MA APIs before GA #22336

Merged
merged 5 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions sdk/metricsadvisor/azure-ai-metricsadvisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 =
Expand Down Expand Up @@ -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()
Expand All @@ -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 =
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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";

Expand All @@ -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";

Expand Down Expand Up @@ -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("alertme@alertme.com")
.setEmailsToAlert(new ArrayList<String>() {{ add("alertme@alertme.com"); }})
.setExternalLink("https://adwiki.azurewebsites.net/articles/howto/alerts/create-hooks.html");

final NotificationHook notificationHook = metricsAdvisorAdminClient.createHook(emailNotificationHook);
Expand All @@ -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()
Expand All @@ -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");
Expand All @@ -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 -> {
Expand All @@ -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");
Expand All @@ -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()
Expand Down
Loading