mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
9d0b6db6b3
### Packages impacted by this PR - @azure-rest/load-testing ### Issues associated with this PR Fixes broken documentation links that were causing link verification failures. ### Describe the problem that is addressed by this PR Microsoft Learn reorganized the Load Testing API documentation from `/rest/api/loadtesting/` to `/rest/api/apptesting/loadtest/`. This caused link verification failures across the README and sample files. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? Direct URL replacement is the only approach. Updated all references from: - `https://learn.microsoft.com/rest/api/loadtesting/` → `https://learn.microsoft.com/rest/api/apptesting/loadtest/` - `https://learn.microsoft.com/rest/api/loadtesting/data-plane-uri` → `https://learn.microsoft.com/rest/api/apptesting/loadtest/data-plane-uri` ### Are there test cases added in this PR? _(If not, why?)_ No. Documentation link updates only. Link verification will be performed by existing CI. ### Provide a list of related PRs _(if any)_ N/A ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ N/A ### Checklists - [x] Added impacted package name to the issue description - [x] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `learn.microsoft.com` > - Triggering command: `curl -s -o /dev/null -w %{http_code} REDACTED` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/Azure/azure-sdk-for-js/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[doc] loadtesting readme broken links</issue_title> > <issue_description>We got this failure in link verification: > > >Summary of broken links: > 'file:///mnt/vss/_work/1/s/sdk/loadtesting/load-testing-rest/README.md' has 2 broken link(s): > https://learn.microsoft.com/rest/api/loadtesting/ > https://learn.microsoft.com/rest/api/loadtesting/data-plane-uri > Checked 98 links with 1 broken link(s) found. > > Looks that the url has been changed to > > https://learn.microsoft.com/rest/api/apptesting/loadtest/</issue_description> > > <agent_instructions>Fix the issue by updating the broken links</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes Azure/azure-sdk-for-js#36499 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jeremymeng <[email protected]>
114 lines
3.7 KiB
TypeScript
114 lines
3.7 KiB
TypeScript
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
/**
|
|
* This sample demonstrates how to run a test, poll for its status and then fetch metrics from it.
|
|
*
|
|
* @summary Demonstrates how to start a test run and get metrics.
|
|
*/
|
|
|
|
import AzureLoadTesting, { isUnexpected, getLongRunningPoller } from "@azure-rest/load-testing";
|
|
import { DefaultAzureCredential } from "@azure/identity";
|
|
import { randomUUID } from "node:crypto";
|
|
|
|
async function main(): Promise<void> {
|
|
/**
|
|
* The dataplane endpoint for the Azure Load Testing resource.
|
|
* Refer to https://learn.microsoft.com/rest/api/apptesting/loadtest/data-plane-uri to understand how to obtain the data-plane endpoint.
|
|
*/
|
|
const endpoint = process.env["LOADTESTSERVICE_ENDPOINT"] || "";
|
|
|
|
/** Microsoft Entra ID authentication */
|
|
/**
|
|
* In this sample you can populate the three AZURE_CLIENT_ID, AZURE_CLIENT_SECRET & AZURE_TENANT_ID variables for Microsoft Entra ID auth
|
|
*/
|
|
const credential = new DefaultAzureCredential();
|
|
const testId = process.env["LOADTESTSERVICE_TESTID"] || ""; // TestId of a test already created.
|
|
|
|
const testRunId = randomUUID(); // Random ID for the Test Run
|
|
const displayName = "Sample Test Run";
|
|
|
|
// Build a client through AAD
|
|
const client = AzureLoadTesting(endpoint, credential);
|
|
|
|
// Creating the test run
|
|
const testRunCreationResult = await client.path("/test-runs/{testRunId}", testRunId).patch({
|
|
contentType: "application/merge-patch+json",
|
|
body: {
|
|
testId: testId,
|
|
displayName: displayName,
|
|
},
|
|
});
|
|
|
|
if (isUnexpected(testRunCreationResult)) {
|
|
throw testRunCreationResult.body.error;
|
|
}
|
|
|
|
let testRunResult;
|
|
|
|
const testRunPoller = await getLongRunningPoller(client, testRunCreationResult);
|
|
try {
|
|
testRunResult = await testRunPoller.pollUntilDone({
|
|
abortSignal: AbortSignal.timeout(90000), // timeout of 90 seconds
|
|
});
|
|
} catch (ex: any) {
|
|
new Error("Error in polling for test run completion: " + ex.message); // Polling timed out
|
|
}
|
|
|
|
if (testRunPoller.getOperationState().status !== "succeeded") {
|
|
throw new Error("There is some issue in running the test, Error Response : " + testRunResult);
|
|
}
|
|
|
|
if (testRunResult) {
|
|
const testRunStartTime = testRunResult.body.startDateTime;
|
|
const testRunEndTime = testRunResult.body.endDateTime;
|
|
|
|
// Get the list of all metric namespaces and pick the first one
|
|
const metricNamespaces = await client
|
|
.path("/test-runs/{testRunId}/metric-namespaces", testRunId)
|
|
.get();
|
|
|
|
if (isUnexpected(metricNamespaces)) {
|
|
throw metricNamespaces.body.error;
|
|
}
|
|
|
|
const metricNamespace = metricNamespaces.body.value[0];
|
|
|
|
if (metricNamespace.name === undefined) {
|
|
throw "No Metric Namespace name is defined.";
|
|
}
|
|
|
|
// Get the list of all metric definitions and pick the first one
|
|
const metricDefinitions = await client
|
|
.path("/test-runs/{testRunId}/metric-definitions", testRunId)
|
|
.get({
|
|
queryParameters: {
|
|
metricNamespace: metricNamespace.name,
|
|
},
|
|
});
|
|
|
|
if (isUnexpected(metricDefinitions)) {
|
|
throw metricDefinitions.body.error;
|
|
}
|
|
|
|
const metricDefinition = metricDefinitions.body.value[0];
|
|
|
|
if (metricDefinition.name === undefined) {
|
|
throw "No Metric Definition name is defined.";
|
|
}
|
|
|
|
// Fetch client metrics using metric namespace and metric definition name
|
|
const metricsResult = await client.path("/test-runs/{testRunId}/metrics", testRunId).post({
|
|
queryParameters: {
|
|
metricname: metricDefinition.name,
|
|
metricNamespace: metricNamespace.name,
|
|
timespan: testRunStartTime + "/" + testRunEndTime,
|
|
},
|
|
});
|
|
|
|
console.log(metricsResult);
|
|
console.log(testRunResult);
|
|
}
|
|
}
|
|
main().catch(console.error);
|