Skip to content

Commit

Permalink
[@azure/monitor-query]Update Readme file (Azure#29105)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR
@azure/monitor-query

### Issues associated with this PR
NA

### Describe the problem that is addressed by this PR
The Readme sample is using the incorrect class. This has to be fixed to
the correct class.

### 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?
No special design considerations. Just a readme file update

### Are there test cases added in this PR? _(If not, why?)_
No. This is just a readme file change.

### Provide a list of related PRs _(if any)_
NA

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_
NA

### Checklists
- [X] Added impacted package name to the issue description
- [ ] 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)

@srnagar Please review and approve the PR.
  • Loading branch information
sarangan12 authored Mar 28, 2024
1 parent 18a9b09 commit fa799a1
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions sdk/monitor/monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ const metricsQueryClient: MetricsQueryClient = new MetricsQueryClient(credential
// or
const endPoint: string = "<YOUR_METRICS_ENDPOINT>"; //for example, https://eastus.metrics.monitor.azure.com/

const metricsQueryClient: MetricsQueryClient = new MetricsQueryClient(
endPoint,
credential
);
const metricsQueryClient: MetricsQueryClient = new MetricsQueryClient(endPoint, credential);
```

#### Configure client for Azure sovereign cloud
Expand Down Expand Up @@ -215,7 +212,7 @@ export async function main() {
throw new Error("LOGS_RESOURCE_ID must be set in the environment for this sample");
}

const kustoQuery = `MyTable_CL | summarize count()`
const kustoQuery = `MyTable_CL | summarize count()`;

console.log(`Running '${kustoQuery}' over the last One Hour`);
const queryLogsOptions: LogsQueryOptions = {
Expand All @@ -227,18 +224,19 @@ export async function main() {
};

const result = await logsQueryClient.queryResource(
logsResourceId,
logsResourceId,
kustoQuery,
{ duration: Durations.sevenDays },
queryLogsOptions);
queryLogsOptions,
);

const executionTime =
result.statistics && result.statistics.query && (result.statistics.query as any).executionTime;

console.log(
`Results for query '${kustoQuery}', execution time: ${
executionTime == null ? "unknown" : executionTime
}`
}`,
);

