From ffba1aba445dfd46a16676bca25c34ab01c3167d Mon Sep 17 00:00:00 2001 From: Srikanta <51379715+srnagar@users.noreply.github.com> Date: Tue, 3 Aug 2021 19:47:06 +0000 Subject: [PATCH] Perf tests for Azure Monitor Query (#23280) * Perf tests for Azure Monitor Query * fix docs * add module to version_client.txt * Update sdk/monitor/azure-monitor-query-perf/pom.xml Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> * Update sdk/monitor/azure-monitor-query-perf/pom.xml Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> --- eng/versioning/version_client.txt | 1 + .../azure-monitor-query-perf/CHANGELOG.md | 5 ++ .../azure-monitor-query-perf/README.md | 67 +++++++++++++++ sdk/monitor/azure-monitor-query-perf/pom.xml | 68 +++++++++++++++ .../com/azure/monitor/query/perf/App.java | 34 ++++++++ .../azure/monitor/query/perf/CustomModel.java | 86 +++++++++++++++++++ .../query/perf/LogsBatchQueryTest.java | 42 +++++++++ .../query/perf/LogsQueryAsModelTest.java | 41 +++++++++ .../monitor/query/perf/LogsQueryTest.java | 40 +++++++++ .../monitor/query/perf/MetricsQueryTest.java | 45 ++++++++++ .../monitor/query/perf/core/ServiceTest.java | 48 +++++++++++ sdk/monitor/pom.xml | 1 + 12 files changed, 478 insertions(+) create mode 100644 sdk/monitor/azure-monitor-query-perf/CHANGELOG.md create mode 100644 sdk/monitor/azure-monitor-query-perf/README.md create mode 100644 sdk/monitor/azure-monitor-query-perf/pom.xml create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/App.java create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/CustomModel.java create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsBatchQueryTest.java create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryAsModelTest.java create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryTest.java create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/MetricsQueryTest.java create mode 100644 sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/core/ServiceTest.java diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index a6e286b6dc99d..db987f4840d22 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -103,6 +103,7 @@ com.azure:azure-mixedreality-authentication;1.0.0;1.1.0 com.azure:azure-mixedreality-remoterendering;1.0.0;1.1.0-beta.1 com.azure:azure-monitor-opentelemetry-exporter;1.0.0-beta.4;1.0.0-beta.5 com.azure:azure-monitor-query;1.0.0-beta.2;1.0.0-beta.3 +com.azure:azure-monitor-query-perf;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-quantum-jobs;1.0.0-beta.1;1.0.0-beta.2 com.azure:azure-search-documents;11.4.0;11.5.0-beta.2 com.azure:azure-search-perf;1.0.0-beta.1;1.0.0-beta.1 diff --git a/sdk/monitor/azure-monitor-query-perf/CHANGELOG.md b/sdk/monitor/azure-monitor-query-perf/CHANGELOG.md new file mode 100644 index 0000000000000..2a2738d963818 --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/CHANGELOG.md @@ -0,0 +1,5 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + + diff --git a/sdk/monitor/azure-monitor-query-perf/README.md b/sdk/monitor/azure-monitor-query-perf/README.md new file mode 100644 index 0000000000000..290ebb2b3685c --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/README.md @@ -0,0 +1,67 @@ +# Azure Monitor Query Performance test client library for Java + +Represents Performance tests for Azure Monitor Query SDK for Java. + +## Getting started + +### Prerequisites + +- A [Java Development Kit (JDK)][jdk_link], version 8 or later. +- [Azure Subscription][azure_subscription] + +#### Setup for test resources + +You will need the following environment variables for running the tests to access the live resources: + +``` +AZURE_TENANT_ID= +AZURE_CLIENT_ID= +AZURE_CLIENT_SECRET= +AZURE_MONITOR_LOGS_WORKSPACE_ID= +AZURE_MONITOR_METRICS_RESOURCE_ID= +``` + +## Key concepts + +## Examples +#### Executing the performance test +1. Compile the performance project into a standalone jar using the command from the root of the perf project folder +``` + mvn clean package -f sdk/monitor/azure-monitor-query-perf/pom.xml +``` + +2. Execute the corresponding perf test in the project using the command. +``` + java -jar + java -jar sdk/monitor/azure-monitor-query-perf/target/azure-monitor-query-perf-1.0.0-beta.1-jar-with-dependencies.jar logsquery --warmup 1 --iterations 1 --parallel 50 --duration 15 --count 1000 + java -jar sdk/monitor/azure-monitor-query-perf/target/azure-monitor-query-perf-1.0.0-beta.1-jar-with-dependencies.jar logsbatchquery --warmup 1 --iterations 1 --parallel 50 --duration 15 --count 1000 + java -jar sdk/monitor/azure-monitor-query-perf/target/azure-monitor-query-perf-1.0.0-beta.1-jar-with-dependencies.jar logsqueryasmodel --warmup 1 --iterations 1 --parallel 50 --duration 15 --count 1000 + java -jar sdk/monitor/azure-monitor-query-perf/target/azure-monitor-query-perf-1.0.0-beta.1-jar-with-dependencies.jar metricsquery --warmup 1 --iterations 1 --parallel 50 --duration 15 --count 1000 +``` + +#### Common perf test command line options for Azure Monitor Query +- `--duration` - Number of seconds to run the main test for. Default is 10. +- `--iterations` - Number of iterations of main test loop. +- `--parallel` - Number of operations to execute in parallel, +- `--warmup` - Duration of test warmup time in seconds before the test attributes are calculated. + +Use [PerfStressOptions](https://github.com/Azure/azure-sdk-for-java/blob/main/common/perf-test-core/src/main/java/com/azure/perf/test/core/PerfStressOptions.java) +for the other command line options that could be used. + +## Troubleshooting + +## Next steps + +## Contributing + +For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md). + +1. Fork it +1. Create your feature branch (`git checkout -b my-new-feature`) +1. Commit your changes (`git commit -am 'Add some feature'`) +1. Push to the branch (`git push origin my-new-feature`) +1. Create new Pull Request + + +[azure_subscription]: https://azure.microsoft.com/free +[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable diff --git a/sdk/monitor/azure-monitor-query-perf/pom.xml b/sdk/monitor/azure-monitor-query-perf/pom.xml new file mode 100644 index 0000000000000..5a2b959a7899b --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-monitor-query-perf + 1.0.0-beta.1 + jar + + Microsoft Azure client library for Logs and Metrics query performance tests + + + + com.azure + perf-test-core + 1.0.0-beta.1 + + + com.azure + azure-monitor-query + 1.0.0-beta.3 + + + com.azure + azure-identity + 1.3.4 + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.2.0 + + + package + + single + + + + + + com.azure.monitor.query.perf.App + + + + + jar-with-dependencies + + + + + + + + diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/App.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/App.java new file mode 100644 index 0000000000000..4f4cce4a186f1 --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/App.java @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.perf; + +import com.azure.perf.test.core.PerfStressProgram; + +/** + * Runs Azure Monitor Query performance tests. + *

+ * Test scenarios: + *

    + *
  • Query logs from Azure Monitor Log Analytics workspace
  • + *
  • Query metrics from Azure Monitor for an Azure resource
  • + *
+ * To run performance tests from the command line, package the project into an uber jar using {@code mvn clean + * package}. Then run the program using {@code java -jar compiled-jar-with-dependencies-path} + *

+ * To run performance tests in IntelliJ, set all the required environment variables via {@code Run -> Edit + * Configurations} section. Then run the App's main method. + */ +public class App { + /** + * Main method to invoke performance tests + * + * @param args Arguments to the performance tests. + */ + public static void main(String[] args) { + PerfStressProgram.run(new Class[]{LogsQueryTest.class, + LogsBatchQueryTest.class, + LogsQueryAsModelTest.class, + MetricsQueryTest.class}, args); + } +} diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/CustomModel.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/CustomModel.java new file mode 100644 index 0000000000000..b518f9b3709d3 --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/CustomModel.java @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.perf; + +import java.time.OffsetDateTime; + +/** + * A custom model to read the logs query result. + */ +public final class CustomModel { + private OffsetDateTime timeGenerated; + private String tenantId; + private String id; + private String source; + private Boolean success; + private Double durationMs; + private Object properties; + private String operationName; + private String operationId; + + + /** + * Returns the time the log event was generated. + * @return the time the log event was generated. + */ + public OffsetDateTime getTimeGenerated() { + return timeGenerated; + } + + /** + * Returns the tenant id of the resource for which this log was recorded. + * @return the tenant id of the resource for which this log was recorded. + */ + public String getTenantId() { + return tenantId; + } + + /** + * Returns the unique identifier of this log. + * @return the unique identifier of this log. + */ + public String getId() { + return id; + } + + /** + * Returns the source of this log. + * @return the source of this log. + */ + public String getSource() { + return source; + } + + /** + * Returns {@code true} if the logged request returned a successful response. + * @return {@code true} if the logged request returned a successful response. + */ + public Boolean getSuccess() { + return success; + } + + /** + * Returns the time duration the service took to process the request. + * @return the time duration the service took to process the request. + */ + public Double getDurationMs() { + return durationMs; + } + + /** + * Returns additional properties of the request. + * @return additional properties of the request. + */ + public Object getProperties() { + return properties; + } + + /** + * Returns the name of the operation. + * @return the name of the operation. + */ + public String getOperationName() { + return operationName; + } +} diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsBatchQueryTest.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsBatchQueryTest.java new file mode 100644 index 0000000000000..e4c511fd9546b --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsBatchQueryTest.java @@ -0,0 +1,42 @@ +package com.azure.monitor.query.perf; + +import com.azure.core.util.Configuration; +import com.azure.monitor.query.LogsQueryClient; +import com.azure.monitor.query.perf.core.ServiceTest; +import com.azure.perf.test.core.PerfStressOptions; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; + +/** + * This class tests the performance of a batch of logs queries using the {@link LogsQueryClient}. + */ +public class LogsBatchQueryTest extends ServiceTest { + + private static final List LOGS_BATCH_QUERIES = Arrays + .asList("AppRequests | take 100", "AzureActivity | take 100", "AppPerformanceCounters | take 100"); + private final String workspaceId; + + /** + * Creates an instance of logs batch query perf test. + * @param options the configurable options for perf testing this class + */ + public LogsBatchQueryTest(PerfStressOptions options) { + super(options); + workspaceId = Configuration.getGlobalConfiguration().get("AZURE_MONITOR_LOGS_WORKSPACE_ID"); + if (workspaceId == null) { + throw new IllegalStateException(String.format(CONFIGURATION_ERROR, "AZURE_MONITOR_LOGS_WORKSPACE_ID")); + } + } + + @Override + public void run() { + logsQueryClient.queryLogsBatch(workspaceId, LOGS_BATCH_QUERIES, null); + } + + @Override + public Mono runAsync() { + return logsQueryAsyncClient.queryLogsBatch(workspaceId, LOGS_BATCH_QUERIES, null).then(); + } +} diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryAsModelTest.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryAsModelTest.java new file mode 100644 index 0000000000000..08e012913847f --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryAsModelTest.java @@ -0,0 +1,41 @@ +package com.azure.monitor.query.perf; + +import com.azure.core.util.Configuration; +import com.azure.monitor.query.LogsQueryClient; +import com.azure.monitor.query.perf.core.ServiceTest; +import com.azure.perf.test.core.PerfStressOptions; +import reactor.core.publisher.Mono; + +/** + * This class tests the performance of a single logs query that maps the response to a custom model type using the + * {@link LogsQueryClient}. + */ +public class LogsQueryAsModelTest extends ServiceTest { + + private static final String LOGS_QUERY = "AppRequests | take 100"; + private final String workspaceId; + + /** + * Creates an instance of logs query perf test. + * @param options the configurable options for perf testing this class + */ + public LogsQueryAsModelTest(PerfStressOptions options) { + super(options); + workspaceId = Configuration.getGlobalConfiguration().get("AZURE_MONITOR_LOGS_WORKSPACE_ID"); + if (workspaceId == null) { + throw new IllegalStateException(String.format(CONFIGURATION_ERROR, "AZURE_MONITOR_LOGS_WORKSPACE_ID")); + } + } + + @Override + public void run() { + logsQueryClient.queryLogs(workspaceId, LOGS_QUERY, null).getResultAsObject(CustomModel.class); + } + + @Override + public Mono runAsync() { + return logsQueryAsyncClient.queryLogs(workspaceId, LOGS_QUERY, null) + .map(response -> response.getResultAsObject(CustomModel.class)) + .then(); + } +} diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryTest.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryTest.java new file mode 100644 index 0000000000000..2e2472d2e394f --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/LogsQueryTest.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.perf; + +import com.azure.core.util.Configuration; +import com.azure.monitor.query.LogsQueryClient; +import com.azure.monitor.query.perf.core.ServiceTest; +import com.azure.perf.test.core.PerfStressOptions; +import reactor.core.publisher.Mono; + +/** + * This class tests the performance of a single logs query using the {@link LogsQueryClient}. + */ +public class LogsQueryTest extends ServiceTest { + private static final String LOGS_QUERY = "AppRequests | take 100"; + private final String workspaceId; + + /** + * Creates an instance of logs query perf test. + * @param options the configurable options for perf testing this class + */ + public LogsQueryTest(PerfStressOptions options) { + super(options); + workspaceId = Configuration.getGlobalConfiguration().get("AZURE_MONITOR_LOGS_WORKSPACE_ID"); + if (workspaceId == null) { + throw new IllegalStateException(String.format(CONFIGURATION_ERROR, "AZURE_MONITOR_LOGS_WORKSPACE_ID")); + } + } + + @Override + public void run() { + logsQueryClient.queryLogs(workspaceId, LOGS_QUERY, null); + } + + @Override + public Mono runAsync() { + return logsQueryAsyncClient.queryLogs(workspaceId, LOGS_QUERY, null).then(); + } +} diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/MetricsQueryTest.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/MetricsQueryTest.java new file mode 100644 index 0000000000000..76e807ae23296 --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/MetricsQueryTest.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.perf; + +import com.azure.core.util.Configuration; +import com.azure.core.util.Context; +import com.azure.monitor.query.MetricsQueryClient; +import com.azure.monitor.query.models.MetricsQueryOptions; +import com.azure.monitor.query.perf.core.ServiceTest; +import com.azure.perf.test.core.PerfStressOptions; +import reactor.core.publisher.Mono; + +import java.util.Arrays; + +/** + * This class tests the performance of a basic metrics query using the {@link MetricsQueryClient}. + */ +public class MetricsQueryTest extends ServiceTest { + private final String resourceId; + + /** + * Creates an instance of metrics query perf test. + * @param options the configurable options for perf testing this class + */ + public MetricsQueryTest(PerfStressOptions options) { + super(options); + resourceId = Configuration.getGlobalConfiguration().get("AZURE_MONITOR_METRICS_RESOURCE_ID"); + if (resourceId == null) { + throw new IllegalStateException(String.format(CONFIGURATION_ERROR, "AZURE_MONITOR_METRICS_RESOURCE_ID")); + } + } + + @Override + public void run() { + metricsQueryClient.queryMetricsWithResponse(resourceId, Arrays.asList("SuccessfulCalls"), + new MetricsQueryOptions().setTop(100), Context.NONE); + } + + @Override + public Mono runAsync() { + return metricsQueryAsyncClient.queryMetricsWithResponse(resourceId, Arrays.asList("SuccessfulCalls"), + new MetricsQueryOptions().setTop(100)).then(); + } +} diff --git a/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/core/ServiceTest.java b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/core/ServiceTest.java new file mode 100644 index 0000000000000..0ebc448211ab8 --- /dev/null +++ b/sdk/monitor/azure-monitor-query-perf/src/main/java/com/azure/monitor/query/perf/core/ServiceTest.java @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.monitor.query.perf.core; + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.monitor.query.LogsQueryAsyncClient; +import com.azure.monitor.query.LogsQueryClient; +import com.azure.monitor.query.LogsQueryClientBuilder; +import com.azure.monitor.query.MetricsQueryAsyncClient; +import com.azure.monitor.query.MetricsQueryClient; +import com.azure.monitor.query.MetricsQueryClientBuilder; +import com.azure.perf.test.core.PerfStressOptions; +import com.azure.perf.test.core.PerfStressTest; + +/** + * Base class for Azure Monitor Query performance tests. + */ +public abstract class ServiceTest extends PerfStressTest { + public static final String CONFIGURATION_ERROR = "Configuration %s must be set in either environment variables " + + "or system properties.%n"; + + protected final LogsQueryClient logsQueryClient; + protected final LogsQueryAsyncClient logsQueryAsyncClient; + protected final MetricsQueryClient metricsQueryClient; + protected final MetricsQueryAsyncClient metricsQueryAsyncClient; + + /** + * The base class for Azure Monitor Query performance tests. + * @param options the configurable options for performing perf testing on this class. + */ + public ServiceTest(TOptions options) { + super(options); + + LogsQueryClientBuilder logsQueryClientBuilder = new LogsQueryClientBuilder() + .credential(new DefaultAzureCredentialBuilder().build()); + + MetricsQueryClientBuilder metricsQueryClientBuilder = new MetricsQueryClientBuilder() + .credential(new DefaultAzureCredentialBuilder().build()); + this.logsQueryClient = logsQueryClientBuilder.buildClient(); + this.logsQueryAsyncClient = logsQueryClientBuilder.buildAsyncClient(); + + this.metricsQueryClient = metricsQueryClientBuilder.buildClient(); + this.metricsQueryAsyncClient = metricsQueryClientBuilder.buildAsyncClient(); + } +} diff --git a/sdk/monitor/pom.xml b/sdk/monitor/pom.xml index 3c4cf0f78327a..dd8c5a5ea6e3a 100644 --- a/sdk/monitor/pom.xml +++ b/sdk/monitor/pom.xml @@ -60,6 +60,7 @@ azure-monitor-opentelemetry-exporter azure-monitor-query + azure-monitor-query-perf