Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the error handling for Logs Query and Logs Query Batch #17965

Merged
merged 25 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
702a5ec
update the error handling for Query Logs
KarishmaGhiya Sep 30, 2021
39b0865
lint error and ref-docs
KarishmaGhiya Sep 30, 2021
b4ab85e
remove the throwOnAnyError flag
KarishmaGhiya Sep 30, 2021
54404d0
update user agent to be similar for both clients
KarishmaGhiya Sep 30, 2021
8b4c4d1
update sdk_Version
KarishmaGhiya Sep 30, 2021
1397692
update readme
KarishmaGhiya Sep 30, 2021
84ca11e
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
de48db1
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
d13224a
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
3ff87e9
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
d1596af
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
61245b5
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
5d9bb38
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
ea2e59e
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
9764d68
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
beba760
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
b533deb
Update sdk/monitor/monitor-query/README.md
KarishmaGhiya Oct 1, 2021
cf0657a
Update sdk/monitor/monitor-query/samples-dev/logsQueryBatch.ts
KarishmaGhiya Oct 1, 2021
24cff5c
Update sdk/monitor/monitor-query/samples-dev/logsQueryBatch.ts
KarishmaGhiya Oct 1, 2021
cf2565d
Update sdk/monitor/monitor-query/samples/v1/javascript/logsQueryBatch.js
KarishmaGhiya Oct 1, 2021
36110fa
Update sdk/monitor/monitor-query/src/models/publicLogsModels.ts
KarishmaGhiya Oct 1, 2021
2bf6741
Update sdk/monitor/monitor-query/samples/v1/javascript/logsQueryBatch.js
KarishmaGhiya Oct 1, 2021
5451138
Update sdk/monitor/monitor-query/samples/v1/typescript/src/logsQueryB…
KarishmaGhiya Oct 1, 2021
551fd29
Update sdk/monitor/monitor-query/samples/v1/typescript/src/logsQueryB…
KarishmaGhiya Oct 1, 2021
57d45f4
updated changelog
KarishmaGhiya Oct 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions sdk/monitor/monitor-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# Release History

## 1.0.0-beta.6 (Unreleased)
## 1.0.0-beta.6 (2021-10-05)

### Features Added

- Added `audience` property in `MetricsClientOptions`
- Enabled browser support
- Added different result objects `LogsQueryPartialResult`, `LogsQuerySuccessfulResult` or `LogsQueryError` based on the success scenarios for log queries.

### Breaking Changes

- Renamed `ErrorInfo` to `LogsErrorInfo`, which now extends the `Error` class and `code` as an additional property. Removed all the other properties.
- `query` method in `LogsQueryClient` renamed to `queryWorkspace`
- `query` method in `MetricsQueryClient` renamed to `queryResource`
- Renamed `credentialOptions.credentialScopes` property in `LogsQueryClientOptions` to `audience`
- Renamed the status types in `LogsQueryResultStatus`. `Partial` to `PartialFailure` and `Failed` to `Failure`.
- Renamed `timeGrain` in `MetricAvailability` to `granularity`
- Renamed `TimeInterval` to `QueryTimeInterval`
- Updated constants in `Durations` to camel-case.
- Removed `throwOnAnyError` flag from `LogsQueryOptions` and `LogsQueryBatchOptions`
- Removed the error classes `BatchError` and `AggregateBatchError`
- Updated `LogsQueryBatchResult` object to be a list of objects with the following possible types:
- `LogsQueryPartialResult`
- `LogsQuerySuccessfulResult`
- `LogsQueryError`
- Updated `LogsQueryResult` object to be of type `LogsQuerySuccessfulResult` or `LogsQueryPartialResult`

### Bugs Fixed

### Other Changes
- Updated `listMetricNamespaces` signature to return the list of appropriate `MetricsNamespaces` object type

## 1.0.0-beta.5 (2021-09-09)

Expand Down
227 changes: 149 additions & 78 deletions sdk/monitor/monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,26 @@ async function run() {
const result = await logsQueryClient.queryWorkspace(azureLogAnalyticsWorkspaceId, kustoQuery, {
duration: Durations.twentyFourHours
});
const tablesFromResult = result.tables;

if (tablesFromResult == null) {
console.log(`No results for query '${kustoQuery}'`);
return;
}
if (result.status === LogsQueryResultStatus.Success) {
const tablesFromResult: LogsTable[] = result.tables;

console.log(`Results for query '${kustoQuery}'`);
if (tablesFromResult.length === 0) {
console.log(`No results for query '${kustoQuery}'`);
return;
}
console.log(`This query has returned table(s) - `);
processTables(tablesFromResult);
} else {
console.log(`Error processing the query '${kustoQuery}' - ${result.partialError}`);
if (result.partialTables.length > 0) {
console.log(`This query has also returned partial data in the following table(s) - `);
processTables(result.partialTables);
}
}
}

async function processTables(tablesFromResult: LogsTable[]) {
for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
Expand All @@ -123,41 +134,57 @@ async function run() {
}
}
}

