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 2 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
41 changes: 27 additions & 14 deletions sdk/monitor/monitor-query/review/monitor-query.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,7 @@ export interface LogsQueryBatchOptions extends OperationOptions {
}

// @public
export interface LogsQueryBatchResult {
results: {
tables?: LogsTable[];
error?: LogsErrorInfo;
status?: LogsQueryResultStatus;
statistics?: Record<string, unknown>;
visualization?: Record<string, unknown>;
}[];
}
export type LogsQueryBatchResult = Array<LogsQueryPartialResult | LogsQuerySuccessfulResult | LogsQueryError>;

// @public
export class LogsQueryClient {
Expand All @@ -91,6 +83,12 @@ export interface LogsQueryClientOptions extends CommonClientOptions {
endpoint?: string;
}

// @public
export interface LogsQueryError extends Error {
code: string;
status: LogsQueryResultStatus.Failure;
}

// @public
export interface LogsQueryOptions extends OperationOptions {
additionalWorkspaces?: string[];
Expand All @@ -101,16 +99,31 @@ export interface LogsQueryOptions extends OperationOptions {
}

// @public
export interface LogsQueryResult {
error?: LogsErrorInfo;
export interface LogsQueryPartialResult {
incompleteTables: LogsTable[];
partialError: LogsErrorInfo;
statistics?: Record<string, unknown>;
status: LogsQueryResultStatus;
tables: LogsTable[];
status: LogsQueryResultStatus.PartialFailure;
visualization?: Record<string, unknown>;
}

// @public
export type LogsQueryResultStatus = "PartialFailure" | "Success" | "Failure";
export type LogsQueryResult = LogsQuerySuccessfulResult | LogsQueryPartialResult;

// @public
export enum LogsQueryResultStatus {
Failure = "Failure",
PartialFailure = "PartialFailure",
Success = "Success"
}

// @public
export interface LogsQuerySuccessfulResult {
statistics?: Record<string, unknown>;
status: LogsQueryResultStatus.Success;
tables: LogsTable[];
visualization?: Record<string, unknown>;
}

// @public
export interface LogsTable {
Expand Down
35 changes: 26 additions & 9 deletions sdk/monitor/monitor-query/samples-dev/logsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

import { DefaultAzureCredential } from "@azure/identity";
import { Durations, LogsQueryClient, LogsTable, LogsQueryOptions } from "@azure/monitor-query";
import {
Durations,
LogsQueryClient,
LogsTable,
LogsQueryOptions,
LogsQueryResultStatus
} from "@azure/monitor-query";
import * as dotenv from "dotenv";
dotenv.config();

Expand Down Expand Up @@ -41,14 +47,6 @@ export async function main() {
{ duration: Durations.oneHour },
queryLogsOptions
);

const tablesFromResult: LogsTable[] | undefined = result.tables;

if (tablesFromResult == null) {
console.log(`No results for query '${kustoQuery}'`);
return;
}

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

Expand All @@ -58,6 +56,25 @@ export async function main() {
}`
);

if (result.status === LogsQueryResultStatus.Success) {
const tablesFromResult: LogsTable[] = result.tables;

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.incompleteTables.length > 0) {
console.log(`This query has also returned partial data in the following table(s) - `);
processTables(result.incompleteTables);
}
}
}

async function processTables(tablesFromResult: LogsTable[]) {
for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
Expand Down
58 changes: 32 additions & 26 deletions sdk/monitor/monitor-query/samples-dev/logsQueryBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { DefaultAzureCredential } from "@azure/identity";
import { LogsQueryClient } from "@azure/monitor-query";
import { LogsQueryClient, LogsQueryResultStatus, LogsTable } from "@azure/monitor-query";
import * as dotenv from "dotenv";
dotenv.config();

Expand Down Expand Up @@ -47,43 +47,49 @@ export async function main() {
];

const result = await logsQueryClient.queryBatch(queriesBatch);

if (result.results == null) {
if (result === null) {
throw new Error("No response for query");
}

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}'`
KarishmaGhiya marked this conversation as resolved.
Show resolved Hide resolved
);
processTables(response.incompleteTables);
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}'`);
KarishmaGhiya marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}

main().catch((err) => {
console.error("The sample encountered an error:", err);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
*/

import { DefaultAzureCredential } from "@azure/identity";
import { Durations, LogsQueryClient, LogsTable, LogsQueryOptions } from "@azure/monitor-query";
import {
Durations,
LogsQueryClient,
LogsTable,
LogsQueryOptions,
LogsQueryResultStatus
} from "@azure/monitor-query";
import * as dotenv from "dotenv";
dotenv.config();

Expand Down Expand Up @@ -44,14 +50,6 @@ export async function main() {
{ duration: Durations.oneHour },
queryLogsOptions
);

const tablesFromResult: LogsTable[] | undefined = result.tables;

if (tablesFromResult == null) {
console.log(`No results for query '${kustoQuery}'`);
return;
}

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

Expand All @@ -61,6 +59,23 @@ export async function main() {
}`
);

if (result.status === LogsQueryResultStatus.Success) {
const tablesFromResult: LogsTable[] = result.tables;
if (tablesFromResult == null) {
console.log(`No results for query '${kustoQuery}'`);
return;
}
processTables(tablesFromResult);
} else {
console.log(`Error processing the query '${kustoQuery}' - ${result.partialError}`);
if (result.incompleteTables.length > 0) {
console.log(`This query has also returned partial data in the following table(s) - `);
processTables(result.incompleteTables);
}
}
}

async function processTables(tablesFromResult: LogsTable[]) {
for (const table of tablesFromResult) {
const columnHeaderString = table.columnDescriptors
.map((column) => `${column.name}(${column.type}) `)
Expand Down
5 changes: 3 additions & 2 deletions sdk/monitor/monitor-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export {
LogsQueryBatchResult,
LogsQueryOptions,
LogsQueryResult,
// TODO: design issues around this still pending.
// QueryStatistics,
LogsQueryError,
LogsQueryPartialResult,
LogsQuerySuccessfulResult,
LogsTable,
LogsColumn,
LogsQueryResultStatus,
Expand Down
Loading