if (result.status === LogsQueryResultStatus.Success) {
Expand Down Expand Up @@ -382,16 +380,16 @@ export async function main() {
console.log(`Results for query with query: ${queriesBatch[i]}`);
if (response.status === LogsQueryResultStatus.Success) {
console.log(
`Printing results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`
`Printing results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`,
);
processTables(response.tables);
} else if (response.status === LogsQueryResultStatus.PartialFailure) {
console.log(
`Printing partial results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`
`Printing partial results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`,
);
processTables(response.partialTables);
console.log(
` Query had errors:${response.partialError.message} with code ${response.partialError.code}`
` Query had errors:${response.partialError.message} with code ${response.partialError.code}`,
);
} else {
console.log(`Printing errors from query '${queriesBatch[i].query}'`);
Expand Down Expand Up @@ -472,16 +470,16 @@ async function processBatchResult(result: LogsQueryBatchResult) {
console.log(`Results for query with query: ${queriesBatch[i]}`);
if (response.status === LogsQueryResultStatus.Success) {
console.log(
`Printing results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`
`Printing results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`,
);
processTables(response.tables);
} else if (response.status === LogsQueryResultStatus.PartialFailure) {
console.log(
`Printing partial results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`
`Printing partial results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`,
);
processTables(response.partialTables);
console.log(
` Query had errors:${response.partialError.message} with code ${response.partialError.code}`
` Query had errors:${response.partialError.message} with code ${response.partialError.code}`,
);
} else {
console.log(`Printing errors from query '${queriesBatch[i].query}'`);
Expand Down Expand Up @@ -526,7 +524,7 @@ const result = await logsQueryClient.queryWorkspace(
azureLogAnalyticsWorkspaceId,
kustoQuery,
{ duration: Durations.twentyFourHours },
queryLogsOptions
queryLogsOptions,
);

const tablesFromResult = result.tables;
Expand Down Expand Up @@ -554,7 +552,7 @@ const result = await logsQueryClient.queryWorkspace(
azureLogAnalyticsWorkspaceId,
kustoQuery,
{ duration: Durations.twentyFourHours },
queryLogsOptions
queryLogsOptions,
);
```

Expand Down Expand Up @@ -594,7 +592,7 @@ const result = await logsQueryClient.queryWorkspace(
{ duration: Durations.oneDay },
{
includeQueryStatistics: true,
}
},
);

const executionTime =
Expand All @@ -603,7 +601,7 @@ const executionTime =
console.log(
`Results for query '${kustoQuery}', execution time: ${
executionTime == null ? "unknown" : executionTime
}`
}`,
);
```

Expand Down Expand Up @@ -719,11 +717,11 @@ export async function main() {
{
granularity: "PT1M",
timespan: { duration: Durations.fiveMinutes },
}
},
);

console.log(
`Query cost: ${metricsResponse.cost}, interval: ${metricsResponse.granularity}, time span: ${metricsResponse.timespan}`
`Query cost: ${metricsResponse.cost}, interval: ${metricsResponse.granularity}, time span: ${metricsResponse.timespan}`,
);

const metrics: Metric[] = metricsResponse.metrics;
Expand Down Expand Up @@ -788,7 +786,7 @@ export async function main() {

if (!metricsResourceId) {
throw new Error(
"METRICS_RESOURCE_ID for an Azure Metrics Advisor subscription must be set in the environment for this sample"
"METRICS_RESOURCE_ID for an Azure Metrics Advisor subscription must be set in the environment for this sample",
);
}

Expand All @@ -803,11 +801,11 @@ export async function main() {
},
granularity: "PT1M",
aggregations: ["Count"],
}
},
);

console.log(
`Query cost: ${metricsResponse.cost}, granularity: ${metricsResponse.granularity}, time span: ${metricsResponse.timespan}`
`Query cost: ${metricsResponse.cost}, granularity: ${metricsResponse.granularity}, time span: ${metricsResponse.timespan}`,
);

const metrics: Metric[] = metricsResponse.metrics;
Expand All @@ -833,9 +831,9 @@ A full sample can be found [here](https://github.com/Azure/azure-sdk-for-js/blob

#### Query metrics for multiple resources

To query metrics for multiple Azure resources in a single request, use the `MetricsQueryClient.queryResources` method. This method:
To query metrics for multiple Azure resources in a single request, use the `MetricsClient.queryResources` method. This method:

- Calls a different API than the `MetricsQueryClient` methods.
- Calls a different API than the `MetricsClient` methods.
- Requires a regional endpoint when creating the client. For example, "https://westus3.metrics.monitor.azure.com".

Each Azure resource must reside in:
Expand All @@ -852,18 +850,18 @@ let resourceIds: string[] = [
];
let metricsNamespace: string = "<YOUR_METRICS_NAMESPACE>";
let metricNames: string[] = ["requests", "count"];
const batchEndPoint: string = "<YOUR_METRICS_ENDPOINT>"; //for example, https://eastus.metrics.monitor.azure.com/
const endpoint: string = "<YOUR_METRICS_ENDPOINT>"; //for example, https://eastus.metrics.monitor.azure.com/

const credential = new DefaultAzureCredential();
const metricsQueryClient: MetricsQueryClient = new MetricsQueryClient(
batchEndPoint,
const metricsClient: MetricsClient = new MetricsClient(
endpoint,
credential
);

const result: : MetricsQueryResult[] = await metricsQueryClient.queryResources(
const result: : MetricsQueryResult[] = await metricsClient.queryResources(
resourceIds,
metricsNamespace,
metricNames
metricNames,
metricsNamespace
);
```

Expand Down

0 comments on commit fa799a1

Please sign in to comment.