Skip to content

Commit

Permalink
Metrics Advisor SDK APIs aligning with most recent swagger updates (#…
Browse files Browse the repository at this point in the history
…21936)

* Adding more doc to FeedType types and correcting typo in addFeedback API name

* Using the name Sql, MongoDb, InfluxDb

* Initial impl of credential entities and its integration with data feed

* Apply Fluent, Immutable as appropriate

* Updating listMetricEnrichedSeriesData signature to take detectionId as first argument

* Renaming listAnomaliesForAlert and listAnomaliesForDetectionConfig to listAnomalies

* Adding ClientOptions

* Renaming listIncidentsForAlert and listIncidentsForDetectionConfig to listIncidents

* Adding DimensionKey::get(..) and renaming TOPN enum-value to TOP_N

* Add options overload API's

* revert DataFeedIngestionOption changes

* Updating BoundaryDirection, DataFeedRollupType, DataFeedSourceType and SingleBoundaryDirection to ExpandableStringEnum

* Adding doc for DataFeedSource abstract type, renaming AzureCosmosDataFeedSource to AzureCosmosDbDataFeedSource, deleting unused ElasticsearchDataFeedSource and HttpRequestDataFeedSource

* Removing setSubscriptionKey() and setApiKey(), instead adding an update method to atomically update the keys

* MA Credentials: Removing Entity suffix and adding DataSource prefix

* Rename ErrorCode to MetricsAdvisorErrorCode

* update listDataFeedIngestionStatus

* Addressing feedback for the last commit (Fixingspotbug and checkstyle)

* consider datasource prefix for credential as one word (archfeedback)

* Renaming DataSourceCredentialType to DatasourceCredentialType

* Adding tests for Data Source Credentials. Rename userfacing type DataSourceAuthenticationType to DatasourceAuthenticationType (Datasource as one word)

* Adding junit tests for data source cred async apis

* Adding sync tests for Data Source Credentials and recordings

* Adding samples and code snippets for Credential Entity API

* Adding test skeleton for associating cred to datafeed

* Use single word datasource for DataSourceDataLakeGen2SharedKey

* Removing unsupported value 'Secondly' from Granularity

* Hiding clientSecret getter from AzureLogAnalyticsDataFeedSource

* Finishing Cred association with DataFeedSources

* Completing tests for Cred association with DataFeedSources

* Adding test recordings for Cred to DataFeedSource association

* Adding cred association to AzureLogAnalytics DataFeed

* Add valid cred for log analytics

* rename to updateKey

* rename env vars

* Moving admin models to admininstration.models package

* Removing equality assert on LogAna ids