run().catch((err) => console.log("ERROR:", err));
```

#### Handle logs query response

The `queryWorkspace` function of `LogsQueryClient` returns the `LogsQueryResult`. Here's a hierarchy of the response:
The `queryWorkspace` function of `LogsQueryClient` returns a `LogsQueryResult` object. The object type can be `LogsQuerySuccessfulResult` or `LogsQueryPartialResult`. Here's a hierarchy of the response:

```
LogsQueryResult
LogsQuerySuccessfulResult
|---statistics
|---visualization
|---error
|---status ("PartialFailure" | "Success" | "Failure")
|---status ("Success")
|---tables (list of `LogsTable` objects)
|---name
|---rows
|---columnDescriptors (list of `LogsColumn` objects)
|---name
|---type

KarishmaGhiya marked this conversation as resolved.
Show resolved Hide resolved
LogsQueryPartialResult
|---statistics
|---visualization
|---status ("PartialFailure")
|---partialError
|--name
|--code
|--message
|--stack
|---partialTables (list of `LogsTable` objects)
|---name
|---rows
|---columnDescriptors (list of `LogsColumn` objects)
|---name
|---type
```

For example, to handle a response with tables:

```ts
const tablesFromResult = result.tables;

for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
.join("| ");
console.log("| " + columnHeaderString);
async function processTables(tablesFromResult: LogsTable[]) {
for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
.join("| ");
console.log("| " + columnHeaderString);

for (const row of table.rows) {
const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| ");
console.log("| " + columnValuesString);
for (const row of table.rows) {
const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| ");
console.log("| " + columnValuesString);
}
}
}
```
Expand Down Expand Up @@ -210,89 +237,133 @@ export async function main() {
}

let i = 0;
for (const response of result.results) {
for (const response of result) {
console.log(`Results for query with query: ${queriesBatch[i]}`);

if (response.error) {
console.log(` Query had errors:`, response.error);
if (response.status === LogsQueryResultStatus.Success) {
console.log(
`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}'`
);
processTables(response.partialTables);
console.log(
` Query had errors:${response.partialError.message} with code ${response.partialError.code}`
);
} else {
if (response.tables == null) {
console.log(`No results for query`);
} else {
console.log(
`Printing results from query '${queriesBatch[i].query}' for '${queriesBatch[i].timespan}'`
);

for (const table of response.tables) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
.join("| ");
console.log(columnHeaderString);

for (const row of table.rows) {
const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| ");
console.log(columnValuesString);
}
}
}
console.log(`Printing errors from query '${queriesBatch[i].query}'`);
console.log(` Query had errors:${response.message} with code ${response.code}`);
}
// next query
i++;
}
}

async function processTables(tablesFromResult: LogsTable[]) {
for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
.join("| ");
console.log("| " + columnHeaderString);

for (const row of table.rows) {
const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| ");
console.log("| " + columnValuesString);
}
}
}
```

#### Handle logs batch query response

The `queryBatch` function of `LogsQueryClient` returns a `LogsQueryBatchResult` object. Here's a hierarchy of the response:
The `queryBatch` function of `LogsQueryClient` returns a `LogsQueryBatchResult` object. `LogsQueryBatchResult` contains a list of objects with the following possible types:

- `LogsQueryPartialResult`
- `LogsQuerySuccessfulResult`
- `LogsQueryError`

Here's a hierarchy of the response:

```
LogsQueryBatchResult
|---results (list of following objects)
|---statistics
|---visualization
|---error
|---status ("PartialFailure" | "Success" | "Failure")
|---tables (list of `LogsTable` objects)

LogsQuerySuccessfulResult
|---statistics
|---visualization
|---status ("Success")
|---tables (list of `LogsTable` objects)
|---name
|---rows
|---columnDescriptors (list of `LogsColumn` objects)
|---name
|---rows
|---columnDescriptors (list of `LogsColumn` objects)
|---name
|---type
|---type

KarishmaGhiya marked this conversation as resolved.
Show resolved Hide resolved
LogsQueryPartialResult
|---statistics
|---visualization
|---status ("PartialFailure")
|---partialError
|--name
|--code
|--message
|--stack
|---partialTables (list of `LogsTable` objects)
|---name
|---rows
|---columnDescriptors (list of `LogsColumn` objects)
|---name
|---type

LogsQueryError
|--name
|--code
|--message
|--stack
|--status ("Failure")
```

For example, to handle a batch logs query response:
For example, the following code handles a batch logs query response:

```ts
let i = 0;
for (const response of result.results) {
console.log(`Results for query with query: ${queriesBatch[i]}`);

if (response.error) {
console.log(` Query had errors:`, response.error);
} else {
if (response.tables == null) {
console.log(`No results for query`);
} else {
async function processBatchResult(result: LogsQueryBatchResult) {
let i = 0;
for (const response of result) {
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}'`
);
processTables(response.tables);
} else if (response.status === LogsQueryResultStatus.PartialFailure) {
console.log(
`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}`
);
} else {
console.log(`Printing errors from query '${queriesBatch[i].query}'`);
console.log(` Query had errors:${response.message} with code ${response.code}`);
}
// next query
i++;
}
}

for (const table of response.tables) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
.join("| ");
console.log(columnHeaderString);
async function processTables(tablesFromResult: LogsTable[]) {
for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
.join("| ");
console.log("| " + columnHeaderString);

for (const row of table.rows) {
const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| ");
console.log(columnValuesString);
}
}
for (const row of table.rows) {
const columnValuesString = row.map((columnValue) => `'${columnValue}' `).join("| ");
console.log("| " + columnValuesString);
}
}
// next query
i++;
}
```

Expand Down
Loading