diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index c17792e0b32f..49853c433067 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -94,6 +94,7 @@ specifiers: '@rush-temp/perf-keyvault-certificates': file:./projects/perf-keyvault-certificates.tgz '@rush-temp/perf-keyvault-keys': file:./projects/perf-keyvault-keys.tgz '@rush-temp/perf-keyvault-secrets': file:./projects/perf-keyvault-secrets.tgz + '@rush-temp/perf-monitor-query': file:./projects/perf-monitor-query.tgz '@rush-temp/perf-search-documents': file:./projects/perf-search-documents.tgz '@rush-temp/perf-service-bus': file:./projects/perf-service-bus.tgz '@rush-temp/perf-storage-blob': file:./projects/perf-storage-blob.tgz @@ -223,6 +224,7 @@ dependencies: '@rush-temp/perf-keyvault-certificates': file:projects/perf-keyvault-certificates.tgz '@rush-temp/perf-keyvault-keys': file:projects/perf-keyvault-keys.tgz '@rush-temp/perf-keyvault-secrets': file:projects/perf-keyvault-secrets.tgz + '@rush-temp/perf-monitor-query': file:projects/perf-monitor-query.tgz '@rush-temp/perf-search-documents': file:projects/perf-search-documents.tgz '@rush-temp/perf-service-bus': file:projects/perf-service-bus.tgz '@rush-temp/perf-storage-blob': file:projects/perf-storage-blob.tgz @@ -633,7 +635,7 @@ packages: resolution: {integrity: sha512-Q71Buur3RMcg6lCnisLL8Im562DBw+ybzgm+YQj/FbAaI8ZNu/zl/5z1fE4k3Q9LSIzYrz6HLRzlhdSBXpydlQ==} engines: {node: '>=8.0.0'} dependencies: - '@azure/core-http': 1.2.3 + '@azure/core-http': 1.2.6 '@azure/core-tracing': 1.0.0-preview.9 '@azure/logger': 1.0.3 '@azure/msal-node': 1.0.0-beta.6_debug@4.3.2 @@ -3048,7 +3050,7 @@ packages: resolution: {integrity: sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==} deprecated: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797) dependencies: - ms: 2.1.1 + ms: 2.1.3 dev: false /debug/3.2.7: @@ -11575,6 +11577,25 @@ packages: - supports-color dev: false + file:projects/perf-monitor-query.tgz: + resolution: {integrity: sha512-toEUj6i3XyxLZWIO8erTWaghQaQddo1Fqg5bXigfnfm1Ols9D49XWJlL1TkD4NN02MU04u0j6yYQu+dHSZ+SxQ==, tarball: file:projects/perf-monitor-query.tgz} + name: '@rush-temp/perf-monitor-query' + version: 0.0.0 + dependencies: + '@types/node': 12.20.27 + dotenv: 8.6.0 + eslint: 7.32.0 + prettier: 1.19.1 + rimraf: 3.0.2 + ts-node: 10.2.1_3c2c35653f239e2d026eed3c3359ac92 + tslib: 2.3.1 + typescript: 4.2.4 + transitivePeerDependencies: + - '@swc/core' + - '@swc/wasm' + - supports-color + dev: false + file:projects/perf-search-documents.tgz: resolution: {integrity: sha512-JzZnuFWDzadcVL5Ch79lQLH2bLQbEGlh4m4RjmcE2FQMSUpyEeD6RsgRZjvdp9S1snhJgUHCnjNg8C/k/2GJzg==, tarball: file:projects/perf-search-documents.tgz} name: '@rush-temp/perf-search-documents' diff --git a/rush.json b/rush.json index d55ea3797916..b5c589b79b03 100644 --- a/rush.json +++ b/rush.json @@ -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", diff --git a/sdk/monitor/perf-tests/monitor-query/README.md b/sdk/monitor/perf-tests/monitor-query/README.md new file mode 100644 index 000000000000..654dd7d76974 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/README.md @@ -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` diff --git a/sdk/monitor/perf-tests/monitor-query/package.json b/sdk/monitor/perf-tests/monitor-query/package.json new file mode 100644 index 000000000000..96a70e09ec0f --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/package.json @@ -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" + } +} diff --git a/sdk/monitor/perf-tests/monitor-query/sample.env b/sdk/monitor/perf-tests/monitor-query/sample.env new file mode 100644 index 000000000000..30b090a8026d --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/sample.env @@ -0,0 +1,21 @@ +# Retrieve these values from an instance in the Azure Portal. +MONITOR_WORKSPACE_ID= +METRICS_RESOURCE_ID=> + +# Used by tests and samples to populate data +APPLICATIONINSIGHTS_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= +AZURE_CLIENT_ID= +AZURE_CLIENT_SECRET= + + +# 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" \ No newline at end of file diff --git a/sdk/monitor/perf-tests/monitor-query/test/index.spec.ts b/sdk/monitor/perf-tests/monitor-query/test/index.spec.ts new file mode 100644 index 000000000000..d581e2a242d0 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/test/index.spec.ts @@ -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(); diff --git a/sdk/monitor/perf-tests/monitor-query/test/logQuery.spec.ts b/sdk/monitor/perf-tests/monitor-query/test/logQuery.spec.ts new file mode 100644 index 000000000000..d76aafa44071 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/test/logQuery.spec.ts @@ -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; + +export class LogQueryTest extends MonitorQueryLog { + workspaceId: string; + query: string; + public options: PerfStressOptionDictionary = {}; + constructor() { + super(); + this.workspaceId = getEnvVar("MONITOR_WORKSPACE_ID"); + this.query = + "AppRequests | summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId"; + } + + async runAsync(): Promise { + await this.client.queryWorkspace(this.workspaceId, this.query, { + startTime: new Date("2021-07-25"), + endTime: new Date("2021-07-26") + }); + } +} diff --git a/sdk/monitor/perf-tests/monitor-query/test/logQueryBatch.spec.ts b/sdk/monitor/perf-tests/monitor-query/test/logQueryBatch.spec.ts new file mode 100644 index 000000000000..7630014a82e7 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/test/logQueryBatch.spec.ts @@ -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; + +export class LogQueryBatchTest extends MonitorQueryLog { + workspaceId: string; + queryBatch: QueryBatch[]; + public options: PerfStressOptionDictionary = {}; + 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 { + await this.client.queryBatch(this.queryBatch); + } +} diff --git a/sdk/monitor/perf-tests/monitor-query/test/metricQuery.spec.ts b/sdk/monitor/perf-tests/monitor-query/test/metricQuery.spec.ts new file mode 100644 index 000000000000..37dbf42fdf53 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/test/metricQuery.spec.ts @@ -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; + +export class MetricsQueryTest extends MonitorQueryMetrics { + metricsUri: string; + metricNames: string[]; + aggregations: AggregationType[]; + public options: PerfStressOptionDictionary = {}; + constructor() { + super(); + this.metricsUri = getEnvVar("METRICS_RESOURCE_ID"); + this.metricNames = ["SuccessfulCalls"]; + this.aggregations = ["Count"]; + } + + async runAsync(): Promise { + await this.client.queryResource(this.metricsUri, this.metricNames, { + aggregations: this.aggregations + }); + } +} diff --git a/sdk/monitor/perf-tests/monitor-query/test/monitorQueryLog.spec.ts b/sdk/monitor/perf-tests/monitor-query/test/monitorQueryLog.spec.ts new file mode 100644 index 000000000000..c4023c679441 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/test/monitorQueryLog.spec.ts @@ -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 extends PerfStressTest { + client: LogsQueryClient; + + constructor() { + super(); + const tokenCredential = new DefaultAzureCredential(); + this.client = new LogsQueryClient(tokenCredential); + } +} diff --git a/sdk/monitor/perf-tests/monitor-query/test/monitorQueryMetrics.spec.ts b/sdk/monitor/perf-tests/monitor-query/test/monitorQueryMetrics.spec.ts new file mode 100644 index 000000000000..07dfc433b8d7 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/test/monitorQueryMetrics.spec.ts @@ -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 extends PerfStressTest { + client: MetricsQueryClient; + + constructor() { + super(); + const tokenCredential = new DefaultAzureCredential(); + this.client = new MetricsQueryClient(tokenCredential); + } +} diff --git a/sdk/monitor/perf-tests/monitor-query/tsconfig.json b/sdk/monitor/perf-tests/monitor-query/tsconfig.json new file mode 100644 index 000000000000..aff3fa45a140 --- /dev/null +++ b/sdk/monitor/perf-tests/monitor-query/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../../tsconfig.package", + "compilerOptions": { + "module": "CommonJS", + "lib": ["ES6", "ESNext.AsyncIterable"], + "noEmit": true + }, + "compileOnSave": true, + "include": ["./test/**/*.ts"] +}