From 756237cf8a12d9172107b92aa26c1b65c87e2a04 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Mon, 18 Apr 2022 14:24:06 -0700 Subject: [PATCH 01/14] Initial commit for logs ingestion codegen --- .../azure-monitor-logingestion/CHANGELOG.md | 10 + .../azure-monitor-logingestion/README.md | 49 +++ .../azure-monitor-logingestion/pom.xml | 113 +++++++ .../DataCollectionRulesImpl.java | 251 +++++++++++++++ ...IngestionUsingDataCollectionRulesImpl.java | 127 ++++++++ ...onUsingDataCollectionRulesImplBuilder.java | 299 ++++++++++++++++++ .../models/ErrorAdditionalInfo.java | 49 +++ .../implementation/models/ErrorDetail.java | 102 ++++++ .../implementation/models/ErrorResponse.java | 52 +++ .../models/ErrorResponseException.java | 37 +++ .../implementation/models/package-info.java | 6 + .../implementation/package-info.java | 6 + .../monitor/logingestion/package-info.java | 7 + .../src/main/java/module-info.java | 7 + .../azure-monitor-logingestion.properties | 2 + .../src/samples/README.md | 28 ++ .../swagger/README.md | 24 ++ sdk/monitor/pom.xml | 1 + 18 files changed, 1170 insertions(+) create mode 100644 sdk/monitor/azure-monitor-logingestion/CHANGELOG.md create mode 100644 sdk/monitor/azure-monitor-logingestion/README.md create mode 100644 sdk/monitor/azure-monitor-logingestion/pom.xml create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/resources/azure-monitor-logingestion.properties create mode 100644 sdk/monitor/azure-monitor-logingestion/src/samples/README.md create mode 100644 sdk/monitor/azure-monitor-logingestion/swagger/README.md diff --git a/sdk/monitor/azure-monitor-logingestion/CHANGELOG.md b/sdk/monitor/azure-monitor-logingestion/CHANGELOG.md new file mode 100644 index 0000000000000..6842f1666cc43 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/CHANGELOG.md @@ -0,0 +1,10 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) +Version 1.0.0-beta.1 is a preview of our efforts in creating a client library for Azure Logs Ingestion that is +developer-friendly, idiomatic to the Java ecosystem, and as consistent across different languages and platforms as +possible. The principles that guide our efforts can be found in the +[Azure SDK Design Guidelines for Java](https://azure.github.io/azure-sdk/java_introduction.html). + +## Features Added +- Initial release. Please see the README and wiki for information on using the new library. diff --git a/sdk/monitor/azure-monitor-logingestion/README.md b/sdk/monitor/azure-monitor-logingestion/README.md new file mode 100644 index 0000000000000..0e974d1fbbe9e --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/README.md @@ -0,0 +1,49 @@ +# Azure Logs Ingestion client library for Java + +## Getting started + +### Prerequisites +- A [Java Development Kit (JDK)][jdk_link], version 8 or later. +- [Azure Subscription][azure_subscription] + +### Include the package + +[//]: # ({x-version-update-start;com.azure:azure-monitor-logingestion;current}) +```xml + + com.azure + azure-monitor-logingestion + 1.0.0-beta.1 + +``` +## Key concepts + +## Examples + +## Troubleshooting + +## Next steps + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License +Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the +PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this +once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact +[opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + + +[cla]: https://cla.microsoft.com +[coc]: https://opensource.microsoft.com/codeofconduct/ +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ +[coc_contact]: mailto:opencode@microsoft.com +[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable +[azure_subscription]: https://azure.microsoft.com/free + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-logingestion%2FREADME.png) diff --git a/sdk/monitor/azure-monitor-logingestion/pom.xml b/sdk/monitor/azure-monitor-logingestion/pom.xml new file mode 100644 index 0000000000000..9ee5a88e590c3 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/pom.xml @@ -0,0 +1,113 @@ + + + + 4.0.0 + + com.azure + azure-monitor-logingestion + 1.0.0-beta.1 + + jar + Microsoft Azure SDK for ${name} + This package contains Microsoft Azure Logs Ingestion SDK. + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + + azure-java-build-docs + ${site.url}/site/${project.artifactId} + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + UTF-8 + + + + + + + microsoft + Microsoft + + + + + + com.azure + azure-core + 1.27.0 + + + com.azure + azure-core-http-netty + 1.11.9 + + + + + org.junit.jupiter + junit-jupiter-api + 5.7.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.1 + test + + + org.junit.jupiter + junit-jupiter-params + 5.7.1 + test + + + com.azure + azure-core-test + 1.6.1 + test + + + org.mockito + mockito-core + 3.6.28 + test + + + io.projectreactor + reactor-test + 3.4.3 + test + + + com.azure + azure-identity + 1.4.6 + test + + + diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java new file mode 100644 index 0000000000000..8c0b4990ca9a2 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java @@ -0,0 +1,251 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.monitor.logingestion.implementation.models.ErrorResponseException; +import java.util.List; +import reactor.core.publisher.Mono; + +/** An instance of this class provides access to all the operations defined in DataCollectionRules. */ +public final class DataCollectionRulesImpl { + /** The proxy service used to perform REST calls. */ + private final DataCollectionRulesService service; + + /** The service client containing this operation class. */ + private final IngestionUsingDataCollectionRulesImpl client; + + /** + * Initializes an instance of DataCollectionRulesImpl. + * + * @param client the instance of the service client containing this operation class. + */ + DataCollectionRulesImpl(IngestionUsingDataCollectionRulesImpl client) { + this.service = + RestProxy.create( + DataCollectionRulesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for IngestionUsingDataCollectionRulesDataCollectionRules to be used by + * the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "IngestionUsingDataCo") + private interface DataCollectionRulesService { + @Post("/dataCollectionRules/{ruleId}/streams/{stream}") + @ExpectedResponses({204}) + @UnexpectedResponseExceptionType(ErrorResponseException.class) + Mono> ingest( + @HostParam("endpoint") String endpoint, + @PathParam("ruleId") String ruleId, + @PathParam("stream") String stream, + @QueryParam("api-version") String apiVersion, + @HeaderParam("Content-Encoding") String contentEncoding, + @HeaderParam("x-ms-client-request-id") String xMsClientRequestId, + @BodyParam("application/json") List body, + @HeaderParam("Accept") String accept, + Context context); + } + + /** + * See error response code and error response message for more detail. + * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param contentEncoding gzip. + * @param xMsClientRequestId Client request Id. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> ingestWithResponseAsync( + String ruleId, String stream, List body, String contentEncoding, String xMsClientRequestId) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException( + "Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (ruleId == null) { + return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null.")); + } + if (stream == null) { + return Mono.error(new IllegalArgumentException("Parameter stream is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.ingest( + this.client.getEndpoint(), + ruleId, + stream, + this.client.getApiVersion(), + contentEncoding, + xMsClientRequestId, + body, + accept, + context)); + } + + /** + * See error response code and error response message for more detail. + * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param contentEncoding gzip. + * @param xMsClientRequestId Client request Id. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> ingestWithResponseAsync( + String ruleId, + String stream, + List body, + String contentEncoding, + String xMsClientRequestId, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException( + "Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (ruleId == null) { + return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null.")); + } + if (stream == null) { + return Mono.error(new IllegalArgumentException("Parameter stream is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + final String accept = "application/json"; + return service.ingest( + this.client.getEndpoint(), + ruleId, + stream, + this.client.getApiVersion(), + contentEncoding, + xMsClientRequestId, + body, + accept, + context); + } + + /** + * See error response code and error response message for more detail. + * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param contentEncoding gzip. + * @param xMsClientRequestId Client request Id. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono ingestAsync( + String ruleId, String stream, List body, String contentEncoding, String xMsClientRequestId) { + return ingestWithResponseAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId) + .flatMap((Response res) -> Mono.empty()); + } + + /** + * See error response code and error response message for more detail. + * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param contentEncoding gzip. + * @param xMsClientRequestId Client request Id. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono ingestAsync( + String ruleId, + String stream, + List body, + String contentEncoding, + String xMsClientRequestId, + Context context) { + return ingestWithResponseAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId, context) + .flatMap((Response res) -> Mono.empty()); + } + + /** + * See error response code and error response message for more detail. + * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param contentEncoding gzip. + * @param xMsClientRequestId Client request Id. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void ingest( + String ruleId, String stream, List body, String contentEncoding, String xMsClientRequestId) { + ingestAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId).block(); + } + + /** + * See error response code and error response message for more detail. + * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param contentEncoding gzip. + * @param xMsClientRequestId Client request Id. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ErrorResponseException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response ingestWithResponse( + String ruleId, + String stream, + List body, + String contentEncoding, + String xMsClientRequestId, + Context context) { + return ingestWithResponseAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId, context).block(); + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java new file mode 100644 index 0000000000000..3a134fe77e5bf --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java @@ -0,0 +1,127 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; + +/** Initializes a new instance of the IngestionUsingDataCollectionRules type. */ +public final class IngestionUsingDataCollectionRulesImpl { + /** + * The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + */ + private final String endpoint; + + /** + * Gets The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** Api Version. */ + private final String apiVersion; + + /** + * Gets Api Version. + * + * @return the apiVersion value. + */ + public String getApiVersion() { + return this.apiVersion; + } + + /** The HTTP pipeline to send requests through. */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** The serializer to serialize an object into a string. */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** The DataCollectionRulesImpl object to access its operations. */ + private final DataCollectionRulesImpl dataCollectionRules; + + /** + * Gets the DataCollectionRulesImpl object to access its operations. + * + * @return the DataCollectionRulesImpl object. + */ + public DataCollectionRulesImpl getDataCollectionRules() { + return this.dataCollectionRules; + } + + /** + * Initializes an instance of IngestionUsingDataCollectionRules client. + * + * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * @param apiVersion Api Version. + */ + IngestionUsingDataCollectionRulesImpl(String endpoint, String apiVersion) { + this( + new HttpPipelineBuilder() + .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) + .build(), + JacksonAdapter.createDefaultSerializerAdapter(), + endpoint, + apiVersion); + } + + /** + * Initializes an instance of IngestionUsingDataCollectionRules client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * @param apiVersion Api Version. + */ + IngestionUsingDataCollectionRulesImpl(HttpPipeline httpPipeline, String endpoint, String apiVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); + } + + /** + * Initializes an instance of IngestionUsingDataCollectionRules client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * @param apiVersion Api Version. + */ + IngestionUsingDataCollectionRulesImpl( + HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, String apiVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.apiVersion = apiVersion; + this.dataCollectionRules = new DataCollectionRulesImpl(this); + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java new file mode 100644 index 0000000000000..4dd8161c0f128 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java @@ -0,0 +1,299 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.client.traits.TokenCredentialTrait; +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.CookiePolicy; +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.RetryOptions; +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.builder.ClientBuilderUtil; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** A builder for creating a new instance of the IngestionUsingDataCollectionRules type. */ +@ServiceClientBuilder(serviceClients = {IngestionUsingDataCollectionRulesImpl.class}) +public final class IngestionUsingDataCollectionRulesImplBuilder + implements HttpTrait, + ConfigurationTrait, + TokenCredentialTrait, + EndpointTrait { + @Generated private static final String SDK_NAME = "name"; + + @Generated private static final String SDK_VERSION = "version"; + + @Generated + private final Map properties = CoreUtils.getProperties("azure-monitor-logingestion.properties"); + + @Generated private final List pipelinePolicies; + + /** Create an instance of the IngestionUsingDataCollectionRulesImplBuilder. */ + @Generated + public IngestionUsingDataCollectionRulesImplBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated private HttpPipeline pipeline; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated private HttpClient httpClient; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated private HttpLogOptions httpLogOptions; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a + * request. + */ + @Generated private ClientOptions clientOptions; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated private RetryOptions retryOptions; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service + * client. + */ + @Generated private Configuration configuration; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The TokenCredential used for authentication. + */ + @Generated private TokenCredential tokenCredential; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder credential(TokenCredential tokenCredential) { + this.tokenCredential = tokenCredential; + return this; + } + + /* + * The service endpoint + */ + @Generated private String endpoint; + + /** {@inheritDoc}. */ + @Generated + @Override + public IngestionUsingDataCollectionRulesImplBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * Api Version + */ + @Generated private String apiVersion; + + /** + * Sets Api Version. + * + * @param apiVersion the apiVersion value. + * @return the IngestionUsingDataCollectionRulesImplBuilder. + */ + @Generated + public IngestionUsingDataCollectionRulesImplBuilder apiVersion(String apiVersion) { + this.apiVersion = apiVersion; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + @Generated private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the IngestionUsingDataCollectionRulesImplBuilder. + */ + @Generated + public IngestionUsingDataCollectionRulesImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if + * applicable. + */ + @Generated private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the IngestionUsingDataCollectionRulesImplBuilder. + */ + @Generated + public IngestionUsingDataCollectionRulesImplBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of IngestionUsingDataCollectionRulesImpl with the provided parameters. + * + * @return an instance of IngestionUsingDataCollectionRulesImpl. + */ + @Generated + public IngestionUsingDataCollectionRulesImpl buildClient() { + if (pipeline == null) { + this.pipeline = createHttpPipeline(); + } + if (apiVersion == null) { + this.apiVersion = "2021-11-01-preview"; + } + if (serializerAdapter == null) { + this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); + } + IngestionUsingDataCollectionRulesImpl client = + new IngestionUsingDataCollectionRulesImpl(pipeline, serializerAdapter, endpoint, apiVersion); + return client; + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration = + (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + if (httpLogOptions == null) { + httpLogOptions = new HttpLogOptions(); + } + if (clientOptions == null) { + clientOptions = new ClientOptions(); + } + List policies = new ArrayList<>(); + String clientName = properties.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(clientOptions, httpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = new HttpHeaders(); + clientOptions.getHeaders().forEach(header -> headers.set(header.getName(), header.getValue())); + if (headers.getSize() > 0) { + policies.add(new AddHeadersPolicy(headers)); + } + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + policies.add(new CookiePolicy()); + if (tokenCredential != null) { + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, String.format("%s/.default", endpoint))); + } + policies.addAll( + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = + new HttpPipelineBuilder() + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(clientOptions) + .build(); + return httpPipeline; + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java new file mode 100644 index 0000000000000..3d8bc5a2ebe39 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation.models; + +import com.azure.core.annotation.Immutable; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** The resource management error additional info. */ +@Immutable +public final class ErrorAdditionalInfo { + /* + * The additional info type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /* + * The additional info. + */ + @JsonProperty(value = "info", access = JsonProperty.Access.WRITE_ONLY) + private Object info; + + /** + * Get the type property: The additional info type. + * + * @return the type value. + */ + public String getType() { + return this.type; + } + + /** + * Get the info property: The additional info. + * + * @return the info value. + */ + public Object getInfo() { + return this.info; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() {} +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java new file mode 100644 index 0000000000000..f6db0837c9307 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation.models; + +import com.azure.core.annotation.Immutable; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** The error detail. */ +@Immutable +public final class ErrorDetail { + /* + * The error code. + */ + @JsonProperty(value = "code", access = JsonProperty.Access.WRITE_ONLY) + private String code; + + /* + * The error message. + */ + @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) + private String message; + + /* + * The error target. + */ + @JsonProperty(value = "target", access = JsonProperty.Access.WRITE_ONLY) + private String target; + + /* + * The error details. + */ + @JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY) + private List details; + + /* + * The error additional info. + */ + @JsonProperty(value = "additionalInfo", access = JsonProperty.Access.WRITE_ONLY) + private List additionalInfo; + + /** + * Get the code property: The error code. + * + * @return the code value. + */ + public String getCode() { + return this.code; + } + + /** + * Get the message property: The error message. + * + * @return the message value. + */ + public String getMessage() { + return this.message; + } + + /** + * Get the target property: The error target. + * + * @return the target value. + */ + public String getTarget() { + return this.target; + } + + /** + * Get the details property: The error details. + * + * @return the details value. + */ + public List getDetails() { + return this.details; + } + + /** + * Get the additionalInfo property: The error additional info. + * + * @return the additionalInfo value. + */ + public List getAdditionalInfo() { + return this.additionalInfo; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (getDetails() != null) { + getDetails().forEach(e -> e.validate()); + } + if (getAdditionalInfo() != null) { + getAdditionalInfo().forEach(e -> e.validate()); + } + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java new file mode 100644 index 0000000000000..67287f1a72a7f --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation.models; + +import com.azure.core.annotation.Fluent; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Error response Common error response for all Azure Resource Manager APIs to return error details for failed + * operations. (This also follows the OData error response format.). + */ +@Fluent +public final class ErrorResponse { + /* + * The error object. + */ + @JsonProperty(value = "error") + private ErrorDetail error; + + /** + * Get the error property: The error object. + * + * @return the error value. + */ + public ErrorDetail getError() { + return this.error; + } + + /** + * Set the error property: The error object. + * + * @param error the error value to set. + * @return the ErrorResponse object itself. + */ + public ErrorResponse setError(ErrorDetail error) { + this.error = error; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (getError() != null) { + getError().validate(); + } + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java new file mode 100644 index 0000000000000..da1b1ff3a8d62 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.logingestion.implementation.models; + +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.HttpResponse; + +/** Exception thrown for an invalid response with ErrorResponse information. */ +public final class ErrorResponseException extends HttpResponseException { + /** + * Initializes a new instance of the ErrorResponseException class. + * + * @param message the exception message or the response content if a message is not available. + * @param response the HTTP response. + */ + public ErrorResponseException(String message, HttpResponse response) { + super(message, response); + } + + /** + * Initializes a new instance of the ErrorResponseException class. + * + * @param message the exception message or the response content if a message is not available. + * @param response the HTTP response. + * @param value the deserialized response value. + */ + public ErrorResponseException(String message, HttpResponse response, ErrorResponse value) { + super(message, response, value); + } + + @Override + public ErrorResponse getValue() { + return (ErrorResponse) super.getValue(); + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java new file mode 100644 index 0000000000000..d9b1d48d04386 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** Package containing the data models for IngestionUsingDataCollectionRules. null. */ +package com.azure.monitor.logingestion.implementation.models; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java new file mode 100644 index 0000000000000..6c3bac712671b --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** Package containing the implementations for IngestionUsingDataCollectionRules. null. */ +package com.azure.monitor.logingestion.implementation; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java new file mode 100644 index 0000000000000..81cc7afa5573b --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * + */ +package com.azure.monitor.logingestion; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java new file mode 100644 index 0000000000000..e72df0ff7df55 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +module com.azure.monitor.logingestion { + requires transitive com.azure.core; + exports com.azure.monitor.logingestion; +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/resources/azure-monitor-logingestion.properties b/sdk/monitor/azure-monitor-logingestion/src/main/resources/azure-monitor-logingestion.properties new file mode 100644 index 0000000000000..ca812989b4f27 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/resources/azure-monitor-logingestion.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/sdk/monitor/azure-monitor-logingestion/src/samples/README.md b/sdk/monitor/azure-monitor-logingestion/src/samples/README.md new file mode 100644 index 0000000000000..4bfa8c365c5f8 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/samples/README.md @@ -0,0 +1,28 @@ +# Azure Logs Ingestion client library for Java + +## Getting started +Getting started explained in detail [here][SDK_README_GETTING_STARTED]. + +## Key concepts +Key concepts are explained in detail [here][SDK_README_KEY_CONCEPTS]. + +## Examples +The following sections provide several code snippets covering some of the most common scenarios, including: + +## Troubleshooting +Troubleshooting steps can be found [here][SDK_README_TROUBLESHOOTING]. + +## Next steps +See [Next steps][SDK_README_NEXT_STEPS]. + +## Contributing +This project welcomes contributions and suggestions. Find [more contributing][SDK_README_CONTRIBUTING] details here. + + +[SDK_README_CONTRIBUTING]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#contributing +[SDK_README_GETTING_STARTED]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#getting-started +[SDK_README_TROUBLESHOOTING]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#troubleshooting +[SDK_README_KEY_CONCEPTS]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#key-concepts +[SDK_README_NEXT_STEPS]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#next-steps + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-logingestion%2FREADME.png) diff --git a/sdk/monitor/azure-monitor-logingestion/swagger/README.md b/sdk/monitor/azure-monitor-logingestion/swagger/README.md new file mode 100644 index 0000000000000..21ccc105c9196 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/swagger/README.md @@ -0,0 +1,24 @@ +# Azure Logs Ingestion client library for Java + +## Code generation settings + +```yaml +java: true +use: '@autorest/java@4.0.54' +output-folder: ../ +license-header: MICROSOFT_MIT_SMALL +input-file: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/monitor/data-plane/ingestion/preview/2021-11-01-preview/DataCollectionRules.json +namespace: com.azure.monitor.logingestion +generate-client-interfaces: false +sync-methods: all +add-context-parameter: true +context-client-method-parameter: true +required-parameter-client-methods: false +generate-client-as-impl: true +models-subpackage: implementation.models +required-fields-as-ctor-args: true +model-override-setter-from-superclass: true +credential-types: tokencredential +client-side-validations: true +artifact-id: azure-monitor-logingestion +``` diff --git a/sdk/monitor/pom.xml b/sdk/monitor/pom.xml index a4058326a5ede..c191c4af91349 100644 --- a/sdk/monitor/pom.xml +++ b/sdk/monitor/pom.xml @@ -49,6 +49,7 @@ true + azure-monitor-logingestion azure-monitor-opentelemetry-exporter azure-monitor-query azure-monitor-query-perf From 4d4d928bc31ad00c96b7f32a00af67d11a30c71d Mon Sep 17 00:00:00 2001 From: Srikanta Date: Wed, 11 May 2022 16:30:11 -0700 Subject: [PATCH 02/14] test sending logs --- .../azure-monitor-logingestion/pom.xml | 8 +++- .../azure/monitor/logingestion/LogData.java | 46 +++++++++++++++++++ .../com/azure/monitor/logingestion/Main.java | 35 ++++++++++++++ ...onUsingDataCollectionRulesImplBuilder.java | 3 +- .../src/main/java/module-info.java | 4 ++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java create mode 100644 sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java diff --git a/sdk/monitor/azure-monitor-logingestion/pom.xml b/sdk/monitor/azure-monitor-logingestion/pom.xml index 9ee5a88e590c3..a7dde72c42a0d 100644 --- a/sdk/monitor/azure-monitor-logingestion/pom.xml +++ b/sdk/monitor/azure-monitor-logingestion/pom.xml @@ -10,7 +10,7 @@ 1.0.0-beta.1 jar - Microsoft Azure SDK for ${name} + Microsoft Azure SDK for Azure Logs Ingestion This package contains Microsoft Azure Logs Ingestion SDK. com.azure @@ -109,5 +109,11 @@ 1.4.6 test + + com.azure + azure-identity + 1.6.0-beta.1 + compile + diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java new file mode 100644 index 0000000000000..356ee38cd92e1 --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java @@ -0,0 +1,46 @@ +package com.azure.monitor.logingestion; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.time.OffsetDateTime; + +public class LogData { + + @JsonProperty(value = "Time") + private OffsetDateTime time; + + + @JsonProperty(value = "ExtendedColumn") + private String extendedColumn; + + + @JsonProperty(value = "AdditionalContext") + private String additionalContext; + + public OffsetDateTime getTime() { + return time; + } + + public LogData setTime(OffsetDateTime time) { + this.time = time; + return this; + } + + public String getExtendedColumn() { + return extendedColumn; + } + + public LogData setExtendedColumn(String extendedColumn) { + this.extendedColumn = extendedColumn; + return this; + } + + public String getAdditionalContext() { + return additionalContext; + } + + public LogData setAdditionalContext(String additionalContext) { + this.additionalContext = additionalContext; + return this; + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java new file mode 100644 index 0000000000000..275c19cdf84dd --- /dev/null +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java @@ -0,0 +1,35 @@ +package com.azure.monitor.logingestion; + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; +import com.azure.monitor.logingestion.implementation.DataCollectionRulesImpl; +import com.azure.monitor.logingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; +import com.azure.identity.DefaultAzureCredentialBuilder; + +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; + +public class Main { + + public static void main(String[] args) { + DataCollectionRulesImpl dataCollectionRules = new IngestionUsingDataCollectionRulesImplBuilder() + .credential(new DefaultAzureCredentialBuilder().build()) + .endpoint("https://srnagar-logsingestion-dcr-lrz3.westus2-1.ingest.monitor.azure.com") + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) + .buildClient() + .getDataCollectionRules(); + List dataList = new ArrayList<>(); + + dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("desktop").setAdditionalContext("new" + + "-desktop-log")); + dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("laptop").setAdditionalContext("more" + + "-laptop-log")); + + Response voidResponse = dataCollectionRules.ingestWithResponse("dcr-adec84661d05465f8532f32a04af6f98", + "Custom-MyTableRawData", dataList, "", "", Context.NONE); + System.out.println(voidResponse.getStatusCode()); + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java index 4dd8161c0f128..4dd34410fd1e8 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java @@ -280,7 +280,8 @@ private HttpPipeline createHttpPipeline() { policies.add(new AddDatePolicy()); policies.add(new CookiePolicy()); if (tokenCredential != null) { - policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, String.format("%s/.default", endpoint))); + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, "https://monitor.azure.com//.default" + /*String.format("%s/.default", endpoint)*/)); } policies.addAll( this.pipelinePolicies.stream() diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java index e72df0ff7df55..6fb7e5e4b7c30 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java +++ b/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java @@ -3,5 +3,9 @@ module com.azure.monitor.logingestion { requires transitive com.azure.core; + requires com.azure.identity; exports com.azure.monitor.logingestion; + + opens com.azure.monitor.logingestion to com.fasterxml.jackson.databind; + } From eeaa723c001fae7b07f6c1504bf567757365c969 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 26 May 2022 10:47:10 -0700 Subject: [PATCH 03/14] update package names --- .../CHANGELOG.md | 0 .../README.md | 0 .../pom.xml | 6 +- .../LogsIngestionAsyncClient.java | 9 ++ .../logsingestion/LogsIngestionClient.java | 8 + .../LogsIngestionClientBuilder.java | 137 ++++++++++++++++++ .../LogsIngestionServiceVersion.java | 33 +++++ .../DataCollectionRulesImpl.java | 4 +- ...IngestionUsingDataCollectionRulesImpl.java | 2 +- ...onUsingDataCollectionRulesImplBuilder.java | 2 +- .../models/ErrorAdditionalInfo.java | 2 +- .../implementation/models/ErrorDetail.java | 2 +- .../implementation/models/ErrorResponse.java | 2 +- .../models/ErrorResponseException.java | 2 +- .../implementation/models/package-info.java | 2 +- .../implementation/package-info.java | 2 +- .../monitor/logsingestion}/package-info.java | 2 +- .../src/main/java/module-info.java | 6 +- .../azure-monitor-logingestion.properties | 0 .../src/samples/README.md | 0 .../azure/monitor/logsingestion}/LogData.java | 2 +- .../LogsCollectionClientTest.java} | 12 +- .../swagger/README.md | 0 sdk/monitor/pom.xml | 2 +- 24 files changed, 213 insertions(+), 24 deletions(-) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/CHANGELOG.md (100%) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/README.md (100%) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/pom.xml (96%) create mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java create mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java create mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java create mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/DataCollectionRulesImpl.java (98%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/IngestionUsingDataCollectionRulesImpl.java (98%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/IngestionUsingDataCollectionRulesImplBuilder.java (99%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/models/ErrorAdditionalInfo.java (94%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/models/ErrorDetail.java (97%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/models/ErrorResponse.java (95%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/models/ErrorResponseException.java (95%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/models/package-info.java (79%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/implementation/package-info.java (81%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion}/package-info.java (72%) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/src/main/java/module-info.java (51%) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/src/main/resources/azure-monitor-logingestion.properties (100%) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/src/samples/README.md (100%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion => azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion}/LogData.java (95%) rename sdk/monitor/{azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java => azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java} (80%) rename sdk/monitor/{azure-monitor-logingestion => azure-monitor-dataingestion}/swagger/README.md (100%) diff --git a/sdk/monitor/azure-monitor-logingestion/CHANGELOG.md b/sdk/monitor/azure-monitor-dataingestion/CHANGELOG.md similarity index 100% rename from sdk/monitor/azure-monitor-logingestion/CHANGELOG.md rename to sdk/monitor/azure-monitor-dataingestion/CHANGELOG.md diff --git a/sdk/monitor/azure-monitor-logingestion/README.md b/sdk/monitor/azure-monitor-dataingestion/README.md similarity index 100% rename from sdk/monitor/azure-monitor-logingestion/README.md rename to sdk/monitor/azure-monitor-dataingestion/README.md diff --git a/sdk/monitor/azure-monitor-logingestion/pom.xml b/sdk/monitor/azure-monitor-dataingestion/pom.xml similarity index 96% rename from sdk/monitor/azure-monitor-logingestion/pom.xml rename to sdk/monitor/azure-monitor-dataingestion/pom.xml index a7dde72c42a0d..54c337520ff22 100644 --- a/sdk/monitor/azure-monitor-logingestion/pom.xml +++ b/sdk/monitor/azure-monitor-dataingestion/pom.xml @@ -6,11 +6,11 @@ 4.0.0 com.azure - azure-monitor-logingestion - 1.0.0-beta.1 + azure-monitor-dataingestion + 1.0.0-beta.1 jar - Microsoft Azure SDK for Azure Logs Ingestion + Microsoft Azure SDK for Azure Data Ingestion This package contains Microsoft Azure Logs Ingestion SDK. com.azure diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java new file mode 100644 index 0000000000000..2d133a21af56c --- /dev/null +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java @@ -0,0 +1,9 @@ +package com.azure.monitor.logsingestion; + +import com.azure.monitor.logsingestion.implementation.IngestionUsingDataCollectionRulesImpl; + +public final class LogsIngestionAsyncClient { + + LogsIngestionAsyncClient(IngestionUsingDataCollectionRulesImpl buildClient) { + } +} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java new file mode 100644 index 0000000000000..0af83c6720b76 --- /dev/null +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java @@ -0,0 +1,8 @@ +package com.azure.monitor.logsingestion; + +public final class LogsIngestionClient { + + LogsIngestionClient(LogsIngestionAsyncClient buildAsyncClient) { + + } +} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java new file mode 100644 index 0000000000000..f5761a8efc689 --- /dev/null +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java @@ -0,0 +1,137 @@ +package com.azure.monitor.logsingestion; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.logging.ClientLogger; +import com.azure.monitor.logsingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; + +public final class LogsIngestionClientBuilder { + private final ClientLogger logger = new ClientLogger(LogsIngestionClientBuilder.class); + private final IngestionUsingDataCollectionRulesImplBuilder innerLogBuilder = new IngestionUsingDataCollectionRulesImplBuilder(); + private ClientOptions clientOptions; + private LogsIngestionServiceVersion serviceVersion; + + /** + * Sets the log query endpoint. + * @param endpoint the host value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder endpoint(String endpoint) { + innerLogBuilder.endpoint(endpoint); + return this; + } + + /** + * Sets The HTTP pipeline to send requests through. + * @param pipeline the pipeline value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder pipeline(HttpPipeline pipeline) { + innerLogBuilder.pipeline(pipeline); + return this; + } + + /** + * Sets The HTTP client used to send the request. + * @param httpClient the httpClient value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder httpClient(HttpClient httpClient) { + innerLogBuilder.httpClient(httpClient); + return this; + } + + /** + * Sets The configuration store that is used during construction of the service client. + * @param configuration the configuration value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder configuration(Configuration configuration) { + innerLogBuilder.configuration(configuration); + return this; + } + + /** + * Sets The logging configuration for HTTP requests and responses. + * @param httpLogOptions the httpLogOptions value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + innerLogBuilder.httpLogOptions(httpLogOptions); + return this; + } + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * @param retryPolicy the retryPolicy value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder retryPolicy(RetryPolicy retryPolicy) { + innerLogBuilder.retryPolicy(retryPolicy); + return this; + } + + /** + * Adds a custom Http pipeline policy. + * @param customPolicy The custom Http pipeline policy to add. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + innerLogBuilder.addPolicy(customPolicy); + return this; + } + + /** + * Sets The TokenCredential used for authentication. + * @param tokenCredential the tokenCredential value. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) { + innerLogBuilder.credential(tokenCredential); + return this; + } + + /** + * Set the {@link ClientOptions} used for creating the client. + * @param clientOptions The {@link ClientOptions}. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /** + * The service version to use when creating the client. + * @param serviceVersion The {@link LogsIngestionServiceVersion}. + * @return the {@link LogsIngestionClientBuilder}. + */ + public LogsIngestionClientBuilder serviceVersion(LogsIngestionServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + + /** + * Creates a synchronous client with the configured options in this builder. + * @return A synchronous {@link LogsIngestionClient}. + */ + public LogsIngestionClient buildClient() { + return new LogsIngestionClient(buildAsyncClient()); + } + + /** + * Creates an asynchronous client with the configured options in this builder. + * @return An asynchronous {@link LogsIngestionAsyncClient}. + */ + public LogsIngestionAsyncClient buildAsyncClient() { + logger.info("Using service version " + this.serviceVersion); + return new LogsIngestionAsyncClient(innerLogBuilder.buildClient()); + } + +} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java new file mode 100644 index 0000000000000..36d5e54d029c4 --- /dev/null +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java @@ -0,0 +1,33 @@ +package com.azure.monitor.logsingestion; + +import com.azure.core.util.ServiceVersion; + +public enum LogsIngestionServiceVersion implements ServiceVersion { + /** + * Service version {@code v1}. + */ + V_1("v1"); + + String version; + + /** + * The service version. + * @param version The service version. + */ + LogsIngestionServiceVersion(String version) { + this.version = version; + } + + /** + * Returns the latest supported service version by this library. + * @return The latest supported service version by this library. + */ + public static LogsIngestionServiceVersion getLatest() { + return V_1; + } + + @Override + public String getVersion() { + return version; + } +} diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/DataCollectionRulesImpl.java similarity index 98% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/DataCollectionRulesImpl.java index 8c0b4990ca9a2..30823e1071a63 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/DataCollectionRulesImpl.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/DataCollectionRulesImpl.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation; +package com.azure.monitor.logsingestion.implementation; import com.azure.core.annotation.BodyParam; import com.azure.core.annotation.ExpectedResponses; @@ -20,7 +20,7 @@ import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; -import com.azure.monitor.logingestion.implementation.models.ErrorResponseException; +import com.azure.monitor.logsingestion.implementation.models.ErrorResponseException; import java.util.List; import reactor.core.publisher.Mono; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImpl.java similarity index 98% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImpl.java index 3a134fe77e5bf..6c16e5b63b3d1 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImpl.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImpl.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation; +package com.azure.monitor.logsingestion.implementation; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java similarity index 99% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java index 4dd34410fd1e8..f0206bf1a91eb 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation; +package com.azure.monitor.logsingestion.implementation; import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorAdditionalInfo.java similarity index 94% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorAdditionalInfo.java index 3d8bc5a2ebe39..71126dbdc3608 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorAdditionalInfo.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorAdditionalInfo.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation.models; +package com.azure.monitor.logsingestion.implementation.models; import com.azure.core.annotation.Immutable; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorDetail.java similarity index 97% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorDetail.java index f6db0837c9307..aac0835be2174 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorDetail.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorDetail.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation.models; +package com.azure.monitor.logsingestion.implementation.models; import com.azure.core.annotation.Immutable; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponse.java similarity index 95% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponse.java index 67287f1a72a7f..6903c592e1be9 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponse.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponse.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation.models; +package com.azure.monitor.logsingestion.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponseException.java similarity index 95% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponseException.java index da1b1ff3a8d62..306509084b105 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/ErrorResponseException.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponseException.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logingestion.implementation.models; +package com.azure.monitor.logsingestion.implementation.models; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpResponse; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/package-info.java similarity index 79% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/package-info.java index d9b1d48d04386..0d17eaa3d12e9 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/models/package-info.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/package-info.java @@ -3,4 +3,4 @@ // Code generated by Microsoft (R) AutoRest Code Generator. /** Package containing the data models for IngestionUsingDataCollectionRules. null. */ -package com.azure.monitor.logingestion.implementation.models; +package com.azure.monitor.logsingestion.implementation.models; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/package-info.java similarity index 81% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/package-info.java index 6c3bac712671b..f8e2c62096c3c 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/implementation/package-info.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/package-info.java @@ -3,4 +3,4 @@ // Code generated by Microsoft (R) AutoRest Code Generator. /** Package containing the implementations for IngestionUsingDataCollectionRules. null. */ -package com.azure.monitor.logingestion.implementation; +package com.azure.monitor.logsingestion.implementation; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/package-info.java similarity index 72% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/package-info.java index 81cc7afa5573b..49b31bd807758 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/package-info.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/package-info.java @@ -4,4 +4,4 @@ /** * */ -package com.azure.monitor.logingestion; +package com.azure.monitor.logsingestion; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java similarity index 51% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java rename to sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java index 6fb7e5e4b7c30..b0ddafca338dd 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/module-info.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -module com.azure.monitor.logingestion { +module com.azure.monitor.dataingestion { requires transitive com.azure.core; requires com.azure.identity; - exports com.azure.monitor.logingestion; + exports com.azure.monitor.logsingestion; - opens com.azure.monitor.logingestion to com.fasterxml.jackson.databind; + opens com.azure.monitor.logsingestion to com.fasterxml.jackson.databind; } diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/resources/azure-monitor-logingestion.properties b/sdk/monitor/azure-monitor-dataingestion/src/main/resources/azure-monitor-logingestion.properties similarity index 100% rename from sdk/monitor/azure-monitor-logingestion/src/main/resources/azure-monitor-logingestion.properties rename to sdk/monitor/azure-monitor-dataingestion/src/main/resources/azure-monitor-logingestion.properties diff --git a/sdk/monitor/azure-monitor-logingestion/src/samples/README.md b/sdk/monitor/azure-monitor-dataingestion/src/samples/README.md similarity index 100% rename from sdk/monitor/azure-monitor-logingestion/src/samples/README.md rename to sdk/monitor/azure-monitor-dataingestion/src/samples/README.md diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java b/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogData.java similarity index 95% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java rename to sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogData.java index 356ee38cd92e1..545cba3d21493 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/LogData.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogData.java @@ -1,4 +1,4 @@ -package com.azure.monitor.logingestion; +package com.azure.monitor.logsingestion; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java b/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java similarity index 80% rename from sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java rename to sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java index 275c19cdf84dd..e513e0570e001 100644 --- a/sdk/monitor/azure-monitor-logingestion/src/main/java/com/azure/monitor/logingestion/Main.java +++ b/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java @@ -1,20 +1,22 @@ -package com.azure.monitor.logingestion; +package com.azure.monitor.logsingestion; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; -import com.azure.monitor.logingestion.implementation.DataCollectionRulesImpl; -import com.azure.monitor.logingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.monitor.logsingestion.implementation.DataCollectionRulesImpl; +import com.azure.monitor.logsingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; +import org.junit.jupiter.api.Test; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.List; -public class Main { +public class LogsCollectionClientTest { - public static void main(String[] args) { + @Test + public void testSendLogs() { DataCollectionRulesImpl dataCollectionRules = new IngestionUsingDataCollectionRulesImplBuilder() .credential(new DefaultAzureCredentialBuilder().build()) .endpoint("https://srnagar-logsingestion-dcr-lrz3.westus2-1.ingest.monitor.azure.com") diff --git a/sdk/monitor/azure-monitor-logingestion/swagger/README.md b/sdk/monitor/azure-monitor-dataingestion/swagger/README.md similarity index 100% rename from sdk/monitor/azure-monitor-logingestion/swagger/README.md rename to sdk/monitor/azure-monitor-dataingestion/swagger/README.md diff --git a/sdk/monitor/pom.xml b/sdk/monitor/pom.xml index c191c4af91349..2c6f5f4bc81f0 100644 --- a/sdk/monitor/pom.xml +++ b/sdk/monitor/pom.xml @@ -49,7 +49,7 @@ true - azure-monitor-logingestion + azure-monitor-dataingestion azure-monitor-opentelemetry-exporter azure-monitor-query azure-monitor-query-perf From 373448c609c51e95df87a679f27a5f5bb23a0de1 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 2 Jun 2022 11:41:45 -0700 Subject: [PATCH 04/14] updated api view --- .../LogsIngestionAsyncClient.java | 9 ---- .../logsingestion/LogsIngestionClient.java | 8 --- .../src/main/java/module-info.java | 11 ---- .../CHANGELOG.md | 0 .../README.md | 6 +-- .../pom.xml | 14 ++---- .../ingestion/LogsIngestionAsyncClient.java | 50 +++++++++++++++++++ .../ingestion/LogsIngestionClient.java | 49 ++++++++++++++++++ .../LogsIngestionClientBuilder.java | 36 +++++++++++-- .../LogsIngestionServiceVersion.java | 5 +- .../DataCollectionRulesImpl.java | 4 +- ...IngestionUsingDataCollectionRulesImpl.java | 2 +- ...onUsingDataCollectionRulesImplBuilder.java | 2 +- .../models/ErrorAdditionalInfo.java | 2 +- .../implementation/models/ErrorDetail.java | 2 +- .../implementation/models/ErrorResponse.java | 2 +- .../models/ErrorResponseException.java | 2 +- .../implementation/models/package-info.java | 2 +- .../implementation/package-info.java | 2 +- .../ingestion/models/SendLogsError.java | 41 +++++++++++++++ .../ingestion/models/SendLogsOptions.java | 42 ++++++++++++++++ .../ingestion/models/SendLogsResult.java | 27 ++++++++++ .../ingestion/models/SendLogsStatus.java | 10 ++++ .../ingestion/models/package-info.java | 7 +++ .../monitor/ingestion}/package-info.java | 2 +- .../src/main/java/module-info.java | 11 ++++ .../azure-monitor-logingestion.properties | 0 .../src/samples/README.md | 0 .../com/azure/monitor/ingestion}/LogData.java | 2 +- .../ingestion}/LogsCollectionClientTest.java | 25 ++++++++-- .../swagger/README.md | 2 +- sdk/monitor/pom.xml | 2 +- 32 files changed, 316 insertions(+), 63 deletions(-) delete mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java delete mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java delete mode 100644 sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java rename sdk/monitor/{azure-monitor-dataingestion => azure-monitor-ingestion}/CHANGELOG.md (100%) rename sdk/monitor/{azure-monitor-dataingestion => azure-monitor-ingestion}/README.md (90%) rename sdk/monitor/{azure-monitor-dataingestion => azure-monitor-ingestion}/pom.xml (90%) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/LogsIngestionClientBuilder.java (81%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/LogsIngestionServiceVersion.java (93%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/DataCollectionRulesImpl.java (98%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/IngestionUsingDataCollectionRulesImpl.java (98%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/IngestionUsingDataCollectionRulesImplBuilder.java (99%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/models/ErrorAdditionalInfo.java (94%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/models/ErrorDetail.java (97%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/models/ErrorResponse.java (95%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/models/ErrorResponseException.java (95%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/models/package-info.java (79%) rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/implementation/package-info.java (81%) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java rename sdk/monitor/{azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion}/package-info.java (72%) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java rename sdk/monitor/{azure-monitor-dataingestion => azure-monitor-ingestion}/src/main/resources/azure-monitor-logingestion.properties (100%) rename sdk/monitor/{azure-monitor-dataingestion => azure-monitor-ingestion}/src/samples/README.md (100%) rename sdk/monitor/{azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion}/LogData.java (95%) rename sdk/monitor/{azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion => azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion}/LogsCollectionClientTest.java (56%) rename sdk/monitor/{azure-monitor-dataingestion => azure-monitor-ingestion}/swagger/README.md (94%) diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java deleted file mode 100644 index 2d133a21af56c..0000000000000 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionAsyncClient.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.azure.monitor.logsingestion; - -import com.azure.monitor.logsingestion.implementation.IngestionUsingDataCollectionRulesImpl; - -public final class LogsIngestionAsyncClient { - - LogsIngestionAsyncClient(IngestionUsingDataCollectionRulesImpl buildClient) { - } -} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java deleted file mode 100644 index 0af83c6720b76..0000000000000 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClient.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.azure.monitor.logsingestion; - -public final class LogsIngestionClient { - - LogsIngestionClient(LogsIngestionAsyncClient buildAsyncClient) { - - } -} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java deleted file mode 100644 index b0ddafca338dd..0000000000000 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/module-info.java +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -module com.azure.monitor.dataingestion { - requires transitive com.azure.core; - requires com.azure.identity; - exports com.azure.monitor.logsingestion; - - opens com.azure.monitor.logsingestion to com.fasterxml.jackson.databind; - -} diff --git a/sdk/monitor/azure-monitor-dataingestion/CHANGELOG.md b/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md similarity index 100% rename from sdk/monitor/azure-monitor-dataingestion/CHANGELOG.md rename to sdk/monitor/azure-monitor-ingestion/CHANGELOG.md diff --git a/sdk/monitor/azure-monitor-dataingestion/README.md b/sdk/monitor/azure-monitor-ingestion/README.md similarity index 90% rename from sdk/monitor/azure-monitor-dataingestion/README.md rename to sdk/monitor/azure-monitor-ingestion/README.md index 0e974d1fbbe9e..b59423b914e8b 100644 --- a/sdk/monitor/azure-monitor-dataingestion/README.md +++ b/sdk/monitor/azure-monitor-ingestion/README.md @@ -1,4 +1,4 @@ -# Azure Logs Ingestion client library for Java +# Azure Monitor Data Ingestion client library for Java ## Getting started @@ -8,11 +8,11 @@ ### Include the package -[//]: # ({x-version-update-start;com.azure:azure-monitor-logingestion;current}) +[//]: # ({x-version-update-start;com.azure:azure-monitor-ingestion;current}) ```xml com.azure - azure-monitor-logingestion + azure-monitor-ingestion 1.0.0-beta.1 ``` diff --git a/sdk/monitor/azure-monitor-dataingestion/pom.xml b/sdk/monitor/azure-monitor-ingestion/pom.xml similarity index 90% rename from sdk/monitor/azure-monitor-dataingestion/pom.xml rename to sdk/monitor/azure-monitor-ingestion/pom.xml index 54c337520ff22..b68e6ba32b115 100644 --- a/sdk/monitor/azure-monitor-dataingestion/pom.xml +++ b/sdk/monitor/azure-monitor-ingestion/pom.xml @@ -6,12 +6,12 @@ 4.0.0 com.azure - azure-monitor-dataingestion + azure-monitor-ingestion 1.0.0-beta.1 jar - Microsoft Azure SDK for Azure Data Ingestion - This package contains Microsoft Azure Logs Ingestion SDK. + Microsoft Azure SDK for Azure Monitor Data Ingestion + This package contains Microsoft Azure Monitor Data Ingestion SDK. com.azure azure-client-sdk-parent @@ -106,14 +106,8 @@ com.azure azure-identity - 1.4.6 + 1.5.1 test - - com.azure - azure-identity - 1.6.0-beta.1 - compile - diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java new file mode 100644 index 0000000000000..fdf285e0b2d87 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java @@ -0,0 +1,50 @@ +package com.azure.monitor.ingestion; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; +import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesImpl; +import com.azure.monitor.ingestion.models.SendLogsOptions; +import com.azure.monitor.ingestion.models.SendLogsResult; +import reactor.core.publisher.Mono; + +import java.util.List; + +/** + * + */ +@ServiceClient(isAsync = true, builder = LogsIngestionClientBuilder.class) +public final class LogsIngestionAsyncClient { + + LogsIngestionAsyncClient(IngestionUsingDataCollectionRulesImpl innerClient) { + } + + /** + * @param dataCollectionRuleId + * @param streamDeclaration + * @param logs + * @param options + * @param context + * @param + * @return + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> sendLogsWithResponse(String dataCollectionRuleId, String streamDeclaration, + List logs, SendLogsOptions options, Context context) { + return Mono.empty(); + } + + /** + * @param dataCollectionRuleId + * @param streamDeclaration + * @param logs + * @param + * @return + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono sendLogs(String dataCollectionRuleId, String streamDeclaration, List logs) { + return Mono.empty(); + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java new file mode 100644 index 0000000000000..8e05d55111bf8 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java @@ -0,0 +1,49 @@ +package com.azure.monitor.ingestion; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; +import com.azure.monitor.ingestion.models.SendLogsOptions; +import com.azure.monitor.ingestion.models.SendLogsResult; + +import java.util.List; + +/** + * + */ +@ServiceClient(builder = LogsIngestionClientBuilder.class) +public final class LogsIngestionClient { + + LogsIngestionClient(LogsIngestionAsyncClient asyncClient) { + + } + + /** + * @param dataCollectionRuleId + * @param streamDeclaration + * @param logs + * @param options + * @param context + * @param + * @return + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response sendLogsWithResponse(String dataCollectionRuleId, String streamDeclaration, + List logs, SendLogsOptions options, Context context) { + return null; + } + + /** + * @param dataCollectionRuleId + * @param streamDeclaration + * @param logs + * @param + * @return + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SendLogsResult sendLogs(String dataCollectionRuleId, String streamDeclaration, List logs) { + return null; + } +} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java similarity index 81% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java index f5761a8efc689..753fd910e2086 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionClientBuilder.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java @@ -1,17 +1,28 @@ -package com.azure.monitor.logsingestion; +package com.azure.monitor.ingestion; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.client.traits.TokenCredentialTrait; import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.RetryOptions; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.util.ClientOptions; import com.azure.core.util.Configuration; import com.azure.core.util.logging.ClientLogger; -import com.azure.monitor.logsingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; +import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; -public final class LogsIngestionClientBuilder { +/** + * + */ +@ServiceClientBuilder(serviceClients = {LogsIngestionClient.class, LogsIngestionAsyncClient.class}) +public final class LogsIngestionClientBuilder implements ConfigurationTrait, + HttpTrait, EndpointTrait, TokenCredentialTrait { private final ClientLogger logger = new ClientLogger(LogsIngestionClientBuilder.class); private final IngestionUsingDataCollectionRulesImplBuilder innerLogBuilder = new IngestionUsingDataCollectionRulesImplBuilder(); private ClientOptions clientOptions; @@ -22,6 +33,7 @@ public final class LogsIngestionClientBuilder { * @param endpoint the host value. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder endpoint(String endpoint) { innerLogBuilder.endpoint(endpoint); return this; @@ -32,6 +44,7 @@ public LogsIngestionClientBuilder endpoint(String endpoint) { * @param pipeline the pipeline value. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder pipeline(HttpPipeline pipeline) { innerLogBuilder.pipeline(pipeline); return this; @@ -42,6 +55,7 @@ public LogsIngestionClientBuilder pipeline(HttpPipeline pipeline) { * @param httpClient the httpClient value. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder httpClient(HttpClient httpClient) { innerLogBuilder.httpClient(httpClient); return this; @@ -52,6 +66,7 @@ public LogsIngestionClientBuilder httpClient(HttpClient httpClient) { * @param configuration the configuration value. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder configuration(Configuration configuration) { innerLogBuilder.configuration(configuration); return this; @@ -62,6 +77,7 @@ public LogsIngestionClientBuilder configuration(Configuration configuration) { * @param httpLogOptions the httpLogOptions value. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { innerLogBuilder.httpLogOptions(httpLogOptions); return this; @@ -82,16 +98,27 @@ public LogsIngestionClientBuilder retryPolicy(RetryPolicy retryPolicy) { * @param customPolicy The custom Http pipeline policy to add. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { innerLogBuilder.addPolicy(customPolicy); return this; } + /** + * @param retryOptions + * @return + */ + @Override + public LogsIngestionClientBuilder retryOptions(RetryOptions retryOptions) { + return this; + } + /** * Sets The TokenCredential used for authentication. * @param tokenCredential the tokenCredential value. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) { innerLogBuilder.credential(tokenCredential); return this; @@ -102,6 +129,7 @@ public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) { * @param clientOptions The {@link ClientOptions}. * @return the {@link LogsIngestionClientBuilder}. */ + @Override public LogsIngestionClientBuilder clientOptions(ClientOptions clientOptions) { this.clientOptions = clientOptions; return this; @@ -133,5 +161,5 @@ public LogsIngestionAsyncClient buildAsyncClient() { logger.info("Using service version " + this.serviceVersion); return new LogsIngestionAsyncClient(innerLogBuilder.buildClient()); } - + } diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java similarity index 93% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java index 36d5e54d029c4..bef34319904c2 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/LogsIngestionServiceVersion.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java @@ -1,7 +1,10 @@ -package com.azure.monitor.logsingestion; +package com.azure.monitor.ingestion; import com.azure.core.util.ServiceVersion; +/** + * + */ public enum LogsIngestionServiceVersion implements ServiceVersion { /** * Service version {@code v1}. diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/DataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java similarity index 98% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/DataCollectionRulesImpl.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java index 30823e1071a63..25cc04f3e8519 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/DataCollectionRulesImpl.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation; +package com.azure.monitor.ingestion.implementation; import com.azure.core.annotation.BodyParam; import com.azure.core.annotation.ExpectedResponses; @@ -20,7 +20,7 @@ import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; -import com.azure.monitor.logsingestion.implementation.models.ErrorResponseException; +import com.azure.monitor.ingestion.implementation.models.ErrorResponseException; import java.util.List; import reactor.core.publisher.Mono; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java similarity index 98% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImpl.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java index 6c16e5b63b3d1..8397f1279d009 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImpl.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation; +package com.azure.monitor.ingestion.implementation; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java similarity index 99% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java index f0206bf1a91eb..8ab8ca25eb590 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation; +package com.azure.monitor.ingestion.implementation; import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorAdditionalInfo.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java similarity index 94% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorAdditionalInfo.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java index 71126dbdc3608..115f59fa8e856 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorAdditionalInfo.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation.models; +package com.azure.monitor.ingestion.implementation.models; import com.azure.core.annotation.Immutable; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorDetail.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java similarity index 97% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorDetail.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java index aac0835be2174..5409060a367e5 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorDetail.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation.models; +package com.azure.monitor.ingestion.implementation.models; import com.azure.core.annotation.Immutable; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponse.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java similarity index 95% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponse.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java index 6903c592e1be9..52fb1c05cb964 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponse.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation.models; +package com.azure.monitor.ingestion.implementation.models; import com.azure.core.annotation.Fluent; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponseException.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java similarity index 95% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponseException.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java index 306509084b105..c1ff559a1495f 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/ErrorResponseException.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java @@ -2,7 +2,7 @@ // Licensed under the MIT License. // Code generated by Microsoft (R) AutoRest Code Generator. -package com.azure.monitor.logsingestion.implementation.models; +package com.azure.monitor.ingestion.implementation.models; import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpResponse; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java similarity index 79% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/package-info.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java index 0d17eaa3d12e9..0b7698942fc98 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/models/package-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java @@ -3,4 +3,4 @@ // Code generated by Microsoft (R) AutoRest Code Generator. /** Package containing the data models for IngestionUsingDataCollectionRules. null. */ -package com.azure.monitor.logsingestion.implementation.models; +package com.azure.monitor.ingestion.implementation.models; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java similarity index 81% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/package-info.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java index f8e2c62096c3c..137f159e77795 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/implementation/package-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/package-info.java @@ -3,4 +3,4 @@ // Code generated by Microsoft (R) AutoRest Code Generator. /** Package containing the implementations for IngestionUsingDataCollectionRules. null. */ -package com.azure.monitor.logsingestion.implementation; +package com.azure.monitor.ingestion.implementation; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java new file mode 100644 index 0000000000000..2a0c0d7d7e859 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java @@ -0,0 +1,41 @@ +package com.azure.monitor.ingestion.models; + +import com.azure.core.models.ResponseError; + +import java.util.List; + +/** + * + */ +public class SendLogsError { + private ResponseError responseError; + private List failedLogsIndex; + + /** + * @return + */ + public ResponseError getResponseError() { + return responseError; + } + + /** + * @param responseError + */ + public void setResponseError(ResponseError responseError) { + this.responseError = responseError; + } + + /** + * @return + */ + public List getFailedLogsIndex() { + return failedLogsIndex; + } + + /** + * @param failedLogsIndex + */ + public void setFailedLogsIndex(List failedLogsIndex) { + this.failedLogsIndex = failedLogsIndex; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java new file mode 100644 index 0000000000000..a6825498bdee3 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java @@ -0,0 +1,42 @@ +package com.azure.monitor.ingestion.models; + +import com.azure.core.util.serializer.ObjectSerializer; + +/** + * + */ +public final class SendLogsOptions { + + private ObjectSerializer objectSerializer; + private Integer maxConcurrency; + + /** + * @return + */ + public ObjectSerializer getObjectSerializer() { + return objectSerializer; + } + + /** + * @param objectSerializer + */ + public SendLogsOptions setObjectSerializer(ObjectSerializer objectSerializer) { + this.objectSerializer = objectSerializer; + return this; + } + + /** + * @return + */ + public Integer getMaxConcurrency() { + return maxConcurrency; + } + + /** + * @param maxConcurrency + */ + public SendLogsOptions setMaxConcurrency(Integer maxConcurrency) { + this.maxConcurrency = maxConcurrency; + return this; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java new file mode 100644 index 0000000000000..dbc5229a1d30d --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java @@ -0,0 +1,27 @@ +package com.azure.monitor.ingestion.models; + +import java.util.List; + +/** + * + */ +public final class SendLogsResult { + + SendLogsResult() { + + } + + /** + * @return + */ + public SendLogsStatus getStatus() { + return SendLogsStatus.SUCCESS; + } + + /** + * @return + */ + public List getErrors() { + return null; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java new file mode 100644 index 0000000000000..e07251655cfac --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java @@ -0,0 +1,10 @@ +package com.azure.monitor.ingestion.models; + +/** + * + */ +public enum SendLogsStatus { + SUCCESS, + + PARTIAL_FAILURE; +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java new file mode 100644 index 0000000000000..ea9291d5c5174 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * + */ +package com.azure.monitor.ingestion.models; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java similarity index 72% rename from sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/package-info.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java index 49b31bd807758..af0c66571f1fd 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/main/java/com/azure/monitor/logsingestion/package-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java @@ -4,4 +4,4 @@ /** * */ -package com.azure.monitor.logsingestion; +package com.azure.monitor.ingestion; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java new file mode 100644 index 0000000000000..8138ac0f1b3b9 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +module com.azure.monitor.ingestion { + requires transitive com.azure.core; + exports com.azure.monitor.ingestion; + exports com.azure.monitor.ingestion.models; + + opens com.azure.monitor.ingestion to com.fasterxml.jackson.databind; + +} diff --git a/sdk/monitor/azure-monitor-dataingestion/src/main/resources/azure-monitor-logingestion.properties b/sdk/monitor/azure-monitor-ingestion/src/main/resources/azure-monitor-logingestion.properties similarity index 100% rename from sdk/monitor/azure-monitor-dataingestion/src/main/resources/azure-monitor-logingestion.properties rename to sdk/monitor/azure-monitor-ingestion/src/main/resources/azure-monitor-logingestion.properties diff --git a/sdk/monitor/azure-monitor-dataingestion/src/samples/README.md b/sdk/monitor/azure-monitor-ingestion/src/samples/README.md similarity index 100% rename from sdk/monitor/azure-monitor-dataingestion/src/samples/README.md rename to sdk/monitor/azure-monitor-ingestion/src/samples/README.md diff --git a/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogData.java b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogData.java similarity index 95% rename from sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogData.java rename to sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogData.java index 545cba3d21493..5e8dc1e46e852 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogData.java +++ b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogData.java @@ -1,4 +1,4 @@ -package com.azure.monitor.logsingestion; +package com.azure.monitor.ingestion; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java similarity index 56% rename from sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java rename to sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java index e513e0570e001..21df659619c0f 100644 --- a/sdk/monitor/azure-monitor-dataingestion/src/test/java/com/azure/monitor/logsingestion/LogsCollectionClientTest.java +++ b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java @@ -1,12 +1,13 @@ -package com.azure.monitor.logsingestion; +package com.azure.monitor.ingestion; import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.monitor.logsingestion.implementation.DataCollectionRulesImpl; -import com.azure.monitor.logsingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; +import com.azure.monitor.ingestion.implementation.DataCollectionRulesImpl; +import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; +import com.azure.monitor.ingestion.models.SendLogsResult; import org.junit.jupiter.api.Test; import java.time.OffsetDateTime; @@ -34,4 +35,22 @@ public void testSendLogs() { "Custom-MyTableRawData", dataList, "", "", Context.NONE); System.out.println(voidResponse.getStatusCode()); } + + @Test + public void testSendLogsFromClient() { + LogsIngestionClient logsIngestionClient = new LogsIngestionClientBuilder() + .credential(new DefaultAzureCredentialBuilder().build()) + .endpoint("https://srnagar-logsingestion-dcr-lrz3.westus2-1.ingest.monitor.azure.com") + .buildClient(); + + List dataList = new ArrayList<>(); + + dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("desktop").setAdditionalContext("new" + + "-desktop-log")); + dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("laptop").setAdditionalContext("more" + + "-laptop-log")); + + SendLogsResult response = logsIngestionClient.sendLogs("dcr-adec84661d05465f8532f32a04af6f98", "Custom-MyTableRawData", dataList); + System.out.println(response.getStatus()); + } } diff --git a/sdk/monitor/azure-monitor-dataingestion/swagger/README.md b/sdk/monitor/azure-monitor-ingestion/swagger/README.md similarity index 94% rename from sdk/monitor/azure-monitor-dataingestion/swagger/README.md rename to sdk/monitor/azure-monitor-ingestion/swagger/README.md index 21ccc105c9196..d61348fc5e1f4 100644 --- a/sdk/monitor/azure-monitor-dataingestion/swagger/README.md +++ b/sdk/monitor/azure-monitor-ingestion/swagger/README.md @@ -8,7 +8,7 @@ use: '@autorest/java@4.0.54' output-folder: ../ license-header: MICROSOFT_MIT_SMALL input-file: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/monitor/data-plane/ingestion/preview/2021-11-01-preview/DataCollectionRules.json -namespace: com.azure.monitor.logingestion +namespace: com.azure.monitor.ingestion generate-client-interfaces: false sync-methods: all add-context-parameter: true diff --git a/sdk/monitor/pom.xml b/sdk/monitor/pom.xml index 2c6f5f4bc81f0..60f6690852517 100644 --- a/sdk/monitor/pom.xml +++ b/sdk/monitor/pom.xml @@ -49,7 +49,7 @@ true - azure-monitor-dataingestion + azure-monitor-ingestion azure-monitor-opentelemetry-exporter azure-monitor-query azure-monitor-query-perf From 06f7c8cbebd94f5c12f2dc9c23ed35fd626caaae Mon Sep 17 00:00:00 2001 From: Srikanta Date: Mon, 13 Jun 2022 10:04:58 -0700 Subject: [PATCH 05/14] updates --- .../ingestion/LogsIngestionAsyncClient.java | 188 +++++++++- .../ingestion/LogsIngestionClient.java | 25 +- .../ingestion/LogsIngestionClientBuilder.java | 12 +- .../DataCollectionRulesImpl.java | 251 ------------- .../implementation/DefaultJsonSerializer.java | 84 +++++ ...onUsingDataCollectionRulesAsyncClient.java | 71 ++++ ...gestionUsingDataCollectionRulesClient.java | 70 ++++ ...singDataCollectionRulesClientBuilder.java} | 120 ++++--- ...ionUsingDataCollectionRulesClientImpl.java | 329 ++++++++++++++++++ ...IngestionUsingDataCollectionRulesImpl.java | 127 ------- ...singDataCollectionRulesServiceVersion.java | 33 ++ .../models/ErrorAdditionalInfo.java | 49 --- .../implementation/models/ErrorDetail.java | 102 ------ .../implementation/models/ErrorResponse.java | 52 --- .../models/ErrorResponseException.java | 37 -- .../implementation/models/package-info.java | 6 - .../ingestion/models/SendLogsError.java | 41 --- .../ingestion/models/SendLogsResult.java | 27 -- .../ingestion/models/UploadLogsError.java | 34 ++ ...ogsOptions.java => UploadLogsOptions.java} | 9 +- .../ingestion/models/UploadLogsResult.java | 34 ++ ...dLogsStatus.java => UploadLogsStatus.java} | 6 +- .../azure/monitor/ingestion/package-info.java | 5 +- .../src/main/java/module-info.java | 5 +- .../ingestion/LogsCollectionClientTest.java | 49 +-- .../azure-monitor-ingestion/swagger/README.md | 3 +- 26 files changed, 936 insertions(+), 833 deletions(-) delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java rename sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/{IngestionUsingDataCollectionRulesImplBuilder.java => IngestionUsingDataCollectionRulesClientBuilder.java} (69%) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java rename sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/{SendLogsOptions.java => UploadLogsOptions.java} (73%) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java rename sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/{SendLogsStatus.java => UploadLogsStatus.java} (52%) diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java index fdf285e0b2d87..b284ccbc9096c 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java @@ -3,48 +3,204 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.http.rest.Response; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.models.ResponseError; +import com.azure.core.util.BinaryData; import com.azure.core.util.Context; -import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesImpl; -import com.azure.monitor.ingestion.models.SendLogsOptions; -import com.azure.monitor.ingestion.models.SendLogsResult; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.monitor.ingestion.implementation.DefaultJsonSerializer; +import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesAsyncClient; +import com.azure.monitor.ingestion.models.UploadLogsError; +import com.azure.monitor.ingestion.models.UploadLogsOptions; +import com.azure.monitor.ingestion.models.UploadLogsResult; +import com.azure.monitor.ingestion.models.UploadLogsStatus; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.zip.GZIPOutputStream; + +import static com.azure.core.util.FluxUtil.monoError; +import static com.azure.core.util.FluxUtil.withContext; /** * */ @ServiceClient(isAsync = true, builder = LogsIngestionClientBuilder.class) public final class LogsIngestionAsyncClient { + private static final ClientLogger LOGGER = new ClientLogger(LogsIngestionAsyncClient.class); + private static final String CONTENT_ENCODING = "Content-Encoding"; + private static final long ONE_MB = 1024 * 1024; + private static final String GZIP = "gzip"; + + private final IngestionUsingDataCollectionRulesAsyncClient service; - LogsIngestionAsyncClient(IngestionUsingDataCollectionRulesImpl innerClient) { + LogsIngestionAsyncClient(IngestionUsingDataCollectionRulesAsyncClient service) { + this.service = service; } /** * @param dataCollectionRuleId - * @param streamDeclaration + * @param streamName * @param logs - * @param options - * @param context - * @param * @return */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> sendLogsWithResponse(String dataCollectionRuleId, String streamDeclaration, - List logs, SendLogsOptions options, Context context) { - return Mono.empty(); + public Mono upload(String dataCollectionRuleId, String streamName, List logs) { + return upload(dataCollectionRuleId, streamName, logs, new UploadLogsOptions()); } /** * @param dataCollectionRuleId - * @param streamDeclaration + * @param streamName * @param logs - * @param + * @param options * @return */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono sendLogs(String dataCollectionRuleId, String streamDeclaration, List logs) { - return Mono.empty(); + public Mono upload(String dataCollectionRuleId, String streamName, + List logs, UploadLogsOptions options) { + return withContext(context -> upload(dataCollectionRuleId, streamName, logs, options,context)); + } + + Mono upload(String dataCollectionRuleId, String streamName, + List logs, UploadLogsOptions options, + Context context) { + return Mono.defer(() -> splitAndUpload(dataCollectionRuleId, streamName, logs, options, context)); + } + + private Mono splitAndUpload(String dataCollectionRuleId, String streamName, List logs, UploadLogsOptions options, Context context) { + try { + Objects.requireNonNull(dataCollectionRuleId, "'dataCollectionRuleId' cannot be null."); + Objects.requireNonNull(dataCollectionRuleId, "'streamName' cannot be null."); + Objects.requireNonNull(dataCollectionRuleId, "'logs' cannot be null."); + + if (logs.isEmpty()) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException("'logs' cannot be empty.")); + } + + // TODO (srnagar): Move DefaultJsonSerializer in azure-core to public package + ObjectSerializer serializer = new DefaultJsonSerializer(); + + // set concurrency to 1 as default + int concurrency = 1; + if (options != null) { + if (options.getObjectSerializer() != null) { + serializer = options.getObjectSerializer(); + } + if (options.getMaxConcurrency() != null) { + concurrency = options.getMaxConcurrency(); + } + } + + List> logBatches = new ArrayList<>(); + List requests = createGzipRequests(logs, serializer, logBatches); + RequestOptions requestOptions = new RequestOptions() + .addHeader(CONTENT_ENCODING, GZIP) + .setContext(context); + + Iterator> logBatchesIterator = logBatches.iterator(); + return Flux.fromIterable(requests) + .flatMapSequential(bytes -> service.uploadWithResponse(dataCollectionRuleId, streamName, + BinaryData.fromBytes(bytes), requestOptions), + concurrency) + .map(response -> { + logBatchesIterator.next(); + return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); + }) + .onErrorResume(HttpResponseException.class, + ex -> Mono.just(new UploadLogsResult(UploadLogsStatus.FAILURE, + Arrays.asList(new UploadLogsError((ResponseError) ex.getValue(), + logBatchesIterator.next()))))) + .collectList() + .map(this::createResponse); + } catch (RuntimeException ex) { + return monoError(LOGGER, ex); + } + } + + private UploadLogsResult createResponse(List results) { + boolean allErrors = results.stream().allMatch(result -> result.getStatus() == UploadLogsStatus.FAILURE); + if (allErrors) { + return new UploadLogsResult(UploadLogsStatus.FAILURE, + results.stream().flatMap(result -> result.getErrors().stream()).collect(Collectors.toList())); + } + + boolean anyErrors = results.stream().anyMatch(result -> result.getStatus() == UploadLogsStatus.FAILURE); + if (anyErrors) { + return new UploadLogsResult(UploadLogsStatus.PARTIAL_FAILURE, + results.stream().filter(result -> result.getStatus() == UploadLogsStatus.FAILURE) + .flatMap(result -> result.getErrors().stream()).collect(Collectors.toList())); + } + return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); + } + + private List createGzipRequests(List logs, ObjectSerializer serializer, + List> logBatches) { + try { + List requests = new ArrayList<>(); + long currentBatchSize = 0; + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + + JsonGenerator generator = JsonFactory.builder().build().createGenerator(byteArrayOutputStream); + generator.writeStartArray(); + List serializedLogs = new ArrayList<>(); + + int currentBatchStart = 0; + for (int i = 0; i < logs.size(); i++) { + byte[] bytes = serializer.serializeToBytes(logs.get(i)); + int currentLogSize = bytes.length; + currentBatchSize += currentLogSize; + if (currentBatchSize > ONE_MB) { + generator.writeRaw(serializedLogs.stream() + .collect(Collectors.joining(","))); + generator.writeEndArray(); + generator.close(); + requests.add(gzipRequest(byteArrayOutputStream.toByteArray())); + + byteArrayOutputStream = new ByteArrayOutputStream(); + generator = JsonFactory.builder().build().createGenerator(byteArrayOutputStream); + generator.writeStartArray(); + currentBatchSize = currentLogSize; + serializedLogs.clear(); + logBatches.add(logs.subList(currentBatchStart, i)); + currentBatchStart = i; + } + serializedLogs.add(new String(bytes)); + } + if (currentBatchSize > 0) { + generator.writeRaw(serializedLogs.stream() + .collect(Collectors.joining(","))); + generator.writeEndArray(); + generator.close(); + requests.add(gzipRequest(byteArrayOutputStream.toByteArray())); + logBatches.add(logs.subList(currentBatchStart, logs.size())); + } + return requests; + } catch (IOException exception) { + throw LOGGER.logExceptionAsError(new UncheckedIOException(exception)); + } + } + + private byte[] gzipRequest(byte[] bytes) { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream zip = new GZIPOutputStream(byteArrayOutputStream)) { + zip.write(bytes); + } catch (IOException exception) { + throw new UncheckedIOException(exception); + } + return byteArrayOutputStream.toByteArray(); } } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java index 8e05d55111bf8..6b0773eb82d5a 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java @@ -3,10 +3,9 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.http.rest.Response; import com.azure.core.util.Context; -import com.azure.monitor.ingestion.models.SendLogsOptions; -import com.azure.monitor.ingestion.models.SendLogsResult; +import com.azure.monitor.ingestion.models.UploadLogsOptions; +import com.azure.monitor.ingestion.models.UploadLogsResult; import java.util.List; @@ -16,34 +15,34 @@ @ServiceClient(builder = LogsIngestionClientBuilder.class) public final class LogsIngestionClient { - LogsIngestionClient(LogsIngestionAsyncClient asyncClient) { + private final LogsIngestionAsyncClient asyncClient; + LogsIngestionClient(LogsIngestionAsyncClient asyncClient) { + this.asyncClient = asyncClient; } /** * @param dataCollectionRuleId - * @param streamDeclaration + * @param streamName * @param logs * @param options * @param context - * @param * @return */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response sendLogsWithResponse(String dataCollectionRuleId, String streamDeclaration, - List logs, SendLogsOptions options, Context context) { - return null; + public UploadLogsResult upload(String dataCollectionRuleId, String streamName, + List logs, UploadLogsOptions options, Context context) { + return asyncClient.upload(dataCollectionRuleId, streamName, logs, options, context).block(); } /** * @param dataCollectionRuleId - * @param streamDeclaration + * @param streamName * @param logs - * @param * @return */ @ServiceMethod(returns = ReturnType.SINGLE) - public SendLogsResult sendLogs(String dataCollectionRuleId, String streamDeclaration, List logs) { - return null; + public UploadLogsResult upload(String dataCollectionRuleId, String streamName, List logs) { + return upload(dataCollectionRuleId, streamName, logs); } } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java index 753fd910e2086..c8ce1656d7339 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java @@ -15,7 +15,7 @@ import com.azure.core.util.ClientOptions; import com.azure.core.util.Configuration; import com.azure.core.util.logging.ClientLogger; -import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; +import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesClientBuilder; /** * @@ -24,8 +24,8 @@ public final class LogsIngestionClientBuilder implements ConfigurationTrait, HttpTrait, EndpointTrait, TokenCredentialTrait { private final ClientLogger logger = new ClientLogger(LogsIngestionClientBuilder.class); - private final IngestionUsingDataCollectionRulesImplBuilder innerLogBuilder = new IngestionUsingDataCollectionRulesImplBuilder(); - private ClientOptions clientOptions; + private final IngestionUsingDataCollectionRulesClientBuilder innerLogBuilder = + new IngestionUsingDataCollectionRulesClientBuilder(); private LogsIngestionServiceVersion serviceVersion; /** @@ -110,6 +110,7 @@ public LogsIngestionClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { */ @Override public LogsIngestionClientBuilder retryOptions(RetryOptions retryOptions) { + innerLogBuilder.retryOptions(retryOptions); return this; } @@ -131,7 +132,7 @@ public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) { */ @Override public LogsIngestionClientBuilder clientOptions(ClientOptions clientOptions) { - this.clientOptions = clientOptions; + innerLogBuilder.clientOptions(clientOptions); return this; } @@ -158,8 +159,7 @@ public LogsIngestionClient buildClient() { * @return An asynchronous {@link LogsIngestionAsyncClient}. */ public LogsIngestionAsyncClient buildAsyncClient() { - logger.info("Using service version " + this.serviceVersion); - return new LogsIngestionAsyncClient(innerLogBuilder.buildClient()); + return new LogsIngestionAsyncClient(innerLogBuilder.buildAsyncClient()); } } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java deleted file mode 100644 index 25cc04f3e8519..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DataCollectionRulesImpl.java +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.monitor.ingestion.implementation; - -import com.azure.core.annotation.BodyParam; -import com.azure.core.annotation.ExpectedResponses; -import com.azure.core.annotation.HeaderParam; -import com.azure.core.annotation.Host; -import com.azure.core.annotation.HostParam; -import com.azure.core.annotation.PathParam; -import com.azure.core.annotation.Post; -import com.azure.core.annotation.QueryParam; -import com.azure.core.annotation.ReturnType; -import com.azure.core.annotation.ServiceInterface; -import com.azure.core.annotation.ServiceMethod; -import com.azure.core.annotation.UnexpectedResponseExceptionType; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.RestProxy; -import com.azure.core.util.Context; -import com.azure.core.util.FluxUtil; -import com.azure.monitor.ingestion.implementation.models.ErrorResponseException; -import java.util.List; -import reactor.core.publisher.Mono; - -/** An instance of this class provides access to all the operations defined in DataCollectionRules. */ -public final class DataCollectionRulesImpl { - /** The proxy service used to perform REST calls. */ - private final DataCollectionRulesService service; - - /** The service client containing this operation class. */ - private final IngestionUsingDataCollectionRulesImpl client; - - /** - * Initializes an instance of DataCollectionRulesImpl. - * - * @param client the instance of the service client containing this operation class. - */ - DataCollectionRulesImpl(IngestionUsingDataCollectionRulesImpl client) { - this.service = - RestProxy.create( - DataCollectionRulesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); - this.client = client; - } - - /** - * The interface defining all the services for IngestionUsingDataCollectionRulesDataCollectionRules to be used by - * the proxy service to perform REST calls. - */ - @Host("{endpoint}") - @ServiceInterface(name = "IngestionUsingDataCo") - private interface DataCollectionRulesService { - @Post("/dataCollectionRules/{ruleId}/streams/{stream}") - @ExpectedResponses({204}) - @UnexpectedResponseExceptionType(ErrorResponseException.class) - Mono> ingest( - @HostParam("endpoint") String endpoint, - @PathParam("ruleId") String ruleId, - @PathParam("stream") String stream, - @QueryParam("api-version") String apiVersion, - @HeaderParam("Content-Encoding") String contentEncoding, - @HeaderParam("x-ms-client-request-id") String xMsClientRequestId, - @BodyParam("application/json") List body, - @HeaderParam("Accept") String accept, - Context context); - } - - /** - * See error response code and error response message for more detail. - * - * @param ruleId The immutable Id of the Data Collection Rule resource. - * @param stream The streamDeclaration name as defined in the Data Collection Rule. - * @param body An array of objects matching the schema defined by the provided stream. - * @param contentEncoding gzip. - * @param xMsClientRequestId Client request Id. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> ingestWithResponseAsync( - String ruleId, String stream, List body, String contentEncoding, String xMsClientRequestId) { - if (this.client.getEndpoint() == null) { - return Mono.error( - new IllegalArgumentException( - "Parameter this.client.getEndpoint() is required and cannot be null.")); - } - if (ruleId == null) { - return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null.")); - } - if (stream == null) { - return Mono.error(new IllegalArgumentException("Parameter stream is required and cannot be null.")); - } - if (body == null) { - return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); - } - final String accept = "application/json"; - return FluxUtil.withContext( - context -> - service.ingest( - this.client.getEndpoint(), - ruleId, - stream, - this.client.getApiVersion(), - contentEncoding, - xMsClientRequestId, - body, - accept, - context)); - } - - /** - * See error response code and error response message for more detail. - * - * @param ruleId The immutable Id of the Data Collection Rule resource. - * @param stream The streamDeclaration name as defined in the Data Collection Rule. - * @param body An array of objects matching the schema defined by the provided stream. - * @param contentEncoding gzip. - * @param xMsClientRequestId Client request Id. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response} on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> ingestWithResponseAsync( - String ruleId, - String stream, - List body, - String contentEncoding, - String xMsClientRequestId, - Context context) { - if (this.client.getEndpoint() == null) { - return Mono.error( - new IllegalArgumentException( - "Parameter this.client.getEndpoint() is required and cannot be null.")); - } - if (ruleId == null) { - return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null.")); - } - if (stream == null) { - return Mono.error(new IllegalArgumentException("Parameter stream is required and cannot be null.")); - } - if (body == null) { - return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); - } - final String accept = "application/json"; - return service.ingest( - this.client.getEndpoint(), - ruleId, - stream, - this.client.getApiVersion(), - contentEncoding, - xMsClientRequestId, - body, - accept, - context); - } - - /** - * See error response code and error response message for more detail. - * - * @param ruleId The immutable Id of the Data Collection Rule resource. - * @param stream The streamDeclaration name as defined in the Data Collection Rule. - * @param body An array of objects matching the schema defined by the provided stream. - * @param contentEncoding gzip. - * @param xMsClientRequestId Client request Id. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono ingestAsync( - String ruleId, String stream, List body, String contentEncoding, String xMsClientRequestId) { - return ingestWithResponseAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId) - .flatMap((Response res) -> Mono.empty()); - } - - /** - * See error response code and error response message for more detail. - * - * @param ruleId The immutable Id of the Data Collection Rule resource. - * @param stream The streamDeclaration name as defined in the Data Collection Rule. - * @param body An array of objects matching the schema defined by the provided stream. - * @param contentEncoding gzip. - * @param xMsClientRequestId Client request Id. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return A {@link Mono} that completes when a successful response is received. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono ingestAsync( - String ruleId, - String stream, - List body, - String contentEncoding, - String xMsClientRequestId, - Context context) { - return ingestWithResponseAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId, context) - .flatMap((Response res) -> Mono.empty()); - } - - /** - * See error response code and error response message for more detail. - * - * @param ruleId The immutable Id of the Data Collection Rule resource. - * @param stream The streamDeclaration name as defined in the Data Collection Rule. - * @param body An array of objects matching the schema defined by the provided stream. - * @param contentEncoding gzip. - * @param xMsClientRequestId Client request Id. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public void ingest( - String ruleId, String stream, List body, String contentEncoding, String xMsClientRequestId) { - ingestAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId).block(); - } - - /** - * See error response code and error response message for more detail. - * - * @param ruleId The immutable Id of the Data Collection Rule resource. - * @param stream The streamDeclaration name as defined in the Data Collection Rule. - * @param body An array of objects matching the schema defined by the provided stream. - * @param contentEncoding gzip. - * @param xMsClientRequestId Client request Id. - * @param context The context to associate with this operation. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws ErrorResponseException thrown if the request is rejected by server. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the {@link Response}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Response ingestWithResponse( - String ruleId, - String stream, - List body, - String contentEncoding, - String xMsClientRequestId, - Context context) { - return ingestWithResponseAsync(ruleId, stream, body, contentEncoding, xMsClientRequestId, context).block(); - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java new file mode 100644 index 0000000000000..9dad455b93b08 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.ingestion.implementation; + +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.JsonSerializer; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import com.azure.core.util.serializer.TypeReference; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UncheckedIOException; + +/** + * Jackson based implementation of the {@link JsonSerializer}. This can be used as a default Json serializer if + * no JsonSerializerProvider is in the class path. + */ +public final class DefaultJsonSerializer implements JsonSerializer { + // DefaultJsonSerializer is a commonly used class, use a static logger. + private static final ClientLogger LOGGER = new ClientLogger(DefaultJsonSerializer.class); + + private final SerializerAdapter jacksonAdapter = JacksonAdapter.createDefaultSerializerAdapter(); + + @Override + public T deserializeFromBytes(byte[] data, TypeReference typeReference) { + try { + return jacksonAdapter.deserialize(data, typeReference.getJavaType(), SerializerEncoding.JSON); + } catch (IOException e) { + throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); + } + } + + @Override + public T deserialize(InputStream stream, TypeReference typeReference) { + try { + return jacksonAdapter.deserialize(stream, typeReference.getJavaType(), SerializerEncoding.JSON); + } catch (IOException e) { + throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); + } + } + + @Override + public Mono deserializeFromBytesAsync(byte[] data, TypeReference typeReference) { + return Mono.fromCallable(() -> deserializeFromBytes(data, typeReference)); + } + + @Override + public Mono deserializeAsync(InputStream stream, TypeReference typeReference) { + return Mono.fromCallable(() -> deserialize(stream, typeReference)); + } + + @Override + public byte[] serializeToBytes(Object value) { + try { + return jacksonAdapter.serializeToBytes(value, SerializerEncoding.JSON); + } catch (IOException e) { + throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); + } + } + + @Override + public void serialize(OutputStream stream, Object value) { + try { + jacksonAdapter.serialize(value, SerializerEncoding.JSON, stream); + } catch (IOException e) { + throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); + } + } + + @Override + public Mono serializeToBytesAsync(Object value) { + return Mono.fromCallable(() -> serializeToBytes(value)); + } + + @Override + public Mono serializeAsync(OutputStream stream, Object value) { + return Mono.fromRunnable(() -> serialize(stream, value)); + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java new file mode 100644 index 0000000000000..9825922d53899 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesAsyncClient.java @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.ingestion.implementation; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import reactor.core.publisher.Mono; + +/** Initializes a new instance of the asynchronous IngestionUsingDataCollectionRulesClient type. */ +@ServiceClient(builder = IngestionUsingDataCollectionRulesClientBuilder.class, isAsync = true) +public final class IngestionUsingDataCollectionRulesAsyncClient { + @Generated private final IngestionUsingDataCollectionRulesClientImpl serviceClient; + + /** + * Initializes an instance of IngestionUsingDataCollectionRulesAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + IngestionUsingDataCollectionRulesAsyncClient(IngestionUsingDataCollectionRulesClientImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * See error response code and error response message for more detail. + * + *

Header Parameters + * + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-EncodingStringNogzip
x-ms-client-request-idStringNoClient request Id
+ * + *

Request Body Schema + * + *

{@code
+     * [
+     *     Object
+     * ]
+     * }
+ * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> uploadWithResponse( + String ruleId, String stream, BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.uploadWithResponseAsync(ruleId, stream, body, requestOptions); + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java new file mode 100644 index 0000000000000..2c523b018f796 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClient.java @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.ingestion.implementation; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; + +/** Initializes a new instance of the synchronous IngestionUsingDataCollectionRulesClient type. */ +@ServiceClient(builder = IngestionUsingDataCollectionRulesClientBuilder.class) +public final class IngestionUsingDataCollectionRulesClient { + @Generated private final IngestionUsingDataCollectionRulesAsyncClient client; + + /** + * Initializes an instance of IngestionUsingDataCollectionRulesClient class. + * + * @param client the async client. + */ + @Generated + IngestionUsingDataCollectionRulesClient(IngestionUsingDataCollectionRulesAsyncClient client) { + this.client = client; + } + + /** + * See error response code and error response message for more detail. + * + *

Header Parameters + * + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-EncodingStringNogzip
x-ms-client-request-idStringNoClient request Id
+ * + *

Request Body Schema + * + *

{@code
+     * [
+     *     Object
+     * ]
+     * }
+ * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response uploadWithResponse( + String ruleId, String stream, BinaryData body, RequestOptions requestOptions) { + return this.client.uploadWithResponse(ruleId, stream, body, requestOptions).block(); + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java similarity index 69% rename from sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java index 8ab8ca25eb590..387decaf0bd49 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImplBuilder.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java @@ -34,19 +34,23 @@ import com.azure.core.util.CoreUtils; import com.azure.core.util.builder.ClientBuilderUtil; import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -/** A builder for creating a new instance of the IngestionUsingDataCollectionRules type. */ -@ServiceClientBuilder(serviceClients = {IngestionUsingDataCollectionRulesImpl.class}) -public final class IngestionUsingDataCollectionRulesImplBuilder - implements HttpTrait, - ConfigurationTrait, - TokenCredentialTrait, - EndpointTrait { +/** A builder for creating a new instance of the IngestionUsingDataCollectionRulesClient type. */ +@ServiceClientBuilder( + serviceClients = { + IngestionUsingDataCollectionRulesClient.class, + IngestionUsingDataCollectionRulesAsyncClient.class + }) +public final class IngestionUsingDataCollectionRulesClientBuilder + implements HttpTrait, + ConfigurationTrait, + TokenCredentialTrait, + EndpointTrait { @Generated private static final String SDK_NAME = "name"; @Generated private static final String SDK_VERSION = "version"; @@ -56,9 +60,9 @@ public final class IngestionUsingDataCollectionRulesImplBuilder @Generated private final List pipelinePolicies; - /** Create an instance of the IngestionUsingDataCollectionRulesImplBuilder. */ + /** Create an instance of the IngestionUsingDataCollectionRulesClientBuilder. */ @Generated - public IngestionUsingDataCollectionRulesImplBuilder() { + public IngestionUsingDataCollectionRulesClientBuilder() { this.pipelinePolicies = new ArrayList<>(); } @@ -70,7 +74,7 @@ public IngestionUsingDataCollectionRulesImplBuilder() { /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder pipeline(HttpPipeline pipeline) { + public IngestionUsingDataCollectionRulesClientBuilder pipeline(HttpPipeline pipeline) { this.pipeline = pipeline; return this; } @@ -83,7 +87,7 @@ public IngestionUsingDataCollectionRulesImplBuilder pipeline(HttpPipeline pipeli /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder httpClient(HttpClient httpClient) { + public IngestionUsingDataCollectionRulesClientBuilder httpClient(HttpClient httpClient) { this.httpClient = httpClient; return this; } @@ -96,7 +100,7 @@ public IngestionUsingDataCollectionRulesImplBuilder httpClient(HttpClient httpCl /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + public IngestionUsingDataCollectionRulesClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { this.httpLogOptions = httpLogOptions; return this; } @@ -110,7 +114,7 @@ public IngestionUsingDataCollectionRulesImplBuilder httpLogOptions(HttpLogOption /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder clientOptions(ClientOptions clientOptions) { + public IngestionUsingDataCollectionRulesClientBuilder clientOptions(ClientOptions clientOptions) { this.clientOptions = clientOptions; return this; } @@ -123,7 +127,7 @@ public IngestionUsingDataCollectionRulesImplBuilder clientOptions(ClientOptions /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder retryOptions(RetryOptions retryOptions) { + public IngestionUsingDataCollectionRulesClientBuilder retryOptions(RetryOptions retryOptions) { this.retryOptions = retryOptions; return this; } @@ -131,7 +135,7 @@ public IngestionUsingDataCollectionRulesImplBuilder retryOptions(RetryOptions re /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder addPolicy(HttpPipelinePolicy customPolicy) { + public IngestionUsingDataCollectionRulesClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { pipelinePolicies.add(customPolicy); return this; } @@ -145,7 +149,7 @@ public IngestionUsingDataCollectionRulesImplBuilder addPolicy(HttpPipelinePolicy /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder configuration(Configuration configuration) { + public IngestionUsingDataCollectionRulesClientBuilder configuration(Configuration configuration) { this.configuration = configuration; return this; } @@ -158,7 +162,7 @@ public IngestionUsingDataCollectionRulesImplBuilder configuration(Configuration /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder credential(TokenCredential tokenCredential) { + public IngestionUsingDataCollectionRulesClientBuilder credential(TokenCredential tokenCredential) { this.tokenCredential = tokenCredential; return this; } @@ -171,42 +175,26 @@ public IngestionUsingDataCollectionRulesImplBuilder credential(TokenCredential t /** {@inheritDoc}. */ @Generated @Override - public IngestionUsingDataCollectionRulesImplBuilder endpoint(String endpoint) { + public IngestionUsingDataCollectionRulesClientBuilder endpoint(String endpoint) { this.endpoint = endpoint; return this; } /* - * Api Version - */ - @Generated private String apiVersion; - - /** - * Sets Api Version. - * - * @param apiVersion the apiVersion value. - * @return the IngestionUsingDataCollectionRulesImplBuilder. - */ - @Generated - public IngestionUsingDataCollectionRulesImplBuilder apiVersion(String apiVersion) { - this.apiVersion = apiVersion; - return this; - } - - /* - * The serializer to serialize an object into a string + * Service version */ - @Generated private SerializerAdapter serializerAdapter; + @Generated private IngestionUsingDataCollectionRulesServiceVersion serviceVersion; /** - * Sets The serializer to serialize an object into a string. + * Sets Service version. * - * @param serializerAdapter the serializerAdapter value. - * @return the IngestionUsingDataCollectionRulesImplBuilder. + * @param serviceVersion the serviceVersion value. + * @return the IngestionUsingDataCollectionRulesClientBuilder. */ @Generated - public IngestionUsingDataCollectionRulesImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) { - this.serializerAdapter = serializerAdapter; + public IngestionUsingDataCollectionRulesClientBuilder serviceVersion( + IngestionUsingDataCollectionRulesServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; return this; } @@ -220,32 +208,30 @@ public IngestionUsingDataCollectionRulesImplBuilder serializerAdapter(Serializer * Sets The retry policy that will attempt to retry failed requests, if applicable. * * @param retryPolicy the retryPolicy value. - * @return the IngestionUsingDataCollectionRulesImplBuilder. + * @return the IngestionUsingDataCollectionRulesClientBuilder. */ @Generated - public IngestionUsingDataCollectionRulesImplBuilder retryPolicy(RetryPolicy retryPolicy) { + public IngestionUsingDataCollectionRulesClientBuilder retryPolicy(RetryPolicy retryPolicy) { this.retryPolicy = retryPolicy; return this; } /** - * Builds an instance of IngestionUsingDataCollectionRulesImpl with the provided parameters. + * Builds an instance of IngestionUsingDataCollectionRulesClientImpl with the provided parameters. * - * @return an instance of IngestionUsingDataCollectionRulesImpl. + * @return an instance of IngestionUsingDataCollectionRulesClientImpl. */ @Generated - public IngestionUsingDataCollectionRulesImpl buildClient() { + private IngestionUsingDataCollectionRulesClientImpl buildInnerClient() { if (pipeline == null) { this.pipeline = createHttpPipeline(); } - if (apiVersion == null) { - this.apiVersion = "2021-11-01-preview"; - } - if (serializerAdapter == null) { - this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); + if (serviceVersion == null) { + this.serviceVersion = IngestionUsingDataCollectionRulesServiceVersion.getLatest(); } - IngestionUsingDataCollectionRulesImpl client = - new IngestionUsingDataCollectionRulesImpl(pipeline, serializerAdapter, endpoint, apiVersion); + IngestionUsingDataCollectionRulesClientImpl client = + new IngestionUsingDataCollectionRulesClientImpl( + pipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); return client; } @@ -280,8 +266,7 @@ private HttpPipeline createHttpPipeline() { policies.add(new AddDatePolicy()); policies.add(new CookiePolicy()); if (tokenCredential != null) { - policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, "https://monitor.azure.com//.default" - /*String.format("%s/.default", endpoint)*/)); + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential,"https://monitor.azure.com//.default")); } policies.addAll( this.pipelinePolicies.stream() @@ -297,4 +282,25 @@ private HttpPipeline createHttpPipeline() { .build(); return httpPipeline; } + + /** + * Builds an instance of IngestionUsingDataCollectionRulesAsyncClient class. + * + * @return an instance of IngestionUsingDataCollectionRulesAsyncClient. + */ + @Generated + public IngestionUsingDataCollectionRulesAsyncClient buildAsyncClient() { + return new IngestionUsingDataCollectionRulesAsyncClient(buildInnerClient()); + } + + /** + * Builds an instance of IngestionUsingDataCollectionRulesClient class. + * + * @return an instance of IngestionUsingDataCollectionRulesClient. + */ + @Generated + public IngestionUsingDataCollectionRulesClient buildClient() { + return new IngestionUsingDataCollectionRulesClient( + new IngestionUsingDataCollectionRulesAsyncClient(buildInnerClient())); + } } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java new file mode 100644 index 0000000000000..6f7b5c2377e0e --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientImpl.java @@ -0,0 +1,329 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.ingestion.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.CookiePolicy; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import reactor.core.publisher.Mono; + +/** Initializes a new instance of the IngestionUsingDataCollectionRulesClient type. */ +public final class IngestionUsingDataCollectionRulesClientImpl { + /** The proxy service used to perform REST calls. */ + private final IngestionUsingDataCollectionRulesClientService service; + + /** + * The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + */ + private final String endpoint; + + /** + * Gets The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** Service version. */ + private final IngestionUsingDataCollectionRulesServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public IngestionUsingDataCollectionRulesServiceVersion getServiceVersion() { + return this.serviceVersion; + } + + /** The HTTP pipeline to send requests through. */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** The serializer to serialize an object into a string. */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * Initializes an instance of IngestionUsingDataCollectionRulesClient client. + * + * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * @param serviceVersion Service version. + */ + public IngestionUsingDataCollectionRulesClientImpl( + String endpoint, IngestionUsingDataCollectionRulesServiceVersion serviceVersion) { + this( + new HttpPipelineBuilder() + .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) + .build(), + JacksonAdapter.createDefaultSerializerAdapter(), + endpoint, + serviceVersion); + } + + /** + * Initializes an instance of IngestionUsingDataCollectionRulesClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * @param serviceVersion Service version. + */ + public IngestionUsingDataCollectionRulesClientImpl( + HttpPipeline httpPipeline, + String endpoint, + IngestionUsingDataCollectionRulesServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of IngestionUsingDataCollectionRulesClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example + * https://dce-name.eastus-2.ingest.monitor.azure.com. + * @param serviceVersion Service version. + */ + public IngestionUsingDataCollectionRulesClientImpl( + HttpPipeline httpPipeline, + SerializerAdapter serializerAdapter, + String endpoint, + IngestionUsingDataCollectionRulesServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.serviceVersion = serviceVersion; + this.service = + RestProxy.create( + IngestionUsingDataCollectionRulesClientService.class, + this.httpPipeline, + this.getSerializerAdapter()); + } + + /** + * The interface defining all the services for IngestionUsingDataCollectionRulesClient to be used by the proxy + * service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "IngestionUsingDataCo") + private interface IngestionUsingDataCollectionRulesClientService { + @Post("/dataCollectionRules/{ruleId}/streams/{stream}") + @ExpectedResponses({204}) + @UnexpectedResponseExceptionType( + value = ClientAuthenticationException.class, + code = {401}) + @UnexpectedResponseExceptionType( + value = ResourceNotFoundException.class, + code = {404}) + @UnexpectedResponseExceptionType( + value = ResourceModifiedException.class, + code = {409}) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> upload( + @HostParam("endpoint") String endpoint, + @PathParam("ruleId") String ruleId, + @PathParam("stream") String stream, + @QueryParam("api-version") String apiVersion, + @BodyParam("application/json") BinaryData body, + @HeaderParam("Accept") String accept, + RequestOptions requestOptions, + Context context); + } + + /** + * See error response code and error response message for more detail. + * + *

Header Parameters + * + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-EncodingStringNogzip
x-ms-client-request-idStringNoClient request Id
+ * + *

Request Body Schema + * + *

{@code
+     * [
+     *     Object
+     * ]
+     * }
+ * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> uploadWithResponseAsync( + String ruleId, String stream, BinaryData body, RequestOptions requestOptions) { + if (ruleId == null) { + return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null.")); + } + if (stream == null) { + return Mono.error(new IllegalArgumentException("Parameter stream is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext( + context -> + service.upload( + this.getEndpoint(), + ruleId, + stream, + this.getServiceVersion().getVersion(), + body, + accept, + requestOptions, + context)); + } + + /** + * See error response code and error response message for more detail. + * + *

Header Parameters + * + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-EncodingStringNogzip
x-ms-client-request-idStringNoClient request Id
+ * + *

Request Body Schema + * + *

{@code
+     * [
+     *     Object
+     * ]
+     * }
+ * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @param context The context to associate with this operation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> uploadWithResponseAsync( + String ruleId, String stream, BinaryData body, RequestOptions requestOptions, Context context) { + if (ruleId == null) { + return Mono.error(new IllegalArgumentException("Parameter ruleId is required and cannot be null.")); + } + if (stream == null) { + return Mono.error(new IllegalArgumentException("Parameter stream is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } + final String accept = "application/json"; + return service.upload( + this.getEndpoint(), + ruleId, + stream, + this.getServiceVersion().getVersion(), + body, + accept, + requestOptions, + context); + } + + /** + * See error response code and error response message for more detail. + * + *

Header Parameters + * + * + * + * + * + * + *
Header Parameters
NameTypeRequiredDescription
Content-EncodingStringNogzip
x-ms-client-request-idStringNoClient request Id
+ * + *

Request Body Schema + * + *

{@code
+     * [
+     *     Object
+     * ]
+     * }
+ * + * @param ruleId The immutable Id of the Data Collection Rule resource. + * @param stream The streamDeclaration name as defined in the Data Collection Rule. + * @param body An array of objects matching the schema defined by the provided stream. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response uploadWithResponse( + String ruleId, String stream, BinaryData body, RequestOptions requestOptions) { + return uploadWithResponseAsync(ruleId, stream, body, requestOptions).block(); + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java deleted file mode 100644 index 8397f1279d009..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesImpl.java +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.monitor.ingestion.implementation; - -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.policy.CookiePolicy; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; - -/** Initializes a new instance of the IngestionUsingDataCollectionRules type. */ -public final class IngestionUsingDataCollectionRulesImpl { - /** - * The Data Collection Endpoint for the Data Collection Rule, for example - * https://dce-name.eastus-2.ingest.monitor.azure.com. - */ - private final String endpoint; - - /** - * Gets The Data Collection Endpoint for the Data Collection Rule, for example - * https://dce-name.eastus-2.ingest.monitor.azure.com. - * - * @return the endpoint value. - */ - public String getEndpoint() { - return this.endpoint; - } - - /** Api Version. */ - private final String apiVersion; - - /** - * Gets Api Version. - * - * @return the apiVersion value. - */ - public String getApiVersion() { - return this.apiVersion; - } - - /** The HTTP pipeline to send requests through. */ - private final HttpPipeline httpPipeline; - - /** - * Gets The HTTP pipeline to send requests through. - * - * @return the httpPipeline value. - */ - public HttpPipeline getHttpPipeline() { - return this.httpPipeline; - } - - /** The serializer to serialize an object into a string. */ - private final SerializerAdapter serializerAdapter; - - /** - * Gets The serializer to serialize an object into a string. - * - * @return the serializerAdapter value. - */ - public SerializerAdapter getSerializerAdapter() { - return this.serializerAdapter; - } - - /** The DataCollectionRulesImpl object to access its operations. */ - private final DataCollectionRulesImpl dataCollectionRules; - - /** - * Gets the DataCollectionRulesImpl object to access its operations. - * - * @return the DataCollectionRulesImpl object. - */ - public DataCollectionRulesImpl getDataCollectionRules() { - return this.dataCollectionRules; - } - - /** - * Initializes an instance of IngestionUsingDataCollectionRules client. - * - * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example - * https://dce-name.eastus-2.ingest.monitor.azure.com. - * @param apiVersion Api Version. - */ - IngestionUsingDataCollectionRulesImpl(String endpoint, String apiVersion) { - this( - new HttpPipelineBuilder() - .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) - .build(), - JacksonAdapter.createDefaultSerializerAdapter(), - endpoint, - apiVersion); - } - - /** - * Initializes an instance of IngestionUsingDataCollectionRules client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example - * https://dce-name.eastus-2.ingest.monitor.azure.com. - * @param apiVersion Api Version. - */ - IngestionUsingDataCollectionRulesImpl(HttpPipeline httpPipeline, String endpoint, String apiVersion) { - this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion); - } - - /** - * Initializes an instance of IngestionUsingDataCollectionRules client. - * - * @param httpPipeline The HTTP pipeline to send requests through. - * @param serializerAdapter The serializer to serialize an object into a string. - * @param endpoint The Data Collection Endpoint for the Data Collection Rule, for example - * https://dce-name.eastus-2.ingest.monitor.azure.com. - * @param apiVersion Api Version. - */ - IngestionUsingDataCollectionRulesImpl( - HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, String apiVersion) { - this.httpPipeline = httpPipeline; - this.serializerAdapter = serializerAdapter; - this.endpoint = endpoint; - this.apiVersion = apiVersion; - this.dataCollectionRules = new DataCollectionRulesImpl(this); - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java new file mode 100644 index 0000000000000..a8663a99ae48d --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesServiceVersion.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.monitor.ingestion.implementation; + +import com.azure.core.util.ServiceVersion; + +/** Service version of IngestionUsingDataCollectionRulesClient. */ +public enum IngestionUsingDataCollectionRulesServiceVersion implements ServiceVersion { + /** Enum value 2021-11-01-preview. */ + V2021_11_01_PREVIEW("2021-11-01-preview"); + + private final String version; + + IngestionUsingDataCollectionRulesServiceVersion(String version) { + this.version = version; + } + + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link IngestionUsingDataCollectionRulesServiceVersion}. + */ + public static IngestionUsingDataCollectionRulesServiceVersion getLatest() { + return V2021_11_01_PREVIEW; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java deleted file mode 100644 index 115f59fa8e856..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorAdditionalInfo.java +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.monitor.ingestion.implementation.models; - -import com.azure.core.annotation.Immutable; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** The resource management error additional info. */ -@Immutable -public final class ErrorAdditionalInfo { - /* - * The additional info type. - */ - @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) - private String type; - - /* - * The additional info. - */ - @JsonProperty(value = "info", access = JsonProperty.Access.WRITE_ONLY) - private Object info; - - /** - * Get the type property: The additional info type. - * - * @return the type value. - */ - public String getType() { - return this.type; - } - - /** - * Get the info property: The additional info. - * - * @return the info value. - */ - public Object getInfo() { - return this.info; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() {} -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java deleted file mode 100644 index 5409060a367e5..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorDetail.java +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.monitor.ingestion.implementation.models; - -import com.azure.core.annotation.Immutable; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; - -/** The error detail. */ -@Immutable -public final class ErrorDetail { - /* - * The error code. - */ - @JsonProperty(value = "code", access = JsonProperty.Access.WRITE_ONLY) - private String code; - - /* - * The error message. - */ - @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) - private String message; - - /* - * The error target. - */ - @JsonProperty(value = "target", access = JsonProperty.Access.WRITE_ONLY) - private String target; - - /* - * The error details. - */ - @JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY) - private List details; - - /* - * The error additional info. - */ - @JsonProperty(value = "additionalInfo", access = JsonProperty.Access.WRITE_ONLY) - private List additionalInfo; - - /** - * Get the code property: The error code. - * - * @return the code value. - */ - public String getCode() { - return this.code; - } - - /** - * Get the message property: The error message. - * - * @return the message value. - */ - public String getMessage() { - return this.message; - } - - /** - * Get the target property: The error target. - * - * @return the target value. - */ - public String getTarget() { - return this.target; - } - - /** - * Get the details property: The error details. - * - * @return the details value. - */ - public List getDetails() { - return this.details; - } - - /** - * Get the additionalInfo property: The error additional info. - * - * @return the additionalInfo value. - */ - public List getAdditionalInfo() { - return this.additionalInfo; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getDetails() != null) { - getDetails().forEach(e -> e.validate()); - } - if (getAdditionalInfo() != null) { - getAdditionalInfo().forEach(e -> e.validate()); - } - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java deleted file mode 100644 index 52fb1c05cb964..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponse.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.monitor.ingestion.implementation.models; - -import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Error response Common error response for all Azure Resource Manager APIs to return error details for failed - * operations. (This also follows the OData error response format.). - */ -@Fluent -public final class ErrorResponse { - /* - * The error object. - */ - @JsonProperty(value = "error") - private ErrorDetail error; - - /** - * Get the error property: The error object. - * - * @return the error value. - */ - public ErrorDetail getError() { - return this.error; - } - - /** - * Set the error property: The error object. - * - * @param error the error value to set. - * @return the ErrorResponse object itself. - */ - public ErrorResponse setError(ErrorDetail error) { - this.error = error; - return this; - } - - /** - * Validates the instance. - * - * @throws IllegalArgumentException thrown if the instance is not valid. - */ - public void validate() { - if (getError() != null) { - getError().validate(); - } - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java deleted file mode 100644 index c1ff559a1495f..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/ErrorResponseException.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -package com.azure.monitor.ingestion.implementation.models; - -import com.azure.core.exception.HttpResponseException; -import com.azure.core.http.HttpResponse; - -/** Exception thrown for an invalid response with ErrorResponse information. */ -public final class ErrorResponseException extends HttpResponseException { - /** - * Initializes a new instance of the ErrorResponseException class. - * - * @param message the exception message or the response content if a message is not available. - * @param response the HTTP response. - */ - public ErrorResponseException(String message, HttpResponse response) { - super(message, response); - } - - /** - * Initializes a new instance of the ErrorResponseException class. - * - * @param message the exception message or the response content if a message is not available. - * @param response the HTTP response. - * @param value the deserialized response value. - */ - public ErrorResponseException(String message, HttpResponse response, ErrorResponse value) { - super(message, response, value); - } - - @Override - public ErrorResponse getValue() { - return (ErrorResponse) super.getValue(); - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java deleted file mode 100644 index 0b7698942fc98..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/models/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. - -/** Package containing the data models for IngestionUsingDataCollectionRules. null. */ -package com.azure.monitor.ingestion.implementation.models; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java deleted file mode 100644 index 2a0c0d7d7e859..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsError.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.azure.monitor.ingestion.models; - -import com.azure.core.models.ResponseError; - -import java.util.List; - -/** - * - */ -public class SendLogsError { - private ResponseError responseError; - private List failedLogsIndex; - - /** - * @return - */ - public ResponseError getResponseError() { - return responseError; - } - - /** - * @param responseError - */ - public void setResponseError(ResponseError responseError) { - this.responseError = responseError; - } - - /** - * @return - */ - public List getFailedLogsIndex() { - return failedLogsIndex; - } - - /** - * @param failedLogsIndex - */ - public void setFailedLogsIndex(List failedLogsIndex) { - this.failedLogsIndex = failedLogsIndex; - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java deleted file mode 100644 index dbc5229a1d30d..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsResult.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.azure.monitor.ingestion.models; - -import java.util.List; - -/** - * - */ -public final class SendLogsResult { - - SendLogsResult() { - - } - - /** - * @return - */ - public SendLogsStatus getStatus() { - return SendLogsStatus.SUCCESS; - } - - /** - * @return - */ - public List getErrors() { - return null; - } -} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java new file mode 100644 index 0000000000000..b525f3eaeb1a3 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java @@ -0,0 +1,34 @@ +package com.azure.monitor.ingestion.models; + +import com.azure.core.annotation.Immutable; +import com.azure.core.models.ResponseError; + +import java.util.List; + +/** + * + */ +@Immutable +public class UploadLogsError { + private ResponseError responseError; + private List failedLogs; + + public UploadLogsError(ResponseError error, List failedLogs) { + this.responseError = error; + this.failedLogs = failedLogs; + } + + /** + * @return + */ + public ResponseError getResponseError() { + return responseError; + } + + /** + * @return + */ + public List getFailedLogs() { + return failedLogs; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java similarity index 73% rename from sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java index a6825498bdee3..dbb92bc44af7a 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsOptions.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java @@ -1,12 +1,13 @@ package com.azure.monitor.ingestion.models; +import com.azure.core.annotation.Fluent; import com.azure.core.util.serializer.ObjectSerializer; /** * */ -public final class SendLogsOptions { - +@Fluent +public final class UploadLogsOptions { private ObjectSerializer objectSerializer; private Integer maxConcurrency; @@ -20,7 +21,7 @@ public ObjectSerializer getObjectSerializer() { /** * @param objectSerializer */ - public SendLogsOptions setObjectSerializer(ObjectSerializer objectSerializer) { + public UploadLogsOptions setObjectSerializer(ObjectSerializer objectSerializer) { this.objectSerializer = objectSerializer; return this; } @@ -35,7 +36,7 @@ public Integer getMaxConcurrency() { /** * @param maxConcurrency */ - public SendLogsOptions setMaxConcurrency(Integer maxConcurrency) { + public UploadLogsOptions setMaxConcurrency(Integer maxConcurrency) { this.maxConcurrency = maxConcurrency; return this; } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java new file mode 100644 index 0000000000000..c11cb31f81a90 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java @@ -0,0 +1,34 @@ +package com.azure.monitor.ingestion.models; + +import com.azure.core.annotation.Immutable; + +import java.util.List; + +/** + * + */ +@Immutable +public final class UploadLogsResult { + + private final List errors; + private final UploadLogsStatus status; + + public UploadLogsResult(UploadLogsStatus status, List errors) { + this.status = status; + this.errors = errors; + } + + /** + * @return + */ + public UploadLogsStatus getStatus() { + return status; + } + + /** + * @return + */ + public List getErrors() { + return errors; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java similarity index 52% rename from sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java rename to sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java index e07251655cfac..260892210e34f 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/SendLogsStatus.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java @@ -3,8 +3,8 @@ /** * */ -public enum SendLogsStatus { +public enum UploadLogsStatus { SUCCESS, - - PARTIAL_FAILURE; + PARTIAL_FAILURE, + FAILURE; } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java index af0c66571f1fd..bb2f1aa12a44a 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. -/** - * - */ +/** Package containing the classes for IngestionUsingDataCollectionRules. null. */ package com.azure.monitor.ingestion; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java index 8138ac0f1b3b9..675a8096ca4cc 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java @@ -1,11 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. module com.azure.monitor.ingestion { requires transitive com.azure.core; + exports com.azure.monitor.ingestion; exports com.azure.monitor.ingestion.models; - opens com.azure.monitor.ingestion to com.fasterxml.jackson.databind; - + opens com.azure.monitor.ingestion to com.azure.core, com.fasterxml.jackson.databind; } diff --git a/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java index 21df659619c0f..f41d0529d7ed3 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java +++ b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java @@ -2,12 +2,8 @@ import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; -import com.azure.core.http.rest.Response; -import com.azure.core.util.Context; +import com.azure.core.util.Configuration; import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.monitor.ingestion.implementation.DataCollectionRulesImpl; -import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesImplBuilder; -import com.azure.monitor.ingestion.models.SendLogsResult; import org.junit.jupiter.api.Test; import java.time.OffsetDateTime; @@ -15,42 +11,23 @@ import java.util.List; public class LogsCollectionClientTest { - - @Test - public void testSendLogs() { - DataCollectionRulesImpl dataCollectionRules = new IngestionUsingDataCollectionRulesImplBuilder() - .credential(new DefaultAzureCredentialBuilder().build()) - .endpoint("https://srnagar-logsingestion-dcr-lrz3.westus2-1.ingest.monitor.azure.com") - .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) - .buildClient() - .getDataCollectionRules(); - List dataList = new ArrayList<>(); - - dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("desktop").setAdditionalContext("new" + - "-desktop-log")); - dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("laptop").setAdditionalContext("more" + - "-laptop-log")); - - Response voidResponse = dataCollectionRules.ingestWithResponse("dcr-adec84661d05465f8532f32a04af6f98", - "Custom-MyTableRawData", dataList, "", "", Context.NONE); - System.out.println(voidResponse.getStatusCode()); - } - @Test - public void testSendLogsFromClient() { - LogsIngestionClient logsIngestionClient = new LogsIngestionClientBuilder() + public void testUploadLogsAsync() { + String dataCollectionEndpoint = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_ENDPOINT"); + String dataCollectionRuleId = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_RULE_ID"); + String streamName = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_STREAM_NAME"); + LogsIngestionAsyncClient logsIngestionAsyncClient = new LogsIngestionClientBuilder() .credential(new DefaultAzureCredentialBuilder().build()) - .endpoint("https://srnagar-logsingestion-dcr-lrz3.westus2-1.ingest.monitor.azure.com") - .buildClient(); - - List dataList = new ArrayList<>(); + .endpoint(dataCollectionEndpoint) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS).addAllowedHeaderName("content-length").addAllowedHeaderName("content-encoding")) + .buildAsyncClient(); + List dataList = new ArrayList<>(); dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("desktop").setAdditionalContext("new" + - "-desktop-log")); + "-desktop-log")); dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("laptop").setAdditionalContext("more" + - "-laptop-log")); + "-laptop-log")); - SendLogsResult response = logsIngestionClient.sendLogs("dcr-adec84661d05465f8532f32a04af6f98", "Custom-MyTableRawData", dataList); - System.out.println(response.getStatus()); + logsIngestionAsyncClient.upload(dataCollectionRuleId, streamName, dataList).block(); } } diff --git a/sdk/monitor/azure-monitor-ingestion/swagger/README.md b/sdk/monitor/azure-monitor-ingestion/swagger/README.md index d61348fc5e1f4..faf447ac9d35b 100644 --- a/sdk/monitor/azure-monitor-ingestion/swagger/README.md +++ b/sdk/monitor/azure-monitor-ingestion/swagger/README.md @@ -4,7 +4,7 @@ ```yaml java: true -use: '@autorest/java@4.0.54' +use: '@autorest/java@4.0.61' output-folder: ../ license-header: MICROSOFT_MIT_SMALL input-file: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/monitor/data-plane/ingestion/preview/2021-11-01-preview/DataCollectionRules.json @@ -21,4 +21,5 @@ model-override-setter-from-superclass: true credential-types: tokencredential client-side-validations: true artifact-id: azure-monitor-logingestion +data-plane: true ``` From 62ae314c964e695e6457218327b1eeb4d0c9ba1d Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 02:50:56 -0700 Subject: [PATCH 06/14] samples, docs and tests --- eng/jacoco-test-coverage/pom.xml | 5 + eng/versioning/version_client.txt | 1 + sdk/monitor/azure-monitor-ingestion/README.md | 36 ++- sdk/monitor/azure-monitor-ingestion/pom.xml | 10 +- .../ingestion/LogsIngestionAsyncClient.java | 124 +++++++--- .../ingestion/LogsIngestionClient.java | 46 ++-- .../ingestion/LogsIngestionClientBuilder.java | 48 ++-- .../LogsIngestionServiceVersion.java | 9 +- ...UsingDataCollectionRulesClientBuilder.java | 4 +- .../UploadLogsResponseHolder.java | 43 ++++ .../ingestion/models/UploadLogsError.java | 21 +- .../ingestion/models/UploadLogsOptions.java | 19 +- .../ingestion/models/UploadLogsResult.java | 17 +- .../ingestion/models/UploadLogsStatus.java | 14 +- .../ingestion/models/package-info.java | 2 +- .../azure/monitor/ingestion/package-info.java | 5 +- .../src/main/java/module-info.java | 1 - ...ies => azure-monitor-ingestion.properties} | 0 .../monitor/ingestion/CustomLogData.java | 49 ++++ .../monitor/ingestion/ReadmeSamples.java | 51 +++++ .../monitor/ingestion/UploadLogsSample.java | 39 ++++ .../com/azure/monitor/ingestion/LogData.java | 3 + .../ingestion/LogsCollectionClientTest.java | 177 +++++++++++++-- ...gsCollectionClientTest.testUploadLogs.json | 21 ++ ...ionClientTest.testUploadLogsInBatches.json | 38 ++++ ...ientTest.testUploadLogsPartialFailure.json | 211 ++++++++++++++++++ sdk/monitor/ci.yml | 11 + 27 files changed, 886 insertions(+), 119 deletions(-) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/UploadLogsResponseHolder.java rename sdk/monitor/azure-monitor-ingestion/src/main/resources/{azure-monitor-logingestion.properties => azure-monitor-ingestion.properties} (100%) create mode 100644 sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java create mode 100644 sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogs.json create mode 100644 sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsInBatches.json create mode 100644 sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index e89d10e27c30e..b227eef080b17 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -245,6 +245,11 @@ azure-messaging-webpubsub 1.2.0-beta.1 + + com.azure + azure-monitor-ingestion + 1.0.0-beta.1 + com.azure azure-monitor-opentelemetry-exporter diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index d0b436277baf0..9a035497bc813 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -115,6 +115,7 @@ com.azure:azure-messaging-webpubsub;1.1.3;1.2.0-beta.1 com.azure:azure-mixedreality-authentication;1.2.3;1.3.0-beta.1 com.azure:azure-mixedreality-remoterendering;1.1.7;1.2.0-beta.1 com.azure:azure-monitor-opentelemetry-exporter;1.0.0-beta.5;1.0.0-beta.6 +com.azure:azure-monitor-ingestion;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-monitor-query;1.0.7;1.1.0-beta.1 com.azure:azure-monitor-query-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-perf-test-parent;1.0.0-beta.1;1.0.0-beta.1 diff --git a/sdk/monitor/azure-monitor-ingestion/README.md b/sdk/monitor/azure-monitor-ingestion/README.md index b59423b914e8b..33291b3335ebb 100644 --- a/sdk/monitor/azure-monitor-ingestion/README.md +++ b/sdk/monitor/azure-monitor-ingestion/README.md @@ -1,4 +1,9 @@ -# Azure Monitor Data Ingestion client library for Java +# Azure Monitor Ingestion client library for Java + +The Azure Monitor Ingestion client library is used to send custom logs to [Azure Monitor][azure_monitor_overview]. + +This library allows you to send data from virtually any source to supported built-in tables or to custom tables +that you create in Log Analytics workspace. You can even extend the schema of built-in tables with custom columns. ## Getting started @@ -18,6 +23,33 @@ ``` ## Key concepts +### Data Collection Endpoint + +Data Collection Endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. This +article provides an overview of data collection endpoints including their contents and structure and how you can create +and work with them. + +### Tables +Custom logs can send data to any custom table that you create and to certain built-in tables in your Log Analytics +workspace. The target table must exist before you can send data to it. The following built-in tables are currently supported: + +- [CommonSecurityLog](https://docs.microsoft.com/azure/azure-monitor/reference/tables/commonsecuritylog) +- [SecurityEvents](https://docs.microsoft.com/azure/azure-monitor/reference/tables/securityevent) +- [Syslog](https://docs.microsoft.com/azure/azure-monitor/reference/tables/syslog) +- [WindowsEvents](https://docs.microsoft.com/azure/azure-monitor/reference/tables/windowsevent) + +### Data Collection Rule + +Data collection rules define data collected by Azure Monitor and specify how and where that data should be sent or +stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a +different DCR for different sources and target tables. + +The DCR must understand the structure of the input data and the structure of the target table. If the two don't match, +it can use a transformation to convert the source data to match the target table. You may also use the transform to +filter source data and perform any other calculations or conversions. + +For more details, refer to [Data collection rules in Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/essentials/data-collection-rule-overview). + ## Examples ## Troubleshooting @@ -46,4 +78,4 @@ For more information see the [Code of Conduct FAQ](https://opensource.microsoft. [jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable [azure_subscription]: https://azure.microsoft.com/free -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-logingestion%2FREADME.png) +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-ingestion%2FREADME.png) diff --git a/sdk/monitor/azure-monitor-ingestion/pom.xml b/sdk/monitor/azure-monitor-ingestion/pom.xml index b68e6ba32b115..fec04e622868c 100644 --- a/sdk/monitor/azure-monitor-ingestion/pom.xml +++ b/sdk/monitor/azure-monitor-ingestion/pom.xml @@ -7,7 +7,7 @@ com.azure azure-monitor-ingestion - 1.0.0-beta.1 + 1.0.0-beta.1 jar Microsoft Azure SDK for Azure Monitor Data Ingestion @@ -58,12 +58,12 @@ com.azure azure-core - 1.27.0 + 1.29.1 com.azure azure-core-http-netty - 1.11.9 + 1.12.2 @@ -88,7 +88,7 @@ com.azure azure-core-test - 1.6.1 + 1.9.1 test @@ -106,7 +106,7 @@ com.azure azure-identity - 1.5.1 + 1.5.2 test diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java index b284ccbc9096c..513d48687247f 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion; import com.azure.core.annotation.ReturnType; @@ -12,6 +15,7 @@ import com.azure.core.util.serializer.ObjectSerializer; import com.azure.monitor.ingestion.implementation.DefaultJsonSerializer; import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesAsyncClient; +import com.azure.monitor.ingestion.implementation.UploadLogsResponseHolder; import com.azure.monitor.ingestion.models.UploadLogsError; import com.azure.monitor.ingestion.models.UploadLogsOptions; import com.azure.monitor.ingestion.models.UploadLogsResult; @@ -24,9 +28,11 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -36,14 +42,16 @@ import static com.azure.core.util.FluxUtil.withContext; /** - * + * The asynchronous client for uploading logs to Azure Monitor. */ @ServiceClient(isAsync = true, builder = LogsIngestionClientBuilder.class) public final class LogsIngestionAsyncClient { private static final ClientLogger LOGGER = new ClientLogger(LogsIngestionAsyncClient.class); private static final String CONTENT_ENCODING = "Content-Encoding"; - private static final long ONE_MB = 1024 * 1024; + private static final long MAX_REQUEST_PAYLOAD_SIZE = 1024 * 1024; // 1 MB private static final String GZIP = "gzip"; + // TODO (srnagar): Move DefaultJsonSerializer in azure-core to public package + private static final DefaultJsonSerializer DEFAULT_SERIALIZER = new DefaultJsonSerializer(); private final IngestionUsingDataCollectionRulesAsyncClient service; @@ -52,10 +60,14 @@ public final class LogsIngestionAsyncClient { } /** - * @param dataCollectionRuleId - * @param streamName - * @param logs - * @return + * Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be + * too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split + * the input logs into multiple smaller requests before sending to the service. + * @param dataCollectionRuleId the data collection rule id that is configured to collect and transform the logs. + * @param streamName the stream name configured in data collection rule that matches defines the structure of the + * logs sent in this request. + * @param logs the collection of logs to be uploaded. + * @return the result of the logs upload request. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono upload(String dataCollectionRuleId, String streamName, List logs) { @@ -63,16 +75,20 @@ public Mono upload(String dataCollectionRuleId, String streamN } /** - * @param dataCollectionRuleId - * @param streamName - * @param logs - * @param options - * @return + * Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be + * too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split + * the input logs into multiple smaller requests before sending to the service. + * @param dataCollectionRuleId the data collection rule id that is configured to collect and transform the logs. + * @param streamName the stream name configured in data collection rule that matches defines the structure of the + * logs sent in this request. + * @param logs the collection of logs to be uploaded. + * @param options the options to configure the upload request. + * @return the result of the logs upload request. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono upload(String dataCollectionRuleId, String streamName, List logs, UploadLogsOptions options) { - return withContext(context -> upload(dataCollectionRuleId, streamName, logs, options,context)); + return withContext(context -> upload(dataCollectionRuleId, streamName, logs, options, context)); } Mono upload(String dataCollectionRuleId, String streamName, @@ -91,8 +107,7 @@ private Mono splitAndUpload(String dataCollectionRuleId, Strin throw LOGGER.logExceptionAsError(new IllegalArgumentException("'logs' cannot be empty.")); } - // TODO (srnagar): Move DefaultJsonSerializer in azure-core to public package - ObjectSerializer serializer = new DefaultJsonSerializer(); + ObjectSerializer serializer = DEFAULT_SERIALIZER; // set concurrency to 1 as default int concurrency = 1; @@ -113,17 +128,9 @@ private Mono splitAndUpload(String dataCollectionRuleId, Strin Iterator> logBatchesIterator = logBatches.iterator(); return Flux.fromIterable(requests) - .flatMapSequential(bytes -> service.uploadWithResponse(dataCollectionRuleId, streamName, - BinaryData.fromBytes(bytes), requestOptions), - concurrency) - .map(response -> { - logBatchesIterator.next(); - return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); - }) - .onErrorResume(HttpResponseException.class, - ex -> Mono.just(new UploadLogsResult(UploadLogsStatus.FAILURE, - Arrays.asList(new UploadLogsError((ResponseError) ex.getValue(), - logBatchesIterator.next()))))) + .flatMapSequential(bytes -> + uploadToService(dataCollectionRuleId, streamName, requestOptions, bytes), concurrency) + .map(responseHolder -> mapResult(logBatchesIterator, responseHolder)) .collectList() .map(this::createResponse); } catch (RuntimeException ex) { @@ -131,6 +138,43 @@ private Mono splitAndUpload(String dataCollectionRuleId, Strin } } + private UploadLogsResult mapResult(Iterator> logBatchesIterator, UploadLogsResponseHolder responseHolder) { + List logsBatch = logBatchesIterator.next(); + if (responseHolder.getStatus() == UploadLogsStatus.FAILURE) { + return new UploadLogsResult(responseHolder.getStatus(), + Arrays.asList(new UploadLogsError(responseHolder.getResponseError(), logsBatch))); + } + return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); + } + + private Mono uploadToService(String dataCollectionRuleId, String streamName, RequestOptions requestOptions, byte[] bytes) { + return service.uploadWithResponse(dataCollectionRuleId, streamName, + BinaryData.fromBytes(bytes), requestOptions) + .map(response -> new UploadLogsResponseHolder(UploadLogsStatus.SUCCESS, null)) + .onErrorResume(HttpResponseException.class, + ex -> Mono.just(new UploadLogsResponseHolder(UploadLogsStatus.FAILURE, + mapToResponseError(ex)))); + } + + private ResponseError mapToResponseError(HttpResponseException ex) { + ResponseError responseError = null; + if (ex.getValue() instanceof LinkedHashMap) { + @SuppressWarnings("unchecked") + LinkedHashMap errorMap = (LinkedHashMap) ex.getValue(); + if (errorMap.containsKey("error")) { + Object error = errorMap.get("error"); + if (error instanceof LinkedHashMap) { + @SuppressWarnings("unchecked") + LinkedHashMap errorDetails = (LinkedHashMap) error; + if (errorDetails.containsKey("code") && errorDetails.containsKey("message")) { + responseError = new ResponseError(errorDetails.get("code"), errorDetails.get("message")); + } + } + } + } + return responseError; + } + private UploadLogsResult createResponse(List results) { boolean allErrors = results.stream().allMatch(result -> result.getStatus() == UploadLogsStatus.FAILURE); if (allErrors) { @@ -163,11 +207,8 @@ private List createGzipRequests(List logs, ObjectSerializer seri byte[] bytes = serializer.serializeToBytes(logs.get(i)); int currentLogSize = bytes.length; currentBatchSize += currentLogSize; - if (currentBatchSize > ONE_MB) { - generator.writeRaw(serializedLogs.stream() - .collect(Collectors.joining(","))); - generator.writeEndArray(); - generator.close(); + if (currentBatchSize > MAX_REQUEST_PAYLOAD_SIZE) { + writeLogsAndCloseJsonGenerator(generator, serializedLogs); requests.add(gzipRequest(byteArrayOutputStream.toByteArray())); byteArrayOutputStream = new ByteArrayOutputStream(); @@ -178,13 +219,10 @@ private List createGzipRequests(List logs, ObjectSerializer seri logBatches.add(logs.subList(currentBatchStart, i)); currentBatchStart = i; } - serializedLogs.add(new String(bytes)); + serializedLogs.add(new String(bytes, StandardCharsets.UTF_8)); } if (currentBatchSize > 0) { - generator.writeRaw(serializedLogs.stream() - .collect(Collectors.joining(","))); - generator.writeEndArray(); - generator.close(); + writeLogsAndCloseJsonGenerator(generator, serializedLogs); requests.add(gzipRequest(byteArrayOutputStream.toByteArray())); logBatches.add(logs.subList(currentBatchStart, logs.size())); } @@ -194,12 +232,26 @@ private List createGzipRequests(List logs, ObjectSerializer seri } } + private void writeLogsAndCloseJsonGenerator(JsonGenerator generator, List serializedLogs) throws IOException { + generator.writeRaw(serializedLogs.stream() + .collect(Collectors.joining(","))); + generator.writeEndArray(); + generator.close(); + } + + /** + * Gzips the input byte array. + * @param bytes The input byte array. + * @return gzipped byte array. + */ private byte[] gzipRequest(byte[] bytes) { + // This should be moved to azure-core and should be enabled when the client library requests for gzipping the + // request body content. ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (GZIPOutputStream zip = new GZIPOutputStream(byteArrayOutputStream)) { zip.write(bytes); } catch (IOException exception) { - throw new UncheckedIOException(exception); + throw LOGGER.logExceptionAsError(new UncheckedIOException(exception)); } return byteArrayOutputStream.toByteArray(); } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java index 6b0773eb82d5a..51960c6831307 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion; import com.azure.core.annotation.ReturnType; @@ -10,7 +13,7 @@ import java.util.List; /** - * + * The synchronous client for uploading logs to Azure Monitor. */ @ServiceClient(builder = LogsIngestionClientBuilder.class) public final class LogsIngestionClient { @@ -22,27 +25,38 @@ public final class LogsIngestionClient { } /** - * @param dataCollectionRuleId - * @param streamName - * @param logs - * @param options - * @param context - * @return + * Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be + * too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split + * the input logs into multiple smaller requests before sending to the service. + * + * @param dataCollectionRuleId the data collection rule id that is configured to collect and transform the logs. + * @param streamName the stream name configured in data collection rule that matches defines the structure of the + * logs sent in this request. + * @param logs the collection of logs to be uploaded. + * @return the result of the logs upload request. */ @ServiceMethod(returns = ReturnType.SINGLE) - public UploadLogsResult upload(String dataCollectionRuleId, String streamName, - List logs, UploadLogsOptions options, Context context) { - return asyncClient.upload(dataCollectionRuleId, streamName, logs, options, context).block(); + public UploadLogsResult upload(String dataCollectionRuleId, String streamName, List logs) { + return asyncClient.upload(dataCollectionRuleId, streamName, logs).block(); } /** - * @param dataCollectionRuleId - * @param streamName - * @param logs - * @return + * Uploads logs to Azure Monitor with specified data collection rule id and stream name. The input logs may be + * too large to be sent as a single request to the Azure Monitor service. In such cases, this method will split + * the input logs into multiple smaller requests before sending to the service. + * + * @param dataCollectionRuleId the data collection rule id that is configured to collect and transform the logs. + * @param streamName the stream name configured in data collection rule that matches defines the structure of the + * logs sent in this request. + * @param logs the collection of logs to be uploaded. + * @param options the options to configure the upload request. + * @param context additional context that is passed through the Http pipeline during the service call. If no + * additional context is required, pass {@link Context#NONE} instead. + * @return the result of the logs upload request. */ @ServiceMethod(returns = ReturnType.SINGLE) - public UploadLogsResult upload(String dataCollectionRuleId, String streamName, List logs) { - return upload(dataCollectionRuleId, streamName, logs); + public UploadLogsResult upload(String dataCollectionRuleId, String streamName, + List logs, UploadLogsOptions options, Context context) { + return asyncClient.upload(dataCollectionRuleId, streamName, logs, options, context).block(); } } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java index c8ce1656d7339..dd56b8b1e9a53 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClientBuilder.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion; import com.azure.core.annotation.ServiceClientBuilder; @@ -16,33 +19,41 @@ import com.azure.core.util.Configuration; import com.azure.core.util.logging.ClientLogger; import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesClientBuilder; +import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesServiceVersion; + +import java.net.MalformedURLException; +import java.net.URL; /** - * + * Fluent builder for creating instances of {@link LogsIngestionClient} and {@link LogsIngestionAsyncClient}. */ @ServiceClientBuilder(serviceClients = {LogsIngestionClient.class, LogsIngestionAsyncClient.class}) public final class LogsIngestionClientBuilder implements ConfigurationTrait, HttpTrait, EndpointTrait, TokenCredentialTrait { - private final ClientLogger logger = new ClientLogger(LogsIngestionClientBuilder.class); + private static final ClientLogger LOGGER = new ClientLogger(LogsIngestionClientBuilder.class); private final IngestionUsingDataCollectionRulesClientBuilder innerLogBuilder = new IngestionUsingDataCollectionRulesClientBuilder(); - private LogsIngestionServiceVersion serviceVersion; /** * Sets the log query endpoint. * @param endpoint the host value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder endpoint(String endpoint) { - innerLogBuilder.endpoint(endpoint); - return this; + try { + new URL(endpoint); + innerLogBuilder.endpoint(endpoint); + return this; + } catch (MalformedURLException exception) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException("'endpoint' must be a valid URL.", exception)); + } } /** * Sets The HTTP pipeline to send requests through. * @param pipeline the pipeline value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder pipeline(HttpPipeline pipeline) { @@ -53,7 +64,7 @@ public LogsIngestionClientBuilder pipeline(HttpPipeline pipeline) { /** * Sets The HTTP client used to send the request. * @param httpClient the httpClient value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder httpClient(HttpClient httpClient) { @@ -64,7 +75,7 @@ public LogsIngestionClientBuilder httpClient(HttpClient httpClient) { /** * Sets The configuration store that is used during construction of the service client. * @param configuration the configuration value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder configuration(Configuration configuration) { @@ -75,7 +86,7 @@ public LogsIngestionClientBuilder configuration(Configuration configuration) { /** * Sets The logging configuration for HTTP requests and responses. * @param httpLogOptions the httpLogOptions value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { @@ -86,7 +97,7 @@ public LogsIngestionClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) /** * Sets The retry policy that will attempt to retry failed requests, if applicable. * @param retryPolicy the retryPolicy value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ public LogsIngestionClientBuilder retryPolicy(RetryPolicy retryPolicy) { innerLogBuilder.retryPolicy(retryPolicy); @@ -96,7 +107,7 @@ public LogsIngestionClientBuilder retryPolicy(RetryPolicy retryPolicy) { /** * Adds a custom Http pipeline policy. * @param customPolicy The custom Http pipeline policy to add. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { @@ -105,8 +116,9 @@ public LogsIngestionClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { } /** - * @param retryOptions - * @return + * Sets the retry options for this client. + * @param retryOptions the retry options for this client. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder retryOptions(RetryOptions retryOptions) { @@ -117,7 +129,7 @@ public LogsIngestionClientBuilder retryOptions(RetryOptions retryOptions) { /** * Sets The TokenCredential used for authentication. * @param tokenCredential the tokenCredential value. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) { @@ -128,7 +140,7 @@ public LogsIngestionClientBuilder credential(TokenCredential tokenCredential) { /** * Set the {@link ClientOptions} used for creating the client. * @param clientOptions The {@link ClientOptions}. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ @Override public LogsIngestionClientBuilder clientOptions(ClientOptions clientOptions) { @@ -139,10 +151,10 @@ public LogsIngestionClientBuilder clientOptions(ClientOptions clientOptions) { /** * The service version to use when creating the client. * @param serviceVersion The {@link LogsIngestionServiceVersion}. - * @return the {@link LogsIngestionClientBuilder}. + * @return the updated {@link LogsIngestionClientBuilder}. */ public LogsIngestionClientBuilder serviceVersion(LogsIngestionServiceVersion serviceVersion) { - this.serviceVersion = serviceVersion; + innerLogBuilder.serviceVersion(IngestionUsingDataCollectionRulesServiceVersion.valueOf(serviceVersion.getVersion())); return this; } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java index bef34319904c2..c3b7df0830626 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionServiceVersion.java @@ -1,15 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion; import com.azure.core.util.ServiceVersion; /** - * + * The service version of the Azure Monitor service to upload logs. */ public enum LogsIngestionServiceVersion implements ServiceVersion { /** * Service version {@code v1}. */ - V_1("v1"); + V2021_11_01_PREVIEW("2021-11-01-preview"); String version; @@ -26,7 +29,7 @@ public enum LogsIngestionServiceVersion implements ServiceVersion { * @return The latest supported service version by this library. */ public static LogsIngestionServiceVersion getLatest() { - return V_1; + return V2021_11_01_PREVIEW; } @Override diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java index 387decaf0bd49..ef91f82d8b2fb 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/IngestionUsingDataCollectionRulesClientBuilder.java @@ -56,7 +56,7 @@ public final class IngestionUsingDataCollectionRulesClientBuilder @Generated private static final String SDK_VERSION = "version"; @Generated - private final Map properties = CoreUtils.getProperties("azure-monitor-logingestion.properties"); + private final Map properties = CoreUtils.getProperties("azure-monitor-ingestion.properties"); @Generated private final List pipelinePolicies; @@ -266,7 +266,7 @@ private HttpPipeline createHttpPipeline() { policies.add(new AddDatePolicy()); policies.add(new CookiePolicy()); if (tokenCredential != null) { - policies.add(new BearerTokenAuthenticationPolicy(tokenCredential,"https://monitor.azure.com//.default")); + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, "https://monitor.azure.com//.default")); } policies.addAll( this.pipelinePolicies.stream() diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/UploadLogsResponseHolder.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/UploadLogsResponseHolder.java new file mode 100644 index 0000000000000..93ce39de26610 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/UploadLogsResponseHolder.java @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.ingestion.implementation; + +import com.azure.core.annotation.Immutable; +import com.azure.core.models.ResponseError; +import com.azure.monitor.ingestion.models.UploadLogsStatus; + +/** + * The intermediate response holder for converting exceptions to {@link ResponseError} instances. + */ +@Immutable +public final class UploadLogsResponseHolder { + private UploadLogsStatus status; + private ResponseError responseError; + + /** + * Creates and instance of {@link UploadLogsResponseHolder}. + * @param status The status of the logs upload request. + * @param responseError The error details of the upload request, if any. + */ + public UploadLogsResponseHolder(UploadLogsStatus status, ResponseError responseError) { + this.status = status; + this.responseError = responseError; + } + + /** + * Returns the status of the logs upload request. + * @return the status of the logs upload request. + */ + public UploadLogsStatus getStatus() { + return status; + } + + /** + * Returns the error details of the upload request, if any. + * @return the error details of the upload request, if any. + */ + public ResponseError getResponseError() { + return responseError; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java index b525f3eaeb1a3..2fc4b6cc8ecea 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion.models; import com.azure.core.annotation.Immutable; @@ -6,27 +9,35 @@ import java.util.List; /** - * + * The model representing the error and the associated logs that failed when uploading a subset of logs to Azure + * Monitor. */ @Immutable public class UploadLogsError { - private ResponseError responseError; - private List failedLogs; + private final ResponseError responseError; + private final List failedLogs; + /** + * Creates an instance of error. + * @param error the response error containing the error details returned by the service. + * @param failedLogs the logs that failed to upload. + */ public UploadLogsError(ResponseError error, List failedLogs) { this.responseError = error; this.failedLogs = failedLogs; } /** - * @return + * Returns the response error containing the error details returned by the service. + * @return the response error containing the error details returned by the service. */ public ResponseError getResponseError() { return responseError; } /** - * @return + * Returns the logs that failed to upload. + * @return the logs that failed to upload. */ public List getFailedLogs() { return failedLogs; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java index dbb92bc44af7a..22e041b280c91 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsOptions.java @@ -1,10 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion.models; import com.azure.core.annotation.Fluent; import com.azure.core.util.serializer.ObjectSerializer; /** - * + * The options model to configure the request to upload logs to Azure Monitor. */ @Fluent public final class UploadLogsOptions { @@ -12,14 +15,17 @@ public final class UploadLogsOptions { private Integer maxConcurrency; /** - * @return + * Returns the serializer to use to convert the log objects to JSON. + * @return the serializer to use to convert the log objects to JSON. */ public ObjectSerializer getObjectSerializer() { return objectSerializer; } /** - * @param objectSerializer + * Sets the serializer to use to convert the log objects to JSON. + * @param objectSerializer the serializer to use to convert the log objects to JSON. + * @return the update {@link UploadLogsOptions} instance. */ public UploadLogsOptions setObjectSerializer(ObjectSerializer objectSerializer) { this.objectSerializer = objectSerializer; @@ -27,14 +33,17 @@ public UploadLogsOptions setObjectSerializer(ObjectSerializer objectSerializer) } /** - * @return + * Returns the max concurrent requests to send to the Azure Monitor service when uploading logs. + * @return the max concurrent requests to send to the Azure Monitor service when uploading logs. */ public Integer getMaxConcurrency() { return maxConcurrency; } /** - * @param maxConcurrency + * Sets the max concurrent requests to send to the Azure Monitor service when uploading logs. + * @param maxConcurrency the max concurrent requests to send to the Azure Monitor service when uploading logs. + * @return the update {@link UploadLogsOptions} instance. */ public UploadLogsOptions setMaxConcurrency(Integer maxConcurrency) { this.maxConcurrency = maxConcurrency; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java index c11cb31f81a90..164a3afd0fb42 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsResult.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion.models; import com.azure.core.annotation.Immutable; @@ -5,28 +8,34 @@ import java.util.List; /** - * + * The model class containing the result of a logs upload operation. */ @Immutable public final class UploadLogsResult { - private final List errors; private final UploadLogsStatus status; + /** + * Creates an instance of {@link UploadLogsOptions}. + * @param status the status of the logs upload operation. + * @param errors the list of errors that occurred when uploading logs, if any. + */ public UploadLogsResult(UploadLogsStatus status, List errors) { this.status = status; this.errors = errors; } /** - * @return + * Returns the status of the logs upload operation. + * @return the status of the logs upload operation. */ public UploadLogsStatus getStatus() { return status; } /** - * @return + * Returns the list of errors that occurred when uploading logs, if any. + * @return the list of errors that occurred when uploading logs, if any. */ public List getErrors() { return errors; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java index 260892210e34f..d6ca90563c33c 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsStatus.java @@ -1,10 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.monitor.ingestion.models; /** - * + * Enum to indicate the status of a logs upload operation. */ public enum UploadLogsStatus { + /** + * Indicates that all the logs were successfully uploaded to Azure Monitor. + */ SUCCESS, + /** + * Indicates that some logs failed to upload to Azure Monitor. + */ PARTIAL_FAILURE, + /** + * Indicates that all the logs failed to upload to Azure Monitor. + */ FAILURE; } diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java index ea9291d5c5174..16eb3b425f93e 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/package-info.java @@ -2,6 +2,6 @@ // Licensed under the MIT License. /** - * + * Package containing models for uploading logs to Azure Monitor. */ package com.azure.monitor.ingestion.models; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java index bb2f1aa12a44a..5c2cc6c1c015e 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/package-info.java @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. -/** Package containing the classes for IngestionUsingDataCollectionRules. null. */ +/** + * Package containing client classes for uploading logs to Azure Monitor. + */ package com.azure.monitor.ingestion; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java index 675a8096ca4cc..d392257ae5dd0 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/module-info.java @@ -1,6 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// Code generated by Microsoft (R) AutoRest Code Generator. module com.azure.monitor.ingestion { requires transitive com.azure.core; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/resources/azure-monitor-logingestion.properties b/sdk/monitor/azure-monitor-ingestion/src/main/resources/azure-monitor-ingestion.properties similarity index 100% rename from sdk/monitor/azure-monitor-ingestion/src/main/resources/azure-monitor-logingestion.properties rename to sdk/monitor/azure-monitor-ingestion/src/main/resources/azure-monitor-ingestion.properties diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java new file mode 100644 index 0000000000000..c8686ddbd4b37 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.ingestion; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.time.OffsetDateTime; + +public final class CustomLogData { + + @JsonProperty(value = "Time") + private OffsetDateTime time; + + + @JsonProperty(value = "ExtendedColumn") + private String extendedColumn; + + + @JsonProperty(value = "AdditionalContext") + private String additionalContext; + + public OffsetDateTime getTime() { + return time; + } + + public CustomLogData setTime(OffsetDateTime time) { + this.time = time; + return this; + } + + public String getExtendedColumn() { + return extendedColumn; + } + + public CustomLogData setExtendedColumn(String extendedColumn) { + this.extendedColumn = extendedColumn; + return this; + } + + public String getAdditionalContext() { + return additionalContext; + } + + public CustomLogData setAdditionalContext(String additionalContext) { + this.additionalContext = additionalContext; + return this; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java new file mode 100644 index 0000000000000..64488670518c0 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.ingestion; + +import com.azure.identity.DefaultAzureCredential; +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.monitor.ingestion.models.UploadLogsResult; + +import java.util.List; + +/** + * + */ +public final class ReadmeSamples { + + public void createClient() { + DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); + + LogsIngestionClient client = new LogsIngestionClientBuilder() + .endpoint(" logs = getLogs(); + UploadLogsResult result = client.upload(" getLogs() { + return null; + } +} diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java new file mode 100644 index 0000000000000..843257ec16687 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.ingestion; + +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.monitor.ingestion.models.UploadLogsResult; + +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + * + */ +public final class UploadLogsSample { + + /** + * @param args + */ + public static void main(String[] args) { + LogsIngestionClient client = new LogsIngestionClientBuilder() + .endpoint(" dataList = new ArrayList<>(); + + for (int i = 0; i < 10; i++) { + CustomLogData e = new CustomLogData() + .setTime(OffsetDateTime.now()) + .setExtendedColumn("columndata" + i) + .setAdditionalContext("more logs context"); + dataList.add(e); + } + UploadLogsResult result = client.upload(" Mono.just(new AccessToken("fakeToken", OffsetDateTime.now().plusDays(1)))) + .httpClient(interceptorManager.getPlaybackClient()); + } else if (getTestMode() == TestMode.RECORD) { + clientBuilder + .addPolicy(interceptorManager.getRecordPolicy()) + .credential(getCredential()); + } else if (getTestMode() == TestMode.LIVE) { + clientBuilder.credential(getCredential()); + } + this.clientBuilder = clientBuilder + .endpoint(dataCollectionEndpoint); + } + + private TokenCredential getCredential() { + return new ClientSecretCredentialBuilder() + .clientId(Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_CLIENT_ID)) + .clientSecret(Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_CLIENT_SECRET)) + .tenantId(Configuration.getGlobalConfiguration().get(Configuration.PROPERTY_AZURE_TENANT_ID)) + .build(); + } + + @Test + public void testUploadLogs() { + List dataList = new ArrayList<>(); + + for (int i = 0; i < 10; i++) { + LogData logData = new LogData() + .setTime(OffsetDateTime.now()) + .setExtendedColumn("test" + i) + .setAdditionalContext("additional logs context"); + dataList.add(logData); + } + LogsIngestionClient client = clientBuilder.buildClient(); + UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, dataList); + assertEquals(UploadLogsStatus.SUCCESS, result.getStatus()); + } -public class LogsCollectionClientTest { @Test - public void testUploadLogsAsync() { - String dataCollectionEndpoint = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_ENDPOINT"); - String dataCollectionRuleId = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_RULE_ID"); - String streamName = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_STREAM_NAME"); - LogsIngestionAsyncClient logsIngestionAsyncClient = new LogsIngestionClientBuilder() - .credential(new DefaultAzureCredentialBuilder().build()) - .endpoint(dataCollectionEndpoint) - .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS).addAllowedHeaderName("content-length").addAllowedHeaderName("content-encoding")) - .buildAsyncClient(); + public void testUploadLogsInBatches() { + List dataList = new ArrayList<>(); + for (int i = 0; i < 10000; i++) { + LogData logData = new LogData() + .setTime(OffsetDateTime.now()) + .setExtendedColumn("test" + i) + .setAdditionalContext("additional logs context"); + dataList.add(logData); + } + + AtomicInteger count = new AtomicInteger(); + LogsIngestionClient client = clientBuilder + .addPolicy(new HttpPipelinePolicy() { + @Override + public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { + count.incrementAndGet(); + return next.process(); + } + @Override + public HttpPipelinePosition getPipelinePosition() { + return HttpPipelinePosition.PER_CALL; + } + }) + .buildClient(); + UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, dataList); + assertEquals(UploadLogsStatus.SUCCESS, result.getStatus()); + assertEquals(2, count.get()); + } + + @Test + public void testUploadLogsPartialFailure() { List dataList = new ArrayList<>(); - dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("desktop").setAdditionalContext("new" + - "-desktop-log")); - dataList.add(new LogData().setTime(OffsetDateTime.now()).setExtendedColumn("laptop").setAdditionalContext("more" + - "-laptop-log")); + for (int i = 0; i < 100000; i++) { + LogData logData = new LogData() + .setTime(OffsetDateTime.now()) + .setExtendedColumn("test" + i) + .setAdditionalContext("additional logs context"); + dataList.add(logData); + } + + AtomicBoolean changeDcrId = new AtomicBoolean(); + AtomicInteger count = new AtomicInteger(); + + LogsIngestionClient client = clientBuilder + .addPolicy(new HttpPipelinePolicy() { + @Override + public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { + count.incrementAndGet(); + if (changeDcrId.get()) { + String url = context.getHttpRequest().getUrl().toString() + .replace(dataCollectionRuleId, "dcr-id"); + context.getHttpRequest().setUrl(url); + changeDcrId.set(false); + return next.process(); + } + changeDcrId.set(true); + return next.process(); + } + + @Override + public HttpPipelinePosition getPipelinePosition() { + return HttpPipelinePosition.PER_CALL; + } + }) + .buildClient(); - logsIngestionAsyncClient.upload(dataCollectionRuleId, streamName, dataList).block(); + UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, dataList); + assertEquals(UploadLogsStatus.PARTIAL_FAILURE, result.getStatus()); + assertEquals(11, count.get()); + assertEquals(5, result.getErrors().size()); + result.getErrors().stream().forEach(error -> assertEquals("NotFound", error.getResponseError().getCode())); } } diff --git a/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogs.json b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogs.json new file mode 100644 index 0000000000000..e427be504bf78 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogs.json @@ -0,0 +1,21 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "e620d321-5a70-482f-893b-f5807955c36a", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "8b1d0de5-3164-4526-b448-af69779ae220", + "x-ms-client-request-id" : "e620d321-5a70-482f-893b-f5807955c36a", + "Date" : "Thu, 16 Jun 2022 08:51:11 GMT" + }, + "Exception" : null + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsInBatches.json b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsInBatches.json new file mode 100644 index 0000000000000..1145eb9030cd5 --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsInBatches.json @@ -0,0 +1,38 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "f8c4603b-4458-4371-8dc0-f934d1f1c8a0", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "347a4518-3fa6-4325-aebc-582cbfef3914", + "x-ms-client-request-id" : "f8c4603b-4458-4371-8dc0-f934d1f1c8a0", + "Date" : "Thu, 16 Jun 2022 08:51:11 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "9c22b939-c5ba-4d03-92f5-c4257a00daf1", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "403030ad-7ed3-4cc2-8700-c25d9c26d90b", + "x-ms-client-request-id" : "9c22b939-c5ba-4d03-92f5-c4257a00daf1", + "Date" : "Thu, 16 Jun 2022 08:51:11 GMT" + }, + "Exception" : null + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json new file mode 100644 index 0000000000000..793206b35825c --- /dev/null +++ b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json @@ -0,0 +1,211 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "6abbd653-3124-4341-b674-39fbc2215ee9", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "0d8269a9-88c3-4e74-b885-a75103231839", + "x-ms-client-request-id" : "6abbd653-3124-4341-b674-39fbc2215ee9", + "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "34d67b72-13af-4575-b288-03aa5cbf49b7", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "Server" : "Microsoft-HTTPAPI/2.0", + "x-ms-error-code" : "NotFound", + "retry-after" : "0", + "StatusCode" : "404", + "x-ms-request-id" : "ac6fd1e1-e359-4e6d-b290-005d110d0ae1", + "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", + "x-ms-client-request-id" : "34d67b72-13af-4575-b288-03aa5cbf49b7", + "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "Content-Type" : "application/json" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "52a64de9-294c-427d-ae11-72c65c4b5032", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "154e897c-f697-4c78-92a1-a58ab5cf6b26", + "x-ms-client-request-id" : "52a64de9-294c-427d-ae11-72c65c4b5032", + "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "6bf6c265-fc26-4c46-9b09-82fa84c5b957", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "Server" : "Microsoft-HTTPAPI/2.0", + "x-ms-error-code" : "NotFound", + "retry-after" : "0", + "StatusCode" : "404", + "x-ms-request-id" : "870f4c2a-9cc1-4ad9-88f3-f29766a9dc85", + "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", + "x-ms-client-request-id" : "6bf6c265-fc26-4c46-9b09-82fa84c5b957", + "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "Content-Type" : "application/json" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "5ff84e09-beb1-4709-bcc0-f1b483616d49", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "dc0010f9-c70f-4386-abcb-c80ffbf4dee8", + "x-ms-client-request-id" : "5ff84e09-beb1-4709-bcc0-f1b483616d49", + "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "7a778092-ce54-476c-90da-6e8ea288f993", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "Server" : "Microsoft-HTTPAPI/2.0", + "x-ms-error-code" : "NotFound", + "retry-after" : "0", + "StatusCode" : "404", + "x-ms-request-id" : "537c933b-2401-4ee1-9fb5-c7ba4a26a4c9", + "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", + "x-ms-client-request-id" : "7a778092-ce54-476c-90da-6e8ea288f993", + "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "Content-Type" : "application/json" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "fe8aea60-16e3-46cf-af36-350a23faf1d2", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "2d415fe5-ce89-4005-bfb1-35d2a9d96ff8", + "x-ms-client-request-id" : "fe8aea60-16e3-46cf-af36-350a23faf1d2", + "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "62172d33-cadb-4d68-b261-0dd5d4970e2f", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "Server" : "Microsoft-HTTPAPI/2.0", + "x-ms-error-code" : "NotFound", + "retry-after" : "0", + "StatusCode" : "404", + "x-ms-request-id" : "6598624d-1871-44fa-8f64-38c0b63c0fef", + "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", + "x-ms-client-request-id" : "62172d33-cadb-4d68-b261-0dd5d4970e2f", + "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "Content-Type" : "application/json" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "0d000f5b-4909-4319-8002-e4761ceff17c", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "02cbecc5-b763-411b-be57-b68e6247e9b7", + "x-ms-client-request-id" : "0d000f5b-4909-4319-8002-e4761ceff17c", + "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "6b808f37-e765-49f5-a930-a83d4b64e11d", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "Server" : "Microsoft-HTTPAPI/2.0", + "x-ms-error-code" : "NotFound", + "retry-after" : "0", + "StatusCode" : "404", + "x-ms-request-id" : "2c21fd4b-f23f-42fa-85b4-a92febf292a3", + "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", + "x-ms-client-request-id" : "6b808f37-e765-49f5-a930-a83d4b64e11d", + "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "Content-Type" : "application/json" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "39b0a282-03c0-451a-8aa9-23e0c98f1ad1", + "Content-Type" : "application/json" + }, + "Response" : { + "Server" : "Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "8078025d-7988-4a9b-b34f-d028548a4e4a", + "x-ms-client-request-id" : "39b0a282-03c0-451a-8aa9-23e0c98f1ad1", + "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + }, + "Exception" : null + } ], + "variables" : [ ] +} \ No newline at end of file diff --git a/sdk/monitor/ci.yml b/sdk/monitor/ci.yml index bbfe35782a47c..ee0ad9c52ddfc 100644 --- a/sdk/monitor/ci.yml +++ b/sdk/monitor/ci.yml @@ -9,10 +9,12 @@ trigger: paths: include: - sdk/monitor/ci.yml + - sdk/monitor/azure-monitor-ingestion/ - sdk/monitor/azure-monitor-opentelemetry-exporter/ - sdk/monitor/azure-monitor-query/ exclude: - sdk/monitor/pom.xml + - sdk/monitor/azure-monitor-ingestion/pom.xml - sdk/monitor/azure-monitor-opentelemetry-exporter/pom.xml - sdk/monitor/azure-monitor-query/pom.xml @@ -26,6 +28,7 @@ pr: paths: include: - sdk/monitor/ci.yml + - sdk/monitor/azure-monitor-ingestion/ - sdk/monitor/azure-monitor-opentelemetry-exporter/ - sdk/monitor/azure-monitor-query/ exclude: @@ -34,6 +37,10 @@ pr: - sdk/monitor/azure-monitor-query/pom.xml parameters: +- name: release_azuremonitoringestion + displayName: 'azure-monitor-ingestion' + type: boolean + default: true - name: release_azuremonitoropentelemetryexporter displayName: 'azure-monitor-opentelemetry-exporter' type: boolean @@ -49,6 +56,10 @@ extends: ServiceDirectory: monitor EnableBatchRelease: true Artifacts: + - name: azure-monitor-ingestion + groupId: com.azure + safeName: azuremonitoringestion + releaseInBatch: ${{ parameters.release_azuremonitoringestion }} - name: azure-monitor-opentelemetry-exporter groupId: com.azure safeName: azuremonitoropentelemetryexporter From 5bbf183afd5b27d20f21f26a19bc5c1ab0dc7b76 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 11:05:58 -0700 Subject: [PATCH 07/14] more samples and readme docs --- sdk/monitor/azure-monitor-ingestion/README.md | 121 ++++++++++++++++-- .../ingestion/LogsIngestionAsyncClient.java | 10 ++ .../monitor/ingestion/CustomLogData.java | 30 +++++ .../monitor/ingestion/ReadmeSamples.java | 46 ++++++- .../monitor/ingestion/UploadLogsSample.java | 20 ++- .../ingestion/LogsCollectionClientTest.java | 48 +++---- 6 files changed, 222 insertions(+), 53 deletions(-) diff --git a/sdk/monitor/azure-monitor-ingestion/README.md b/sdk/monitor/azure-monitor-ingestion/README.md index 33291b3335ebb..f145958e86984 100644 --- a/sdk/monitor/azure-monitor-ingestion/README.md +++ b/sdk/monitor/azure-monitor-ingestion/README.md @@ -10,6 +10,9 @@ that you create in Log Analytics workspace. You can even extend the schema of bu ### Prerequisites - A [Java Development Kit (JDK)][jdk_link], version 8 or later. - [Azure Subscription][azure_subscription] +- A [Data Collection Endpoint][data_collection_endpoint] +- A [Data Collection Rule][data_collection_rule] +- A [Log Analytics workspace][log_analytics_workspace] ### Include the package @@ -21,15 +24,72 @@ that you create in Log Analytics workspace. You can even extend the schema of bu 1.0.0-beta.1 ``` + +### Create the client + +An authenticated client is required to upload logs to Azure Monitor. The library includes both synchronous and asynchronous forms of the clients. To authenticate, +the following examples use `DefaultAzureCredentialBuilder` from the [com.azure:azure-identity](https://search.maven.org/artifact/com.azure/azure-identity) package. + +#### Authenticating using Azure Active Directory +You can authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. +To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below, or other credential providers provided with the Azure SDK, please include the `azure-identity` package: +[//]: # ({x-version-update-start;com.azure:azure-identity;dependency}) +```xml + + com.azure + azure-identity + 1.5.2 + +``` +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET. + +#### Synchronous clients + +```java readme-sample-createLogsIngestionClient +DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); + +LogsIngestionClient client = new LogsIngestionClientBuilder() + .endpoint("") + .credential(tokenCredential) + .buildClient(); +``` + +#### Asynchronous clients + +```java readme-sample-createLogsIngestionAsyncClient +DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); + +LogsIngestionAsyncClient asyncClient = new LogsIngestionClientBuilder() + .endpoint("") + .credential(tokenCredential) + .buildAsyncClient(); +``` +### Uploading logs + +For examples on how to upload logs, see the [Examples](#examples) section. + ## Key concepts ### Data Collection Endpoint -Data Collection Endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. This -article provides an overview of data collection endpoints including their contents and structure and how you can create +Data Collection Endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. [This +article][data_collection_endpoint] provides an overview of data collection endpoints including their contents and structure and how you can create and work with them. -### Tables +### Data Collection Rule + +Data collection rules define data collected by Azure Monitor and specify how and where that data should be sent or +stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a +different DCR for different sources and target tables. + +The DCR must understand the structure of the input data and the structure of the target table. If the two don't match, +it can use a transformation to convert the source data to match the target table. You may also use the transform to +filter source data and perform any other calculations or conversions. + +For more details, refer to [Data collection rules in Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/essentials/data-collection-rule-overview). + +### Log Analytics Workspace Tables + Custom logs can send data to any custom table that you create and to certain built-in tables in your Log Analytics workspace. The target table must exist before you can send data to it. The following built-in tables are currently supported: @@ -38,23 +98,53 @@ workspace. The target table must exist before you can send data to it. The follo - [Syslog](https://docs.microsoft.com/azure/azure-monitor/reference/tables/syslog) - [WindowsEvents](https://docs.microsoft.com/azure/azure-monitor/reference/tables/windowsevent) -### Data Collection Rule +## Examples -Data collection rules define data collected by Azure Monitor and specify how and where that data should be sent or -stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a -different DCR for different sources and target tables. +- [Upload custom logs](#upload-custom-logs) +- [Upload custom logs with max concurrency](#upload-custom-logs-with-max-concurrency) -The DCR must understand the structure of the input data and the structure of the target table. If the two don't match, -it can use a transformation to convert the source data to match the target table. You may also use the transform to -filter source data and perform any other calculations or conversions. +### Upload custom logs -For more details, refer to [Data collection rules in Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/essentials/data-collection-rule-overview). +```java readme-sample-uploadLogs +DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); -## Examples +LogsIngestionClient client = new LogsIngestionClientBuilder() + .endpoint(" logs = getLogs(); +UploadLogsResult result = client.upload("", "", logs); +System.out.println("Logs upload result status " + result.getStatus()); +``` + +### Upload custom logs with max concurrency +```java readme-sample-uploadLogsWithMaxConcurrency +DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); + +LogsIngestionClient client = new LogsIngestionClientBuilder() + .endpoint(" logs = getLogs(); +UploadLogsOptions uploadLogsOptions = new UploadLogsOptions() + .setMaxConcurrency(3); +UploadLogsResult result = client.upload("", "", logs, uploadLogsOptions, + Context.NONE); +System.out.println("Logs upload result status " + result.getStatus()); +``` ## Troubleshooting +### Enabling Logging + +Azure SDKs for Java offer a consistent logging story to help aid in troubleshooting application errors and expedite +their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help +locate the root issue. View the [logging][logging] wiki for guidance about enabling logging. + ## Next steps +More samples can be found [here][samples]. ## Contributing @@ -77,5 +167,10 @@ For more information see the [Code of Conduct FAQ](https://opensource.microsoft. [coc_contact]: mailto:opencode@microsoft.com [jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable [azure_subscription]: https://azure.microsoft.com/free - +[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity +[samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion +[data_collection_endpoint]: https://docs.microsoft.com//azure/azure-monitor/essentials/data-collection-endpoint-overview +[data_collection_rule]: https://docs.microsoft.com/azure/azure-monitor/essentials/data-collection-rule-overview +[log_analytics_workspace]: https://docs.microsoft.com//azure/azure-monitor/logs/log-analytics-workspace-overview ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-ingestion%2FREADME.png) diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java index 513d48687247f..47868b35bd249 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java @@ -121,6 +121,8 @@ private Mono splitAndUpload(String dataCollectionRuleId, Strin } List> logBatches = new ArrayList<>(); + // TODO (srnagar): can improve memory usage by creating these request payloads right before sending the + // request if the allowed concurrency is lower than the number of requests. List requests = createGzipRequests(logs, serializer, logBatches); RequestOptions requestOptions = new RequestOptions() .addHeader(CONTENT_ENCODING, GZIP) @@ -156,8 +158,16 @@ private Mono uploadToService(String dataCollectionRule mapToResponseError(ex)))); } + /** + * Method to map the exception to {@link ResponseError}. + * @param ex the {@link HttpResponseException}. + * @return the mapped {@link ResponseError}. + */ private ResponseError mapToResponseError(HttpResponseException ex) { ResponseError responseError = null; + // with DPG clients, the error object is just a LinkedHashMap and should map to the standard error + // response structure + // https://github.com/Azure/azure-rest-api-specs/blob/main/specification/common-types/data-plane/v1/types.json#L46 if (ex.getValue() instanceof LinkedHashMap) { @SuppressWarnings("unchecked") LinkedHashMap errorMap = (LinkedHashMap) ex.getValue(); diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java index c8686ddbd4b37..3a710f8a9dd65 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/CustomLogData.java @@ -7,6 +7,9 @@ import java.time.OffsetDateTime; +/** + * An object representing custom log data as defined in the data collection rule's stream declaration. + */ public final class CustomLogData { @JsonProperty(value = "Time") @@ -20,28 +23,55 @@ public final class CustomLogData { @JsonProperty(value = "AdditionalContext") private String additionalContext; + /** + * Returns the time of creation of this log. + * @return the time of creation of this log. + */ public OffsetDateTime getTime() { return time; } + /** + * Sets the time of creation of this log. + * @param time the time of creation of this log. + * @return the updated {@link CustomLogData}. + */ public CustomLogData setTime(OffsetDateTime time) { this.time = time; return this; } + /** + * Returns the extended column field of this log. + * @return the extended column field of this log. + */ public String getExtendedColumn() { return extendedColumn; } + /** + * Sets the extended column field of this log. + * @param extendedColumn the extended column field of this log. + * @return the updated {@link CustomLogData}. + */ public CustomLogData setExtendedColumn(String extendedColumn) { this.extendedColumn = extendedColumn; return this; } + /** + * Returns the additional context field of this log. + * @return the additional context field of this log. + */ public String getAdditionalContext() { return additionalContext; } + /** + * Sets the additional context field of this log. + * @param additionalContext the additional context field of this log. + * @return the updated {@link CustomLogData}. + */ public CustomLogData setAdditionalContext(String additionalContext) { this.additionalContext = additionalContext; return this; diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java index 64488670518c0..9ffe19f21d807 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/ReadmeSamples.java @@ -3,36 +3,70 @@ package com.azure.monitor.ingestion; +import com.azure.core.util.Context; import com.azure.identity.DefaultAzureCredential; import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.monitor.ingestion.models.UploadLogsOptions; import com.azure.monitor.ingestion.models.UploadLogsResult; import java.util.List; /** - * + * Class to include all the README.md code samples. */ public final class ReadmeSamples { + /** + * Sample to demonstrate creation of a synchronous client. + */ public void createClient() { + // BEGIN: readme-sample-createLogsIngestionClient DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); LogsIngestionClient client = new LogsIngestionClientBuilder() - .endpoint("") .credential(tokenCredential) .buildClient(); + // END: readme-sample-createLogsIngestionClient } + /** + * Sample to demonstrate creation of an asynchronous client. + */ public void createAsyncClient() { + // BEGIN: readme-sample-createLogsIngestionAsyncClient DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); LogsIngestionAsyncClient asyncClient = new LogsIngestionClientBuilder() - .endpoint("") .credential(tokenCredential) .buildAsyncClient(); + // END: readme-sample-createLogsIngestionAsyncClient } + /** + * Sample to demonstrate uploading logs to Azure Monitor. + */ public void uploadLogs() { + // BEGIN: readme-sample-uploadLogs + DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); + + LogsIngestionClient client = new LogsIngestionClientBuilder() + .endpoint(" logs = getLogs(); + UploadLogsResult result = client.upload("", "", logs); + System.out.println("Logs upload result status " + result.getStatus()); + // END: readme-sample-uploadLogs + } + + /** + * Sample to demonstrate uploading logs to Azure Monitor. + */ + public void uploadLogsWithMaxConcurrency() { + // BEGIN: readme-sample-uploadLogsWithMaxConcurrency DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); LogsIngestionClient client = new LogsIngestionClientBuilder() @@ -41,8 +75,12 @@ public void uploadLogs() { .buildClient(); List logs = getLogs(); - UploadLogsResult result = client.upload("", "", logs, uploadLogsOptions, + Context.NONE); System.out.println("Logs upload result status " + result.getStatus()); + // END: readme-sample-uploadLogsWithMaxConcurrency } private List getLogs() { diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java index 843257ec16687..dbd68e914cb4a 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion/UploadLogsSample.java @@ -11,12 +11,13 @@ import java.util.List; /** - * + * Sample to demonstrate uploading logs to Azure Monitor. */ public final class UploadLogsSample { /** - * @param args + * Main method to run the sample. + * @param args ignore args. */ public static void main(String[] args) { LogsIngestionClient client = new LogsIngestionClientBuilder() @@ -24,16 +25,21 @@ public static void main(String[] args) { .credential(new DefaultAzureCredentialBuilder().build()) .buildClient(); - List dataList = new ArrayList<>(); + List dataList = getLogs(); + UploadLogsResult result = client.upload(" getLogs() { + List logs = new ArrayList<>(); for (int i = 0; i < 10; i++) { CustomLogData e = new CustomLogData() .setTime(OffsetDateTime.now()) - .setExtendedColumn("columndata" + i) + .setExtendedColumn("extend column data" + i) .setAdditionalContext("more logs context"); - dataList.add(e); + logs.add(e); } - UploadLogsResult result = client.upload(" dataList = new ArrayList<>(); - - for (int i = 0; i < 10; i++) { - LogData logData = new LogData() - .setTime(OffsetDateTime.now()) - .setExtendedColumn("test" + i) - .setAdditionalContext("additional logs context"); - dataList.add(logData); - } + List logs = getObjects(10); LogsIngestionClient client = clientBuilder.buildClient(); - UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, dataList); + UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, logs); assertEquals(UploadLogsStatus.SUCCESS, result.getStatus()); } @Test public void testUploadLogsInBatches() { - List dataList = new ArrayList<>(); - for (int i = 0; i < 10000; i++) { - LogData logData = new LogData() - .setTime(OffsetDateTime.now()) - .setExtendedColumn("test" + i) - .setAdditionalContext("additional logs context"); - dataList.add(logData); - } + List logs = getObjects(10000); AtomicInteger count = new AtomicInteger(); LogsIngestionClient client = clientBuilder @@ -123,22 +108,14 @@ public HttpPipelinePosition getPipelinePosition() { } }) .buildClient(); - UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, dataList); + UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, logs); assertEquals(UploadLogsStatus.SUCCESS, result.getStatus()); assertEquals(2, count.get()); } @Test public void testUploadLogsPartialFailure() { - List dataList = new ArrayList<>(); - for (int i = 0; i < 100000; i++) { - LogData logData = new LogData() - .setTime(OffsetDateTime.now()) - .setExtendedColumn("test" + i) - .setAdditionalContext("additional logs context"); - dataList.add(logData); - } - + List logs = getObjects(100000); AtomicBoolean changeDcrId = new AtomicBoolean(); AtomicInteger count = new AtomicInteger(); @@ -165,10 +142,23 @@ public HttpPipelinePosition getPipelinePosition() { }) .buildClient(); - UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, dataList); + UploadLogsResult result = client.upload(dataCollectionRuleId, streamName, logs); assertEquals(UploadLogsStatus.PARTIAL_FAILURE, result.getStatus()); assertEquals(11, count.get()); assertEquals(5, result.getErrors().size()); result.getErrors().stream().forEach(error -> assertEquals("NotFound", error.getResponseError().getCode())); } + + private List getObjects(int x) { + List logs = new ArrayList<>(); + + for (int i = 0; i < x; i++) { + LogData logData = new LogData() + .setTime(OffsetDateTime.now()) + .setExtendedColumn("test" + i) + .setAdditionalContext("additional logs context"); + logs.add(logData); + } + return logs; + } } From a87c0ee5766a162b70076cafabccf6e79add0fe5 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 11:16:54 -0700 Subject: [PATCH 08/14] update readme --- sdk/monitor/azure-monitor-ingestion/README.md | 17 ++++++++++------- sdk/monitor/azure-monitor-ingestion/pom.xml | 6 ------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/sdk/monitor/azure-monitor-ingestion/README.md b/sdk/monitor/azure-monitor-ingestion/README.md index f145958e86984..c61c190131485 100644 --- a/sdk/monitor/azure-monitor-ingestion/README.md +++ b/sdk/monitor/azure-monitor-ingestion/README.md @@ -43,7 +43,7 @@ To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below ``` Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET. -#### Synchronous clients +#### Synchronous Logs Ingestion client ```java readme-sample-createLogsIngestionClient DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); @@ -54,7 +54,7 @@ LogsIngestionClient client = new LogsIngestionClientBuilder() .buildClient(); ``` -#### Asynchronous clients +#### Asynchronous Logs Ingestion client ```java readme-sample-createLogsIngestionAsyncClient DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); @@ -161,16 +161,19 @@ For more information see the [Code of Conduct FAQ](https://opensource.microsoft. [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity +[azure_monitor_overview]: https://docs.microsoft.com/azure/azure-monitor/overview +[azure_subscription]: https://azure.microsoft.com/free [cla]: https://cla.microsoft.com [coc]: https://opensource.microsoft.com/codeofconduct/ [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ [coc_contact]: mailto:opencode@microsoft.com -[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable -[azure_subscription]: https://azure.microsoft.com/free -[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential -[azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity -[samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion [data_collection_endpoint]: https://docs.microsoft.com//azure/azure-monitor/essentials/data-collection-endpoint-overview [data_collection_rule]: https://docs.microsoft.com/azure/azure-monitor/essentials/data-collection-rule-overview +[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential +[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable [log_analytics_workspace]: https://docs.microsoft.com//azure/azure-monitor/logs/log-analytics-workspace-overview +[logging]: https://docs.microsoft.com//azure/developer/java/sdk/logging-overview +[samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/src/samples/java/com/azure/monitor/ingestion + ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-ingestion%2FREADME.png) diff --git a/sdk/monitor/azure-monitor-ingestion/pom.xml b/sdk/monitor/azure-monitor-ingestion/pom.xml index fec04e622868c..62ff4662e0c1c 100644 --- a/sdk/monitor/azure-monitor-ingestion/pom.xml +++ b/sdk/monitor/azure-monitor-ingestion/pom.xml @@ -91,12 +91,6 @@ 1.9.1 test - - org.mockito - mockito-core - 3.6.28 - test - io.projectreactor reactor-test From e041e85109a64867df1ac31b8d81a179825dfeaa Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 11:32:59 -0700 Subject: [PATCH 09/14] fix tests --- sdk/monitor/azure-monitor-ingestion/pom.xml | 8 +- .../ingestion/LogsCollectionClientTest.java | 15 +-- ...ientTest.testUploadLogsPartialFailure.json | 109 +++++++++++------- 3 files changed, 77 insertions(+), 55 deletions(-) diff --git a/sdk/monitor/azure-monitor-ingestion/pom.xml b/sdk/monitor/azure-monitor-ingestion/pom.xml index 62ff4662e0c1c..b651967494404 100644 --- a/sdk/monitor/azure-monitor-ingestion/pom.xml +++ b/sdk/monitor/azure-monitor-ingestion/pom.xml @@ -70,19 +70,19 @@ org.junit.jupiter junit-jupiter-api - 5.7.1 + 5.8.2 test org.junit.jupiter junit-jupiter-engine - 5.7.1 + 5.8.2 test org.junit.jupiter junit-jupiter-params - 5.7.1 + 5.8.2 test @@ -94,7 +94,7 @@ io.projectreactor reactor-test - 3.4.3 + 3.4.17 test diff --git a/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java index 066830108635e..f7eb78df3f3fa 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java +++ b/sdk/monitor/azure-monitor-ingestion/src/test/java/com/azure/monitor/ingestion/LogsCollectionClientTest.java @@ -36,15 +36,16 @@ */ public class LogsCollectionClientTest extends TestBase { private LogsIngestionClientBuilder clientBuilder; + private String dataCollectionEndpoint; private String dataCollectionRuleId; private String streamName; - private String dataCollectionEndpoint; @BeforeEach public void setup() { - dataCollectionEndpoint = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_ENDPOINT"); - dataCollectionRuleId = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_RULE_ID"); - streamName = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_STREAM_NAME"); + dataCollectionEndpoint = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_ENDPOINT", + "https://dce.monitor.azure.com"); + dataCollectionRuleId = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_RULE_ID", "dcr-adec84661d05465f8532f32a04af6f98"); + streamName = Configuration.getGlobalConfiguration().get("DATA_COLLECTION_STREAM_NAME", "Custom-MyTableRawData"); LogsIngestionClientBuilder clientBuilder = new LogsIngestionClientBuilder() .retryPolicy(new RetryPolicy(new RetryStrategy() { @@ -149,12 +150,12 @@ public HttpPipelinePosition getPipelinePosition() { result.getErrors().stream().forEach(error -> assertEquals("NotFound", error.getResponseError().getCode())); } - private List getObjects(int x) { + private List getObjects(int logsCount) { List logs = new ArrayList<>(); - for (int i = 0; i < x; i++) { + for (int i = 0; i < logsCount; i++) { LogData logData = new LogData() - .setTime(OffsetDateTime.now()) + .setTime(OffsetDateTime.parse("2022-01-01T00:00:00+07:00")) .setExtendedColumn("test" + i) .setAdditionalContext("additional logs context"); logs.add(logData); diff --git a/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json index 793206b35825c..b374ea029cfb8 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json +++ b/sdk/monitor/azure-monitor-ingestion/src/test/resources/session-records/LogsCollectionClientTest.testUploadLogsPartialFailure.json @@ -4,16 +4,16 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "6abbd653-3124-4341-b674-39fbc2215ee9", + "x-ms-client-request-id" : "ba12563a-8b6a-47c7-8488-f59951a2e551", "Content-Type" : "application/json" }, "Response" : { "Server" : "Microsoft-HTTPAPI/2.0", "retry-after" : "0", "StatusCode" : "204", - "x-ms-request-id" : "0d8269a9-88c3-4e74-b885-a75103231839", - "x-ms-client-request-id" : "6abbd653-3124-4341-b674-39fbc2215ee9", - "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + "x-ms-request-id" : "69e30197-7ce2-4bed-926e-fe10ad327568", + "x-ms-client-request-id" : "ba12563a-8b6a-47c7-8488-f59951a2e551", + "Date" : "Thu, 16 Jun 2022 18:25:26 GMT" }, "Exception" : null }, { @@ -21,7 +21,7 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "34d67b72-13af-4575-b288-03aa5cbf49b7", + "x-ms-client-request-id" : "74894721-dc74-4b4a-a3c7-df4062a42e68", "Content-Type" : "application/json" }, "Response" : { @@ -30,10 +30,10 @@ "x-ms-error-code" : "NotFound", "retry-after" : "0", "StatusCode" : "404", - "x-ms-request-id" : "ac6fd1e1-e359-4e6d-b290-005d110d0ae1", + "x-ms-request-id" : "c1c2001e-76c7-4e0c-abb2-2773971abac0", "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", - "x-ms-client-request-id" : "34d67b72-13af-4575-b288-03aa5cbf49b7", - "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "x-ms-client-request-id" : "74894721-dc74-4b4a-a3c7-df4062a42e68", + "Date" : "Thu, 16 Jun 2022 18:25:26 GMT", "Content-Type" : "application/json" }, "Exception" : null @@ -42,16 +42,16 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "52a64de9-294c-427d-ae11-72c65c4b5032", + "x-ms-client-request-id" : "b0b9d6ba-38c3-49ab-99ab-79e86f4b0982", "Content-Type" : "application/json" }, "Response" : { "Server" : "Microsoft-HTTPAPI/2.0", "retry-after" : "0", "StatusCode" : "204", - "x-ms-request-id" : "154e897c-f697-4c78-92a1-a58ab5cf6b26", - "x-ms-client-request-id" : "52a64de9-294c-427d-ae11-72c65c4b5032", - "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + "x-ms-request-id" : "7a70dff4-0be9-4045-98e0-73b129c493d0", + "x-ms-client-request-id" : "b0b9d6ba-38c3-49ab-99ab-79e86f4b0982", + "Date" : "Thu, 16 Jun 2022 18:25:26 GMT" }, "Exception" : null }, { @@ -59,7 +59,7 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "6bf6c265-fc26-4c46-9b09-82fa84c5b957", + "x-ms-client-request-id" : "f60d2aec-eea1-4300-b733-ae6ba7cbda37", "Content-Type" : "application/json" }, "Response" : { @@ -68,10 +68,10 @@ "x-ms-error-code" : "NotFound", "retry-after" : "0", "StatusCode" : "404", - "x-ms-request-id" : "870f4c2a-9cc1-4ad9-88f3-f29766a9dc85", + "x-ms-request-id" : "b004c1a3-5506-444f-bc35-f710595245de", "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", - "x-ms-client-request-id" : "6bf6c265-fc26-4c46-9b09-82fa84c5b957", - "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "x-ms-client-request-id" : "f60d2aec-eea1-4300-b733-ae6ba7cbda37", + "Date" : "Thu, 16 Jun 2022 18:25:27 GMT", "Content-Type" : "application/json" }, "Exception" : null @@ -80,16 +80,16 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "5ff84e09-beb1-4709-bcc0-f1b483616d49", + "x-ms-client-request-id" : "b777e620-9921-4d5e-95d0-e462c9cbd33f", "Content-Type" : "application/json" }, "Response" : { "Server" : "Microsoft-HTTPAPI/2.0", "retry-after" : "0", "StatusCode" : "204", - "x-ms-request-id" : "dc0010f9-c70f-4386-abcb-c80ffbf4dee8", - "x-ms-client-request-id" : "5ff84e09-beb1-4709-bcc0-f1b483616d49", - "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + "x-ms-request-id" : "446d6029-5d7a-46ba-b3c0-50cb84c2042c", + "x-ms-client-request-id" : "b777e620-9921-4d5e-95d0-e462c9cbd33f", + "Date" : "Thu, 16 Jun 2022 18:25:26 GMT" }, "Exception" : null }, { @@ -97,7 +97,7 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "7a778092-ce54-476c-90da-6e8ea288f993", + "x-ms-client-request-id" : "a60d95bf-6c8b-42b2-a9c9-a8f853e3067f", "Content-Type" : "application/json" }, "Response" : { @@ -106,10 +106,10 @@ "x-ms-error-code" : "NotFound", "retry-after" : "0", "StatusCode" : "404", - "x-ms-request-id" : "537c933b-2401-4ee1-9fb5-c7ba4a26a4c9", + "x-ms-request-id" : "adb2a2b0-c6bb-4f22-ab12-5c922953b5b0", "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", - "x-ms-client-request-id" : "7a778092-ce54-476c-90da-6e8ea288f993", - "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "x-ms-client-request-id" : "a60d95bf-6c8b-42b2-a9c9-a8f853e3067f", + "Date" : "Thu, 16 Jun 2022 18:25:27 GMT", "Content-Type" : "application/json" }, "Exception" : null @@ -118,16 +118,16 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "fe8aea60-16e3-46cf-af36-350a23faf1d2", + "x-ms-client-request-id" : "ec094474-8acf-43a6-9ca4-065f1d3755ff", "Content-Type" : "application/json" }, "Response" : { "Server" : "Microsoft-HTTPAPI/2.0", "retry-after" : "0", "StatusCode" : "204", - "x-ms-request-id" : "2d415fe5-ce89-4005-bfb1-35d2a9d96ff8", - "x-ms-client-request-id" : "fe8aea60-16e3-46cf-af36-350a23faf1d2", - "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + "x-ms-request-id" : "e78cb09f-95c3-476f-b095-b1543a52527d", + "x-ms-client-request-id" : "ec094474-8acf-43a6-9ca4-065f1d3755ff", + "Date" : "Thu, 16 Jun 2022 18:25:26 GMT" }, "Exception" : null }, { @@ -135,7 +135,7 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "62172d33-cadb-4d68-b261-0dd5d4970e2f", + "x-ms-client-request-id" : "de648fff-bf1b-4d94-8d97-5148471e4c49", "Content-Type" : "application/json" }, "Response" : { @@ -144,10 +144,10 @@ "x-ms-error-code" : "NotFound", "retry-after" : "0", "StatusCode" : "404", - "x-ms-request-id" : "6598624d-1871-44fa-8f64-38c0b63c0fef", + "x-ms-request-id" : "4f2011fd-52eb-4c03-a0f0-0e682e8a948c", "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", - "x-ms-client-request-id" : "62172d33-cadb-4d68-b261-0dd5d4970e2f", - "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "x-ms-client-request-id" : "de648fff-bf1b-4d94-8d97-5148471e4c49", + "Date" : "Thu, 16 Jun 2022 18:25:27 GMT", "Content-Type" : "application/json" }, "Exception" : null @@ -156,16 +156,16 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "0d000f5b-4909-4319-8002-e4761ceff17c", + "x-ms-client-request-id" : "7f58c754-166c-4450-886c-0db96e341a6c", "Content-Type" : "application/json" }, "Response" : { "Server" : "Microsoft-HTTPAPI/2.0", "retry-after" : "0", "StatusCode" : "204", - "x-ms-request-id" : "02cbecc5-b763-411b-be57-b68e6247e9b7", - "x-ms-client-request-id" : "0d000f5b-4909-4319-8002-e4761ceff17c", - "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + "x-ms-request-id" : "ba784388-2330-4459-99ec-d2ba226362e2", + "x-ms-client-request-id" : "7f58c754-166c-4450-886c-0db96e341a6c", + "Date" : "Thu, 16 Jun 2022 18:25:26 GMT" }, "Exception" : null }, { @@ -173,7 +173,7 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "6b808f37-e765-49f5-a930-a83d4b64e11d", + "x-ms-client-request-id" : "0df5188d-72cc-40a1-88f3-9ca372f5b4bf", "Content-Type" : "application/json" }, "Response" : { @@ -182,10 +182,10 @@ "x-ms-error-code" : "NotFound", "retry-after" : "0", "StatusCode" : "404", - "x-ms-request-id" : "2c21fd4b-f23f-42fa-85b4-a92febf292a3", + "x-ms-request-id" : "90723b98-f2c4-4063-8097-41c0dcea0ddd", "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", - "x-ms-client-request-id" : "6b808f37-e765-49f5-a930-a83d4b64e11d", - "Date" : "Thu, 16 Jun 2022 08:55:43 GMT", + "x-ms-client-request-id" : "0df5188d-72cc-40a1-88f3-9ca372f5b4bf", + "Date" : "Thu, 16 Jun 2022 18:25:27 GMT", "Content-Type" : "application/json" }, "Exception" : null @@ -194,16 +194,37 @@ "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-adec84661d05465f8532f32a04af6f98/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", "Headers" : { "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", - "x-ms-client-request-id" : "39b0a282-03c0-451a-8aa9-23e0c98f1ad1", + "x-ms-client-request-id" : "8fc878bb-eef7-4c1c-aabb-a0917e72a0b8", "Content-Type" : "application/json" }, "Response" : { "Server" : "Microsoft-HTTPAPI/2.0", "retry-after" : "0", "StatusCode" : "204", - "x-ms-request-id" : "8078025d-7988-4a9b-b34f-d028548a4e4a", - "x-ms-client-request-id" : "39b0a282-03c0-451a-8aa9-23e0c98f1ad1", - "Date" : "Thu, 16 Jun 2022 08:55:44 GMT" + "x-ms-request-id" : "56dba2c6-f910-4a6b-8a99-8b18d4a4b880", + "x-ms-client-request-id" : "8fc878bb-eef7-4c1c-aabb-a0917e72a0b8", + "Date" : "Thu, 16 Jun 2022 18:25:27 GMT" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.westus2-1.ingest.monitor.azure.com/dataCollectionRules/dcr-id/streams/Custom-MyTableRawData?api-version=2021-11-01-preview", + "Headers" : { + "User-Agent" : "azsdk-java-azure-monitor-ingestion/1.0.0-beta.1 (17.0.2; Windows 10; 10.0)", + "x-ms-client-request-id" : "78560d24-7c33-4cf5-a3ef-31d69b0671c3", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "Server" : "Microsoft-HTTPAPI/2.0", + "x-ms-error-code" : "NotFound", + "retry-after" : "0", + "StatusCode" : "404", + "x-ms-request-id" : "9fe41f22-b7b3-4ac2-9854-d74946d65d66", + "Body" : "{\"error\":{\"code\":\"NotFound\",\"message\":\"Data collection rule with immutable Id 'dcr-id' not found.\"}}", + "x-ms-client-request-id" : "78560d24-7c33-4cf5-a3ef-31d69b0671c3", + "Date" : "Thu, 16 Jun 2022 18:25:27 GMT", + "Content-Type" : "application/json" }, "Exception" : null } ], From 65acb48cc17c2e37910158d6c35215615905925d Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 11:34:15 -0700 Subject: [PATCH 10/14] make final --- .../com/azure/monitor/ingestion/models/UploadLogsError.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java index 2fc4b6cc8ecea..ab27a7678953b 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/models/UploadLogsError.java @@ -13,7 +13,7 @@ * Monitor. */ @Immutable -public class UploadLogsError { +public final class UploadLogsError { private final ResponseError responseError; private final List failedLogs; From d922450fcd11c01e74a83eef71b2ff1bef954f6d Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 13:41:59 -0700 Subject: [PATCH 11/14] address pr comments --- sdk/monitor/azure-monitor-ingestion/README.md | 6 +- .../ingestion/LogsIngestionAsyncClient.java | 6 +- .../implementation/DefaultJsonSerializer.java | 84 ------------------- 3 files changed, 6 insertions(+), 90 deletions(-) delete mode 100644 sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java diff --git a/sdk/monitor/azure-monitor-ingestion/README.md b/sdk/monitor/azure-monitor-ingestion/README.md index c61c190131485..78ae33bb3247c 100644 --- a/sdk/monitor/azure-monitor-ingestion/README.md +++ b/sdk/monitor/azure-monitor-ingestion/README.md @@ -73,12 +73,12 @@ For examples on how to upload logs, see the [Examples](#examples) section. ### Data Collection Endpoint Data Collection Endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. [This -article][data_collection_endpoint] provides an overview of data collection endpoints including their contents and structure and how you can create -and work with them. +article][data_collection_endpoint] provides an overview of data collection endpoints including their contents and +structure and how you can create and work with them. ### Data Collection Rule -Data collection rules define data collected by Azure Monitor and specify how and where that data should be sent or +Data collection rules (DCR) define data collected by Azure Monitor and specify how and where that data should be sent or stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a different DCR for different sources and target tables. diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java index 47868b35bd249..d68585092e266 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java @@ -12,8 +12,9 @@ import com.azure.core.util.BinaryData; import com.azure.core.util.Context; import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JsonSerializer; +import com.azure.core.util.serializer.JsonSerializerProviders; import com.azure.core.util.serializer.ObjectSerializer; -import com.azure.monitor.ingestion.implementation.DefaultJsonSerializer; import com.azure.monitor.ingestion.implementation.IngestionUsingDataCollectionRulesAsyncClient; import com.azure.monitor.ingestion.implementation.UploadLogsResponseHolder; import com.azure.monitor.ingestion.models.UploadLogsError; @@ -50,8 +51,7 @@ public final class LogsIngestionAsyncClient { private static final String CONTENT_ENCODING = "Content-Encoding"; private static final long MAX_REQUEST_PAYLOAD_SIZE = 1024 * 1024; // 1 MB private static final String GZIP = "gzip"; - // TODO (srnagar): Move DefaultJsonSerializer in azure-core to public package - private static final DefaultJsonSerializer DEFAULT_SERIALIZER = new DefaultJsonSerializer(); + private static final JsonSerializer DEFAULT_SERIALIZER = JsonSerializerProviders.createInstance(true); private final IngestionUsingDataCollectionRulesAsyncClient service; diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java deleted file mode 100644 index 9dad455b93b08..0000000000000 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/implementation/DefaultJsonSerializer.java +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.monitor.ingestion.implementation; - -import com.azure.core.util.logging.ClientLogger; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.JsonSerializer; -import com.azure.core.util.serializer.SerializerAdapter; -import com.azure.core.util.serializer.SerializerEncoding; -import com.azure.core.util.serializer.TypeReference; -import reactor.core.publisher.Mono; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UncheckedIOException; - -/** - * Jackson based implementation of the {@link JsonSerializer}. This can be used as a default Json serializer if - * no JsonSerializerProvider is in the class path. - */ -public final class DefaultJsonSerializer implements JsonSerializer { - // DefaultJsonSerializer is a commonly used class, use a static logger. - private static final ClientLogger LOGGER = new ClientLogger(DefaultJsonSerializer.class); - - private final SerializerAdapter jacksonAdapter = JacksonAdapter.createDefaultSerializerAdapter(); - - @Override - public T deserializeFromBytes(byte[] data, TypeReference typeReference) { - try { - return jacksonAdapter.deserialize(data, typeReference.getJavaType(), SerializerEncoding.JSON); - } catch (IOException e) { - throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); - } - } - - @Override - public T deserialize(InputStream stream, TypeReference typeReference) { - try { - return jacksonAdapter.deserialize(stream, typeReference.getJavaType(), SerializerEncoding.JSON); - } catch (IOException e) { - throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); - } - } - - @Override - public Mono deserializeFromBytesAsync(byte[] data, TypeReference typeReference) { - return Mono.fromCallable(() -> deserializeFromBytes(data, typeReference)); - } - - @Override - public Mono deserializeAsync(InputStream stream, TypeReference typeReference) { - return Mono.fromCallable(() -> deserialize(stream, typeReference)); - } - - @Override - public byte[] serializeToBytes(Object value) { - try { - return jacksonAdapter.serializeToBytes(value, SerializerEncoding.JSON); - } catch (IOException e) { - throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); - } - } - - @Override - public void serialize(OutputStream stream, Object value) { - try { - jacksonAdapter.serialize(value, SerializerEncoding.JSON, stream); - } catch (IOException e) { - throw LOGGER.logExceptionAsError(new UncheckedIOException(e)); - } - } - - @Override - public Mono serializeToBytesAsync(Object value) { - return Mono.fromCallable(() -> serializeToBytes(value)); - } - - @Override - public Mono serializeAsync(OutputStream stream, Object value) { - return Mono.fromRunnable(() -> serialize(stream, value)); - } -} From 43d892a5e5fb95b33ca41aa9188d4b1737108c6b Mon Sep 17 00:00:00 2001 From: Srikanta Date: Thu, 16 Jun 2022 13:46:48 -0700 Subject: [PATCH 12/14] fix broken links --- .../azure-monitor-ingestion/src/samples/README.md | 14 +++++++------- .../azure-monitor-ingestion/swagger/README.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/monitor/azure-monitor-ingestion/src/samples/README.md b/sdk/monitor/azure-monitor-ingestion/src/samples/README.md index 4bfa8c365c5f8..7aa8f84e35855 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/samples/README.md +++ b/sdk/monitor/azure-monitor-ingestion/src/samples/README.md @@ -1,4 +1,4 @@ -# Azure Logs Ingestion client library for Java +# Azure Monitor Ingestion client library for Java ## Getting started Getting started explained in detail [here][SDK_README_GETTING_STARTED]. @@ -19,10 +19,10 @@ See [Next steps][SDK_README_NEXT_STEPS]. This project welcomes contributions and suggestions. Find [more contributing][SDK_README_CONTRIBUTING] details here. -[SDK_README_CONTRIBUTING]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#contributing -[SDK_README_GETTING_STARTED]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#getting-started -[SDK_README_TROUBLESHOOTING]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#troubleshooting -[SDK_README_KEY_CONCEPTS]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#key-concepts -[SDK_README_NEXT_STEPS]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-logingestion/README.md#next-steps +[SDK_README_CONTRIBUTING]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/README.md#contributing +[SDK_README_GETTING_STARTED]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/README.md#getting-started +[SDK_README_TROUBLESHOOTING]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/README.md#troubleshooting +[SDK_README_KEY_CONCEPTS]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/README.md#key-concepts +[SDK_README_NEXT_STEPS]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor/azure-monitor-ingestion/README.md#next-steps -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-logingestion%2FREADME.png) +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fmonitor%2Fazure-monitor-ingestion%2FREADME.png) diff --git a/sdk/monitor/azure-monitor-ingestion/swagger/README.md b/sdk/monitor/azure-monitor-ingestion/swagger/README.md index faf447ac9d35b..754bfb67eee8d 100644 --- a/sdk/monitor/azure-monitor-ingestion/swagger/README.md +++ b/sdk/monitor/azure-monitor-ingestion/swagger/README.md @@ -1,4 +1,4 @@ -# Azure Logs Ingestion client library for Java +# Azure Monitor Ingestion client library for Java ## Code generation settings From ae1f09b09922c1661f035c108b2b1bc4c5b20f81 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Fri, 17 Jun 2022 12:32:29 -0700 Subject: [PATCH 13/14] address pr comments --- pom.xml | 7 ++-- sdk/monitor/azure-monitor-ingestion/README.md | 9 +++-- .../ingestion/LogsIngestionAsyncClient.java | 37 ++++++++++++------- .../ingestion/LogsIngestionClient.java | 4 ++ 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 28f19ed8c5cab..694e863fcd222 100644 --- a/pom.xml +++ b/pom.xml @@ -345,9 +345,10 @@ 1.8 Azure SDK for Java Reference Documentation Azure SDK for Java Reference Documentation -
Visit the <a href="https://docs.microsoft.com/java/azure/">Azure for Java Developers</a> site - for more Java documentation, including quick starts, tutorials, and code samples. -
+ + + + false *.impl*: diff --git a/sdk/monitor/azure-monitor-ingestion/README.md b/sdk/monitor/azure-monitor-ingestion/README.md index 78ae33bb3247c..6221f1d1e874f 100644 --- a/sdk/monitor/azure-monitor-ingestion/README.md +++ b/sdk/monitor/azure-monitor-ingestion/README.md @@ -64,10 +64,6 @@ LogsIngestionAsyncClient asyncClient = new LogsIngestionClientBuilder() .credential(tokenCredential) .buildAsyncClient(); ``` -### Uploading logs - -For examples on how to upload logs, see the [Examples](#examples) section. - ## Key concepts ### Data Collection Endpoint @@ -119,6 +115,11 @@ System.out.println("Logs upload result status " + result.getStatus()); ``` ### Upload custom logs with max concurrency + +If the in input logs collection is too large, the client will split the input into multiple smaller requests. These +requests are sent serially, by default, but by configuring the max concurrency in `UploadLogsOptions`, these requests +can be concurrently sent to the service as shown in the example below. + ```java readme-sample-uploadLogsWithMaxConcurrency DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build(); diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java index d68585092e266..f627ca23b06b8 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionAsyncClient.java @@ -31,7 +31,7 @@ import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -68,6 +68,8 @@ public final class LogsIngestionAsyncClient { * logs sent in this request. * @param logs the collection of logs to be uploaded. * @return the result of the logs upload request. + * @throws NullPointerException if any of {@code dataCollectionRuleId}, {@code streamName} or {@code logs} are null. + * @throws IllegalArgumentException if {@code logs} is empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono upload(String dataCollectionRuleId, String streamName, List logs) { @@ -84,6 +86,8 @@ public Mono upload(String dataCollectionRuleId, String streamN * @param logs the collection of logs to be uploaded. * @param options the options to configure the upload request. * @return the result of the logs upload request. + * @throws NullPointerException if any of {@code dataCollectionRuleId}, {@code streamName} or {@code logs} are null. + * @throws IllegalArgumentException if {@code logs} is empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono upload(String dataCollectionRuleId, String streamName, @@ -144,7 +148,7 @@ private UploadLogsResult mapResult(Iterator> logBatchesIterator, Up List logsBatch = logBatchesIterator.next(); if (responseHolder.getStatus() == UploadLogsStatus.FAILURE) { return new UploadLogsResult(responseHolder.getStatus(), - Arrays.asList(new UploadLogsError(responseHolder.getResponseError(), logsBatch))); + Collections.singletonList(new UploadLogsError(responseHolder.getResponseError(), logsBatch))); } return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); } @@ -154,7 +158,7 @@ private Mono uploadToService(String dataCollectionRule BinaryData.fromBytes(bytes), requestOptions) .map(response -> new UploadLogsResponseHolder(UploadLogsStatus.SUCCESS, null)) .onErrorResume(HttpResponseException.class, - ex -> Mono.just(new UploadLogsResponseHolder(UploadLogsStatus.FAILURE, + ex -> Mono.fromSupplier(() -> new UploadLogsResponseHolder(UploadLogsStatus.FAILURE, mapToResponseError(ex)))); } @@ -186,19 +190,24 @@ private ResponseError mapToResponseError(HttpResponseException ex) { } private UploadLogsResult createResponse(List results) { - boolean allErrors = results.stream().allMatch(result -> result.getStatus() == UploadLogsStatus.FAILURE); - if (allErrors) { - return new UploadLogsResult(UploadLogsStatus.FAILURE, - results.stream().flatMap(result -> result.getErrors().stream()).collect(Collectors.toList())); + int failureCount = 0; + List errors = null; + for (UploadLogsResult result : results) { + if (result.getStatus() != UploadLogsStatus.SUCCESS) { + failureCount++; + if (errors == null) { + errors = new ArrayList<>(); + } + errors.addAll(result.getErrors()); + } } - - boolean anyErrors = results.stream().anyMatch(result -> result.getStatus() == UploadLogsStatus.FAILURE); - if (anyErrors) { - return new UploadLogsResult(UploadLogsStatus.PARTIAL_FAILURE, - results.stream().filter(result -> result.getStatus() == UploadLogsStatus.FAILURE) - .flatMap(result -> result.getErrors().stream()).collect(Collectors.toList())); + if (failureCount == 0) { + return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); } - return new UploadLogsResult(UploadLogsStatus.SUCCESS, null); + if (failureCount < results.size()) { + return new UploadLogsResult(UploadLogsStatus.PARTIAL_FAILURE, errors); + } + return new UploadLogsResult(UploadLogsStatus.FAILURE, errors); } private List createGzipRequests(List logs, ObjectSerializer serializer, diff --git a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java index 51960c6831307..ded564ab32314 100644 --- a/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java +++ b/sdk/monitor/azure-monitor-ingestion/src/main/java/com/azure/monitor/ingestion/LogsIngestionClient.java @@ -34,6 +34,8 @@ public final class LogsIngestionClient { * logs sent in this request. * @param logs the collection of logs to be uploaded. * @return the result of the logs upload request. + * @throws NullPointerException if any of {@code dataCollectionRuleId}, {@code streamName} or {@code logs} are null. + * @throws IllegalArgumentException if {@code logs} is empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public UploadLogsResult upload(String dataCollectionRuleId, String streamName, List logs) { @@ -53,6 +55,8 @@ public UploadLogsResult upload(String dataCollectionRuleId, String streamName, L * @param context additional context that is passed through the Http pipeline during the service call. If no * additional context is required, pass {@link Context#NONE} instead. * @return the result of the logs upload request. + * @throws NullPointerException if any of {@code dataCollectionRuleId}, {@code streamName} or {@code logs} are null. + * @throws IllegalArgumentException if {@code logs} is empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public UploadLogsResult upload(String dataCollectionRuleId, String streamName, From 4a2771df4867aa6a949779cfb8f03bbfa34edfe1 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Fri, 17 Jun 2022 15:02:52 -0700 Subject: [PATCH 14/14] update changelog date --- sdk/monitor/azure-monitor-ingestion/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md b/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md index 6842f1666cc43..2f048879f6480 100644 --- a/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-ingestion/CHANGELOG.md @@ -1,10 +1,10 @@ # Release History -## 1.0.0-beta.1 (Unreleased) +## 1.0.0-beta.1 (2022-06-17) Version 1.0.0-beta.1 is a preview of our efforts in creating a client library for Azure Logs Ingestion that is developer-friendly, idiomatic to the Java ecosystem, and as consistent across different languages and platforms as possible. The principles that guide our efforts can be found in the [Azure SDK Design Guidelines for Java](https://azure.github.io/azure-sdk/java_introduction.html). ## Features Added -- Initial release. Please see the README and wiki for information on using the new library. +- Initial release. Please see the README for information on using the new library.