Skip to content

Commit

Permalink
Perf tests for monitor query (Azure#18063)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarishmaGhiya authored Oct 6, 2021
1 parent 1c4d060 commit a3d8612
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 2 deletions.
25 changes: 23 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@
"projectFolder": "sdk/appconfiguration/perf-tests/app-configuration",
"versionPolicyName": "test"
},
{
"packageName": "@azure-tests/perf-monitor-query",
"projectFolder": "sdk/monitor/perf-tests/monitor-query",
"versionPolicyName": "test"
},
{
"packageName": "@azure/mixed-reality-remote-rendering",
"projectFolder": "sdk/remoterendering/mixed-reality-remote-rendering",
Expand Down
13 changes: 13 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Guide

1. Build the monitor-query perf tests package `rush build -t perf-monitor-query`.
2. Copy the `sample.env` file and name it as `.env`.
3. Create log analytics workspace account and populate the `.env` file with the values of variables specified from the `sample.env`
4. Run the tests as follows:

- metrics query
- `npm run perf-test:node -- MetricsQueryTest --warmup 1 --iterations 1 --parallel 50 --duration 15`
- log query
- `npm run perf-test:node -- LogQueryTest --warmup 1 --iterations 1 --parallel 50 --duration 15`
- log batch query
- `npm run perf-test:node -- LogQueryBatchTest --warmup 1 --iterations 1 --parallel 50 --duration 15`
48 changes: 48 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@azure-tests/perf-monitor-query",
"sdk-type": "perf-test",
"version": "1.0.0",
"description": "",
"main": "",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@azure/monitor-query": "1.0.0-beta.6",
"@azure/test-utils-perfstress": "^1.0.0",
"dotenv": "^8.2.0",
"@azure/identity": "2.0.0-beta.7"
},
"devDependencies": {
"@types/node": "^12.0.0",
"eslint": "^7.15.0",
"prettier": "^1.16.4",
"rimraf": "^3.0.0",
"tslib": "^2.2.0",
"ts-node": "^10.0.0",
"typescript": "~4.2.0"
},
"private": true,
"scripts": {
"perf-test:node": "ts-node test/index.spec.ts",
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build": "npm run clean && tsc -p .",
"build:samples": "echo skipped",
"build:test": "echo skipped",
"check-format": "prettier --list-different --config ../../../../.prettierrc.json --ignore-path ../../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-esm test-dist types *.tgz *.log",
"format": "prettier --write --config ../../../../.prettierrc.json --ignore-path ../../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "echo skipped",
"integration-test:node": "echo skipped",
"integration-test": "echo skipped",
"lint:fix": "eslint --no-eslintrc -c ../../../.eslintrc.internal.json package.json test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint --no-eslintrc -c ../../../.eslintrc.internal.json package.json test --ext .ts",
"pack": "npm pack 2>&1",
"unit-test:browser": "echo skipped",
"unit-test:node": "echo skipped",
"unit-test": "echo skipped",
"test:browser": "echo skipped",
"test:node": "echo skipped",
"test": "echo skipped"
}
}
21 changes: 21 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Retrieve these values from an instance in the Azure Portal.
MONITOR_WORKSPACE_ID=<The "Workspace ID", as given in the Azure portal for your Log Analytics resource>
METRICS_RESOURCE_ID=<An Azure resource ID to query for metrics. Ex: /subscriptions/<full resource path>>

# Used by tests and samples to populate data
APPLICATIONINSIGHTS_CONNECTION_STRING=<Azure Application Insights connection string>

# Used to authenticate using Azure AD as a service principal for role-based authentication.
#
# See the documentation for `EnvironmentCredential` at the following link:
# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential
AZURE_TENANT_ID=<AD tenant id or name>
AZURE_CLIENT_ID=<ID of the user/service principal to authenticate as>
AZURE_CLIENT_SECRET=<client secret used to authenticate to Azure AD>


# Our tests assume that TEST_MODE is "playback" by default. You can change it
# to "record" to generate new recordings, or "live" to bypass the recorder
# entirely.

# TEST_MODE="playback"
14 changes: 14 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
import { MetricsQueryTest } from "./metricQuery.spec";
import { LogQueryBatchTest } from "./logQueryBatch.spec";
import { LogQueryTest } from "./logQuery.spec";

console.log("=== Starting the perfStress test ===");

const perfStressProgram = new PerfStressProgram(
selectPerfStressTest([MetricsQueryTest, LogQueryBatchTest, LogQueryTest])
);
perfStressProgram.run();
25 changes: 25 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/test/logQuery.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { PerfStressOptionDictionary, getEnvVar } from "@azure/test-utils-perfstress";
import { MonitorQueryLog } from "./monitorQueryLog.spec";

