Skip to content

Commit

Permalink
Perf tests for Azure Monitor Query (Azure#23280)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
srnagar and alzimmermsft authored Aug 3, 2021
1 parent 566badb commit ffba1ab
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 0 deletions.
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions sdk/monitor/azure-monitor-query-perf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 1.0.0-beta.1 (Unreleased)


67 changes: 67 additions & 0 deletions sdk/monitor/azure-monitor-query-perf/README.md
Original file line number Diff line number Diff line change
@@ -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=<Tenant ID of Azure subscription>
AZURE_CLIENT_ID=<Client ID of Azure AAD application>
AZURE_CLIENT_SECRET=<Client secret of Azure AAD application>
AZURE_MONITOR_LOGS_WORKSPACE_ID=<Workspace ID of Log Analytics workspace>
AZURE_MONITOR_METRICS_RESOURCE_ID=<Resource ID of an Azure Resource>
```

## 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 <path-to-packaged-jar-with-dependencies-from-step-1> <options-for-the-test>
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

<!-- LINKS -->
[azure_subscription]: https://azure.microsoft.com/free
[jdk_link]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable
68 changes: 68 additions & 0 deletions sdk/monitor/azure-monitor-query-perf/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.azure</groupId>
<artifactId>azure-client-sdk-parent</artifactId>
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} -->
<relativePath>../../parents/azure-client-sdk-parent</relativePath>
</parent>

<groupId>com.azure</groupId>
<artifactId>azure-monitor-query-perf</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-monitor-query-perf;current} -->
<packaging>jar</packaging>

<name>Microsoft Azure client library for Logs and Metrics query performance tests</name>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>perf-test-core</artifactId>
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:perf-test-core;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-monitor-query</artifactId>
<version>1.0.0-beta.3</version> <!-- {x-version-update;com.azure:azure-monitor-query;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.3.4</version> <!-- {x-version-update;com.azure:azure-identity;dependency} -->
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-assembly-plugin;external_dependency} -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.azure.monitor.query.perf.App
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* Test scenarios:
* <ul>
* <li>Query logs from Azure Monitor Log Analytics workspace</li>
* <li>Query metrics from Azure Monitor for an Azure resource</li>
* </ul>
* 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}
* <p>
* To run performance tests in IntelliJ, set all the required environment variables via {@code Run -&gt; 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<PerfStressOptions> {

private static final List<String> 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<Void> runAsync() {
return logsQueryAsyncClient.queryLogsBatch(workspaceId, LOGS_BATCH_QUERIES, null).then();
}
}
Original file line number Diff line number Diff line change
@@ -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<PerfStressOptions> {

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<Void> runAsync() {
return logsQueryAsyncClient.queryLogs(workspaceId, LOGS_QUERY, null)
.map(response -> response.getResultAsObject(CustomModel.class))
.then();
}
}
Original file line number Diff line number Diff line change
@@ -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<PerfStressOptions> {
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<Void> runAsync() {
return logsQueryAsyncClient.queryLogs(workspaceId, LOGS_QUERY, null).then();
}
}
Loading

0 comments on commit ffba1ab

Please sign in to comment.