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

Cleanup Swagger Transforms and Customizations in Metrics Advisor #33874

Merged
merged 5 commits into from
Mar 14, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.ai.metricsadvisor;

import com.azure.ai.metricsadvisor.implementation.AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl;
import com.azure.ai.metricsadvisor.implementation.MetricsAdvisorImpl;
import com.azure.ai.metricsadvisor.implementation.models.AlertingResultQuery;
import com.azure.ai.metricsadvisor.implementation.models.AnomalyDimensionQuery;
import com.azure.ai.metricsadvisor.implementation.models.AnomalyFeedback;
Expand All @@ -27,6 +27,7 @@
import com.azure.ai.metricsadvisor.implementation.models.PeriodFeedback;
import com.azure.ai.metricsadvisor.implementation.models.PeriodFeedbackValue;
import com.azure.ai.metricsadvisor.implementation.models.SeriesIdentity;
import com.azure.ai.metricsadvisor.implementation.models.TimeMode;
import com.azure.ai.metricsadvisor.implementation.util.AnomalyTransforms;
import com.azure.ai.metricsadvisor.implementation.util.DetectionConfigurationTransforms;
import com.azure.ai.metricsadvisor.implementation.util.IncidentHelper;
Expand All @@ -41,7 +42,6 @@
import com.azure.ai.metricsadvisor.models.DataPointAnomaly;
import com.azure.ai.metricsadvisor.models.DimensionKey;
import com.azure.ai.metricsadvisor.models.EnrichmentStatus;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorResponseException;
import com.azure.ai.metricsadvisor.models.IncidentRootCause;
import com.azure.ai.metricsadvisor.models.ListAlertOptions;
import com.azure.ai.metricsadvisor.models.ListAnomaliesAlertedOptions;
Expand All @@ -61,6 +61,7 @@
import com.azure.ai.metricsadvisor.models.MetricPeriodFeedback;
import com.azure.ai.metricsadvisor.models.MetricSeriesData;
import com.azure.ai.metricsadvisor.models.MetricSeriesDefinition;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorResponseException;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
Expand All @@ -85,6 +86,7 @@
import java.util.stream.Collectors;

import static com.azure.ai.metricsadvisor.implementation.util.Utility.parseOperationId;
import static com.azure.ai.metricsadvisor.implementation.util.Utility.toStringOrNull;
import static com.azure.core.util.FluxUtil.monoError;
import static com.azure.core.util.FluxUtil.withContext;