type MonitorQueryTestOptions = Record<string, unknown>;

export class LogQueryTest extends MonitorQueryLog<MonitorQueryTestOptions> {
workspaceId: string;
query: string;
public options: PerfStressOptionDictionary<MonitorQueryTestOptions> = {};
constructor() {
super();
this.workspaceId = getEnvVar("MONITOR_WORKSPACE_ID");
this.query =
"AppRequests | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId";
}

async runAsync(): Promise<void> {
await this.client.queryWorkspace(this.workspaceId, this.query, {
startTime: new Date("2021-07-25"),
endTime: new Date("2021-07-26")
});
}
}
40 changes: 40 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/test/logQueryBatch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { PerfStressOptionDictionary, getEnvVar } from "@azure/test-utils-perfstress";
import { MonitorQueryLog } from "./monitorQueryLog.spec";
import { QueryBatch } from "@azure/monitor-query";

type MonitorQueryTestOptions = Record<string, unknown>;

export class LogQueryBatchTest extends MonitorQueryLog<MonitorQueryTestOptions> {
workspaceId: string;
queryBatch: QueryBatch[];
public options: PerfStressOptionDictionary<MonitorQueryTestOptions> = {};
constructor() {
super();
this.workspaceId = getEnvVar("MONITOR_WORKSPACE_ID");
this.queryBatch = [
{
workspaceId: this.workspaceId,
query: "AzureActivity | summarize count()",
timespan: { startTime: new Date("2021-07-25"), endTime: new Date("2021-07-26") }
},
{
workspaceId: this.workspaceId,
query:
"AppRequests | take 10 | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId",
timespan: { startTime: new Date("2021-07-25"), endTime: new Date("2021-07-26") }
},
{
workspaceId: this.workspaceId,
query: "AppRequests | take 2",
timespan: { duration: "" },
includeQueryStatistics: true
}
];
}

async runAsync(): Promise<void> {
await this.client.queryBatch(this.queryBatch);
}
}
26 changes: 26 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/test/metricQuery.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { PerfStressOptionDictionary, getEnvVar } from "@azure/test-utils-perfstress";
import { AggregationType } from "@azure/monitor-query";
import { MonitorQueryMetrics } from "./monitorQueryMetrics.spec";

type MonitorQueryTestOptions = Record<string, unknown>;

export class MetricsQueryTest extends MonitorQueryMetrics<MonitorQueryTestOptions> {
metricsUri: string;
metricNames: string[];
aggregations: AggregationType[];
public options: PerfStressOptionDictionary<MonitorQueryTestOptions> = {};
constructor() {
super();
this.metricsUri = getEnvVar("METRICS_RESOURCE_ID");
this.metricNames = ["SuccessfulCalls"];
this.aggregations = ["Count"];
}

async runAsync(): Promise<void> {
await this.client.queryResource(this.metricsUri, this.metricNames, {
aggregations: this.aggregations
});
}
}
20 changes: 20 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/test/monitorQueryLog.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressTest } from "@azure/test-utils-perfstress";
import { LogsQueryClient } from "@azure/monitor-query";
import { DefaultAzureCredential } from "@azure/identity";

// Expects the .env file at the same level
import * as dotenv from "dotenv";
dotenv.config();

export abstract class MonitorQueryLog<TOptions> extends PerfStressTest<TOptions> {
client: LogsQueryClient;

constructor() {
super();
const tokenCredential = new DefaultAzureCredential();
this.client = new LogsQueryClient(tokenCredential);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressTest } from "@azure/test-utils-perfstress";
import { MetricsQueryClient } from "@azure/monitor-query";
import { DefaultAzureCredential } from "@azure/identity";

// Expects the .env file at the same level
import * as dotenv from "dotenv";
dotenv.config();

export abstract class MonitorQueryMetrics<TOptions> extends PerfStressTest<TOptions> {
client: MetricsQueryClient;

constructor() {
super();
const tokenCredential = new DefaultAzureCredential();
this.client = new MetricsQueryClient(tokenCredential);
}
}
10 changes: 10 additions & 0 deletions sdk/monitor/perf-tests/monitor-query/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../../tsconfig.package",
"compilerOptions": {
"module": "CommonJS",
"lib": ["ES6", "ESNext.AsyncIterable"],
"noEmit": true
},
"compileOnSave": true,
"include": ["./test/**/*.ts"]
}

0 comments on commit a3d8612

Please sign in to comment.