* Update Changelog (#7)

* Fix pipeline error - export admin models (#8)

* Moving MetricsAdvisorServiceVersion to root package

* Override setDimensionFilter in Feedback types to ensure fluent chain

* Adding addFeedbackWithResponse in sync client

* Use the param name credentialId consistently, removing unsupported connectionstring cred from data-explorer

* Rename DATA_LAKE_GEN2SHARED_KEY enum-val to DATA_LAKE_GEN2_SHARED_KEY, use DataFeedRollupSettings::rollupIdentificationValue param name consiistently

* Use from prefix (instead of using prefix) for all factory methods to create data-source with credentials

* Introduced MetricsAdvisorKeys that composes subscription and api key

* Renaming error types to MetricsAdvisorError and MetricsAdvisorResponseException

* update module info and add final

Co-authored-by: samvaity <savaity@microsoft.com>
Co-authored-by: Sameeksha Vaity <sameeksha.v91@gmail.com>
  • Loading branch information
3 people committed Jun 4, 2021
1 parent 71e63f7 commit 19b1dde
Show file tree
Hide file tree
Showing 260 changed files with 10,995 additions and 2,545 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AnomaliesListTest(PerfStressOptions options) {
@Override
public void run() {
super.metricsAdvisorClient
.listAnomaliesForAlert(super.alertConfigId,
.listAnomalies(super.alertConfigId,
super.alertId,
new ListAnomaliesAlertedOptions(),
Context.NONE)
Expand All @@ -38,7 +38,7 @@ public void run() {
@Override
public Mono<Void> runAsync() {
return super.metricsAdvisorAsyncClient
.listAnomaliesForAlert(super.alertConfigId,
.listAnomalies(super.alertConfigId,
super.alertId,
new ListAnomaliesAlertedOptions())
.take(super.maxListElements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.azure.ai.metricsadvisor.perf;

import com.azure.ai.metricsadvisor.models.ListIncidentsAlertedOptions;
import com.azure.ai.metricsadvisor.perf.core.ServiceTest;
import com.azure.perf.test.core.PerfStressOptions;
import reactor.core.publisher.Mono;
Expand All @@ -24,9 +23,8 @@ public IncidentsListTest(PerfStressOptions options) {
@Override
public void run() {
super.metricsAdvisorClient
.listIncidentsForAlert(super.alertConfigId,
super.alertId,
new ListIncidentsAlertedOptions())
.listIncidents(super.alertConfigId,
super.alertId)
.stream()
.limit(super.maxListElements)
.forEach(incident -> {
Expand All @@ -36,9 +34,8 @@ public void run() {
@Override
public Mono<Void> runAsync() {
return super.metricsAdvisorAsyncClient
.listIncidentsForAlert(super.alertConfigId,
super.alertId,
new ListIncidentsAlertedOptions())
.listIncidents(super.alertConfigId,
super.alertId)
.take(super.maxListElements)
.then();
}
Expand Down
15 changes: 12 additions & 3 deletions sdk/metricsadvisor/azure-ai-metricsadvisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
## 1.0.0-beta.4 (Unreleased)

### Features added
- Added support for Azure Log Analytics DataFeed source.
- Added support for Azure Log Analytics DataFeed source
- Added data source credential API support to client
- Added authentication type support for data feed
- Added property `splitAlertByDimensions` to AnomalyAlertConfiguration model

### Breaking changes
- Replaced updateSubscriptionKey and updateApiKey into one method updateKey
- Deprecated support for HttpRequestDataFeed and ElasticsearchDataFeed source type
- Renamed `value` and `expectedValue` to `valueOfRootNode` and `expectedValueOfRootNode`
- Renamed `top` parameter to `maxPageSize`

- Removed granularity type DataFeedGranularityType.PerSecond as it's not supported by the service anymore.

## 1.0.0-beta.3 (2021-02-09)
- Support Azure Active Directory (AAD) authentication for Metrics Advisor clients.
- Renamed method `listDimensionValuesWithAnomalies` and `ListDimensionValuesWithAnomaliesOptions`.
Expand All @@ -32,7 +39,9 @@
- Renamed Data feed ingestion granularity type to `"PerMinute"` and `"PerSecond"` instead of `"Minutely"` and `"Secondly"`.
- Renamed Feedback api's from `createMetricFeedback`, `getMetricFeedback` and `listMetricFeedbacks`
to `addFeedback`, `getFeedback` and `listFeedback` respectively.

- Removed `getSubscriptionKey` and `getApiKey` from `MetricsAdvisorKeyCredential` and introduced `MetricsAdvisorKeys`.
- Renamed model `ErrorCode` to `MetricsAdvisorError` and `ErrorCodeException`
to `MetricsAdvisorResponseException`
## 1.0.0-beta.1 (2020-10-07)
Version 1.0.0-beta.1 is a preview of our efforts in creating a Azure Metrics Advisor client library that is developer-friendly
and idiomatic to the Java ecosystem. The principles that guide
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.ai.metricsadvisor.implementation.AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl;
import com.azure.ai.metricsadvisor.implementation.AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2ImplBuilder;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorKeyCredential;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorServiceVersion;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.ContentType;
Expand All @@ -19,11 +18,13 @@
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RequestIdPolicy;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
Expand Down Expand Up @@ -79,6 +80,8 @@ public final class MetricsAdvisorClientBuilder {
private static final RetryPolicy DEFAULT_RETRY_POLICY = new RetryPolicy("retry-after-ms",
ChronoUnit.MILLIS);
private static final String DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default";
private static final HttpLogOptions DEFAULT_LOG_OPTIONS = new HttpLogOptions();
private static final ClientOptions DEFAULT_CLIENT_OPTIONS = new ClientOptions();

private final ClientLogger logger = new ClientLogger(MetricsAdvisorClientBuilder.class);
private final List<HttpPipelinePolicy> policies;
Expand All @@ -91,6 +94,7 @@ public final class MetricsAdvisorClientBuilder {
private TokenCredential tokenCredential;
private HttpClient httpClient;
private HttpLogOptions httpLogOptions;
private ClientOptions clientOptions;
private HttpPipeline httpPipeline;
private Configuration configuration;
private RetryPolicy retryPolicy;
Expand All @@ -111,8 +115,8 @@ public MetricsAdvisorClientBuilder() {
clientVersion = properties.getOrDefault(VERSION, "UnknownVersion");

headers = new HttpHeaders()
.put(ECHO_REQUEST_ID_HEADER, "true")
.put(ACCEPT_HEADER, CONTENT_TYPE_HEADER_VALUE);
.set(ECHO_REQUEST_ID_HEADER, "true")
.set(ACCEPT_HEADER, CONTENT_TYPE_HEADER_VALUE);
}

/**
Expand Down Expand Up @@ -183,24 +187,29 @@ private HttpPipeline getDefaultHttpPipeline(Configuration buildConfiguration) {
// Authentications
if (tokenCredential != null) {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPE));
} else if (!CoreUtils.isNullOrEmpty(metricsAdvisorKeyCredential.getSubscriptionKey())
|| !CoreUtils.isNullOrEmpty(metricsAdvisorKeyCredential.getApiKey())) {
headers.put(OCP_APIM_SUBSCRIPTION_KEY, metricsAdvisorKeyCredential.getSubscriptionKey());
headers.put(API_KEY, metricsAdvisorKeyCredential.getApiKey());
} else if (!CoreUtils.isNullOrEmpty(metricsAdvisorKeyCredential.getKeys().getSubscriptionKey())
|| !CoreUtils.isNullOrEmpty(metricsAdvisorKeyCredential.getKeys().getApiKey())) {
headers.set(OCP_APIM_SUBSCRIPTION_KEY, metricsAdvisorKeyCredential.getKeys().getSubscriptionKey());
headers.set(API_KEY, metricsAdvisorKeyCredential.getKeys().getApiKey());
} else {
// Throw exception that credential cannot be null
throw logger.logExceptionAsError(
new IllegalArgumentException("Missing credential information while building a client."));
}

policies.add(new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion,
ClientOptions buildClientOptions = this.clientOptions == null ? DEFAULT_CLIENT_OPTIONS : this.clientOptions;
HttpLogOptions buildLogOptions = this.httpLogOptions == null ? DEFAULT_LOG_OPTIONS : this.httpLogOptions;
final String applicationId = CoreUtils.getApplicationId(buildClientOptions, buildLogOptions);

policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion,
buildConfiguration));
policies.add(new RequestIdPolicy());
policies.add(new AddHeadersPolicy(headers));

HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy);
policies.add(new AddDatePolicy());
policies.add(new HttpLoggingPolicy(httpLogOptions));

policies.addAll(this.policies);
HttpPolicyProviders.addAfterRetryPolicies(policies);
Expand Down Expand Up @@ -280,6 +289,17 @@ public MetricsAdvisorClientBuilder httpLogOptions(HttpLogOptions logOptions) {
return this;
}

/**
* Sets the client options such as application ID and custom headers to set on a request.
*
* @param clientOptions The client options.
* @return The updated MetricsAdvisorClientBuilder object.
*/
public MetricsAdvisorClientBuilder clientOptions(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
return this;
}

/**
* Adds a policy to the set of existing policies that are executed after required policies.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.ai.metricsadvisor.models;
package com.azure.ai.metricsadvisor;

import com.azure.core.util.ServiceVersion;

Expand Down
Loading

0 comments on commit 19b1dde

Please sign in to comment.