Expand All @@ -107,7 +109,7 @@
@ServiceClient(builder = MetricsAdvisorClientBuilder.class, isAsync = true)
public final class MetricsAdvisorAsyncClient {
final ClientLogger logger = new ClientLogger(MetricsAdvisorAsyncClient.class);
private final AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl service;
private final MetricsAdvisorImpl service;

/**
* Create a {@link MetricsAdvisorAsyncClient} that sends requests to the Metrics Advisor
Expand All @@ -117,7 +119,7 @@ public final class MetricsAdvisorAsyncClient {
* @param service The proxy service used to perform REST calls.
* @param serviceVersion The versions of Azure Metrics Advisor supported by this client library.
*/
MetricsAdvisorAsyncClient(AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl service,
MetricsAdvisorAsyncClient(MetricsAdvisorImpl service,
MetricsAdvisorServiceVersion serviceVersion) {
this.service = service;
}
Expand Down Expand Up @@ -1484,7 +1486,7 @@ private Mono<PagedResponse<AnomalyAlert>> listAlertsSinglePageAsync(
AlertingResultQuery query = new AlertingResultQuery();
query.setStartTime(startTime);
query.setEndTime(endTime);
query.setTimeMode(options.getTimeMode());
query.setTimeMode(TimeMode.fromString(toStringOrNull(options.getTimeMode())));

return service.getAlertsByAnomalyAlertingConfigurationSinglePageAsync(
UUID.fromString(alertConfigurationId),
Expand All @@ -1508,7 +1510,7 @@ private Mono<PagedResponse<AnomalyAlert>> listAlertsNextPageAsync(
AlertingResultQuery query = new AlertingResultQuery();
query.setStartTime(startTime);
query.setEndTime(endTime);
query.setTimeMode(options.getTimeMode());
query.setTimeMode(TimeMode.fromString(toStringOrNull(options.getTimeMode())));
srnagar marked this conversation as resolved.
Show resolved Hide resolved

return service.getAlertsByAnomalyAlertingConfigurationNextSinglePageAsync(nextPageLink,
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

package com.azure.ai.metricsadvisor;

import com.azure.ai.metricsadvisor.implementation.AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl;
import com.azure.ai.metricsadvisor.implementation.AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2ImplBuilder;
import com.azure.ai.metricsadvisor.implementation.MetricsAdvisorImpl;
import com.azure.ai.metricsadvisor.implementation.MetricsAdvisorImplBuilder;
import com.azure.ai.metricsadvisor.models.MetricsAdvisorKeyCredential;
import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.client.traits.ConfigurationTrait;
Expand Down Expand Up @@ -32,8 +32,8 @@
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.TracingOptions;
import com.azure.core.util.HttpClientOptions;
import com.azure.core.util.TracingOptions;
import com.azure.core.util.builder.ClientBuilderUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.tracing.Tracer;
Expand Down Expand Up @@ -220,8 +220,8 @@ public MetricsAdvisorAsyncClient buildAsyncClient() {
if (pipeline == null) {
pipeline = getDefaultHttpPipeline(buildConfiguration);
}
final AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl advisorRestAPIOpenAPIV2 =
new AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2ImplBuilder()
final MetricsAdvisorImpl advisorRestAPIOpenAPIV2 =
new MetricsAdvisorImplBuilder()
.endpoint(endpoint)
.pipeline(pipeline)
.buildClient();
Expand Down Expand Up @@ -267,7 +267,7 @@ private HttpPipeline getDefaultHttpPipeline(Configuration buildConfiguration) {
if (clientOptions != null) {
tracingOptions = clientOptions.getTracingOptions();
}

Tracer tracer = TracerProvider.getDefaultProvider()
.createTracer(clientName, clientVersion, METRICS_ADVISOR_TRACING_NAMESPACE_VALUE, tracingOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.azure.ai.metricsadvisor.administration.models.DataFeedRollupSettings;
import com.azure.ai.metricsadvisor.administration.models.DataFeedSchema;
import com.azure.ai.metricsadvisor.administration.models.DataSourceCredentialEntity;
import com.azure.ai.metricsadvisor.administration.models.IngestionStatusType;
import com.azure.ai.metricsadvisor.administration.models.ListAnomalyAlertConfigsOptions;
import com.azure.ai.metricsadvisor.administration.models.ListCredentialEntityOptions;
import com.azure.ai.metricsadvisor.administration.models.ListDataFeedFilter;
Expand All @@ -25,7 +26,7 @@
import com.azure.ai.metricsadvisor.administration.models.ListDetectionConfigsOptions;
import com.azure.ai.metricsadvisor.administration.models.ListHookOptions;
import com.azure.ai.metricsadvisor.administration.models.NotificationHook;
import com.azure.ai.metricsadvisor.implementation.AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl;
import com.azure.ai.metricsadvisor.implementation.MetricsAdvisorImpl;
import com.azure.ai.metricsadvisor.implementation.models.AnomalyAlertingConfiguration;
import com.azure.ai.metricsadvisor.implementation.models.AnomalyAlertingConfigurationPatch;
import com.azure.ai.metricsadvisor.implementation.models.AnomalyDetectionConfigurationPatch;
Expand All @@ -41,6 +42,8 @@
import com.azure.ai.metricsadvisor.implementation.models.RollUpMethod;
import com.azure.ai.metricsadvisor.implementation.models.ViewMode;
import com.azure.ai.metricsadvisor.implementation.util.AlertConfigurationTransforms;
import com.azure.ai.metricsadvisor.implementation.util.DataFeedIngestionProgressHelper;
import com.azure.ai.metricsadvisor.implementation.util.DataFeedIngestionStatusHelper;
import com.azure.ai.metricsadvisor.implementation.util.DataFeedTransforms;
import com.azure.ai.metricsadvisor.implementation.util.DataSourceCredentialEntityTransforms;
import com.azure.ai.metricsadvisor.implementation.util.DetectionConfigurationTransforms;
Expand All @@ -63,12 +66,14 @@
import reactor.core.publisher.Mono;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.azure.ai.metricsadvisor.administration.models.DataFeedGranularityType.CUSTOM;
import static com.azure.ai.metricsadvisor.implementation.util.Utility.parseOperationId;
import static com.azure.ai.metricsadvisor.implementation.util.Utility.toStringOrNull;
import static com.azure.core.util.FluxUtil.monoError;
import static com.azure.core.util.FluxUtil.withContext;

Expand All @@ -90,7 +95,7 @@
@ServiceClient(builder = MetricsAdvisorAdministrationClientBuilder.class, isAsync = true)
public final class MetricsAdvisorAdministrationAsyncClient {
private final ClientLogger logger = new ClientLogger(MetricsAdvisorAdministrationAsyncClient.class);
private final AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl service;
private final MetricsAdvisorImpl service;

/**
* Create a {@link MetricsAdvisorAdministrationAsyncClient} that sends requests to the Metrics Advisor
Expand All @@ -100,7 +105,7 @@ public final class MetricsAdvisorAdministrationAsyncClient {
* @param service The proxy service used to perform REST calls.
* @param serviceVersion The versions of Azure Metrics Advisor supported by this client library.
*/
MetricsAdvisorAdministrationAsyncClient(AzureCognitiveServiceMetricsAdvisorRestAPIOpenAPIV2Impl service,
MetricsAdvisorAdministrationAsyncClient(MetricsAdvisorImpl service,
MetricsAdvisorServiceVersion serviceVersion) {
this.service = service;
}
Expand Down Expand Up @@ -184,8 +189,6 @@ public Mono<DataFeed> createDataFeed(DataFeed dataFeed) {
* &#125;&#41;;
* </pre>
* <!-- end com.azure.ai.metricsadvisor.administration.MetricsAdvisorAdministrationAsyncClient.createDataFeedWithResponse#DataFeed -->
*
*
* @param dataFeed The data feed to be created.
* @return A {@link Response} of a {@link Mono} containing the created {@link DataFeed data feed}.
* @throws NullPointerException If {@code dataFeed}, {@code dataFeedName}, {@code dataFeedSource}, {@code metrics},
Expand Down Expand Up @@ -731,7 +734,27 @@ private Mono<PagedResponse<DataFeedIngestionStatus>> listDataFeedIngestionStatus
context)
.doOnRequest(ignoredValue -> logger.info("Listing ingestion status for data feed"))
.doOnSuccess(response -> logger.info("Listed ingestion status {}", response))
.doOnError(error -> logger.warning("Failed to ingestion status for data feed", error));
.doOnError(error -> logger.warning("Failed to ingestion status for data feed", error))
.map(res -> new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
toDataFeedIngestionStatus(res.getValue()),
res.getContinuationToken(),
null));
}

private List<DataFeedIngestionStatus> toDataFeedIngestionStatus(List<com.azure.ai.metricsadvisor.implementation.models.DataFeedIngestionStatus> ingestionStatusList) {
return ingestionStatusList
.stream()
.map(ingestionStatus -> {
DataFeedIngestionStatus dataFeedIngestionStatus = new DataFeedIngestionStatus();
DataFeedIngestionStatusHelper.setMessage(dataFeedIngestionStatus, ingestionStatus.getMessage());
DataFeedIngestionStatusHelper.setIngestionStatusType(dataFeedIngestionStatus, IngestionStatusType.fromString(toStringOrNull(ingestionStatus.getStatus())));
DataFeedIngestionStatusHelper.setTimestamp(dataFeedIngestionStatus, ingestionStatus.getTimestamp());
return dataFeedIngestionStatus;
Comment on lines +751 to +755
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? The DataFeedIngestionStatus should be correctly serialized and we don't need accessors to make it public. What's the difference between the DataFeedIngestionStatus in implementation package and the one in public package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is we need the DataFeedIngestionStatus in admin.models and not models. I believe earlier it was manually moved. But to make the swagger work as is without manual modifications we needed this transform.
are there any other options we can do?

})
.collect(Collectors.toList());
}

private Mono<PagedResponse<DataFeedIngestionStatus>> listDataFeedIngestionStatusNextPageAsync(
Expand All @@ -751,7 +774,14 @@ private Mono<PagedResponse<DataFeedIngestionStatus>> listDataFeedIngestionStatus
.doOnSuccess(response -> logger.info("Retrieved the next listing page - Page {} {}",
nextPageLink, response))
.doOnError(error -> logger.warning("Failed to retrieve the next listing page - Page {}", nextPageLink,
error));
error))
.map(res -> new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
toDataFeedIngestionStatus(res.getValue()),
res.getContinuationToken(),
null));
}

/**
Expand Down Expand Up @@ -918,7 +948,16 @@ Mono<Response<DataFeedIngestionProgress>> getDataFeedIngestionProgressWithRespon
return service.getIngestionProgressWithResponseAsync(UUID.fromString(dataFeedId), context)
.doOnRequest(ignoredValue -> logger.info("Retrieving ingestion progress for metric"))
.doOnSuccess(response -> logger.info("Retrieved ingestion progress {}", response))
.doOnError(error -> logger.warning("Failed to retrieve ingestion progress for metric", error));
.doOnError(error -> logger.warning("Failed to retrieve ingestion progress for metric", error))
.map(response -> new SimpleResponse<>(response, toDataFeedIngestionProgress(response.getValue())));
}

private DataFeedIngestionProgress toDataFeedIngestionProgress(
com.azure.ai.metricsadvisor.implementation.models.DataFeedIngestionProgress dataFeedIngestionProgressResponse) {
DataFeedIngestionProgress dataFeedIngestionProgress = new DataFeedIngestionProgress();
DataFeedIngestionProgressHelper.setLatestActiveTimestamp(dataFeedIngestionProgress, dataFeedIngestionProgressResponse.getLatestActiveTimestamp());
DataFeedIngestionProgressHelper.setLatestSuccessTimestamp(dataFeedIngestionProgress, dataFeedIngestionProgressResponse.getLatestSuccessTimestamp());
return dataFeedIngestionProgress;
}

/**
Expand Down Expand Up @@ -1774,7 +1813,7 @@ private Mono<PagedResponse<AnomalyDetectionConfiguration>> listAnomalyDetectionC
.doOnRequest(ignoredValue -> logger.info("Listing MetricAnomalyDetectionConfigs"))
.doOnSuccess(response -> logger.info("Listed MetricAnomalyDetectionConfigs {}", response))
.doOnError(error -> logger.warning("Failed to list the MetricAnomalyDetectionConfigs", error))
.map(response -> DetectionConfigurationTransforms.fromInnerPagedResponse(response));
.map(DetectionConfigurationTransforms::fromInnerPagedResponse);
}

private Mono<PagedResponse<AnomalyDetectionConfiguration>> listAnomalyDetectionConfigsNextPageAsync(
Expand All @@ -1789,7 +1828,7 @@ private Mono<PagedResponse<AnomalyDetectionConfiguration>> listAnomalyDetectionC
response))
.doOnError(error -> logger.warning("Failed to retrieve the next listing page - Page {}", nextPageLink,
error))
.map(response -> DetectionConfigurationTransforms.fromInnerPagedResponse(response));
.map(DetectionConfigurationTransforms::fromInnerPagedResponse);
}

/**
Expand Down Expand Up @@ -2748,7 +2787,7 @@ private Mono<PagedResponse<AnomalyAlertConfiguration>> listAnomalyAlertConfigsSi
.doOnRequest(ignoredValue -> logger.info("Listing AnomalyAlertConfigs"))
.doOnSuccess(response -> logger.info("Listed AnomalyAlertConfigs {}", response))
.doOnError(error -> logger.warning("Failed to list the AnomalyAlertConfigs", error))
.map(response -> AlertConfigurationTransforms.fromInnerPagedResponse(response));
.map(AlertConfigurationTransforms::fromInnerPagedResponse);
}

private Mono<PagedResponse<AnomalyAlertConfiguration>> listAnomalyAlertConfigsNextPageAsync(
Expand All @@ -2763,7 +2802,7 @@ private Mono<PagedResponse<AnomalyAlertConfiguration>> listAnomalyAlertConfigsNe
response))
.doOnError(error -> logger.warning("Failed to retrieve the next listing page - Page {}", nextPageLink,
error))
.map(response -> AlertConfigurationTransforms.fromInnerPagedResponse(response));
.map(AlertConfigurationTransforms::fromInnerPagedResponse);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.ai.metricsadvisor.administration.models.AnomalyAlertConfiguration;
import com.azure.ai.metricsadvisor.administration.models.AnomalyDetectionConfiguration;
import com.azure.ai.metricsadvisor.administration.models.DataFeed;
import com.azure.ai.metricsadvisor.administration.models.DataFeedIngestionProgress;
import com.azure.ai.metricsadvisor.administration.models.DataFeedIngestionStatus;
import com.azure.ai.metricsadvisor.administration.models.DataSourceCredentialEntity;
import com.azure.ai.metricsadvisor.administration.models.ListAnomalyAlertConfigsOptions;
Expand All @@ -16,6 +15,7 @@
import com.azure.ai.metricsadvisor.administration.models.ListDetectionConfigsOptions;
import com.azure.ai.metricsadvisor.administration.models.ListHookOptions;
import com.azure.ai.metricsadvisor.administration.models.NotificationHook;
import com.azure.ai.metricsadvisor.administration.models.DataFeedIngestionProgress;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
Expand Down
Loading