Skip to content

Commit

Permalink
Add rate_limits_hit to QueryStats type (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson authored Oct 28, 2024
1 parent e75ea5e commit d4e2e33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions __tests__/integration/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const dummyResponse: HTTPResponse = {
storage_bytes_read: 0,
storage_bytes_write: 0,
contention_retries: 0,
rate_limits_hit: ["read", "write", "compute"],
},
}),
headers: {},
Expand All @@ -62,6 +63,7 @@ describe("query", () => {
expect(result.stats?.compute_ops).toBeDefined();
expect(result.stats?.contention_retries).toBeDefined();
expect(result.stats?.query_time_ms).toBeDefined();
expect(result.stats?.rate_limits_hit).toBeDefined();
expect(result.stats?.read_ops).toBeDefined();
expect(result.stats?.storage_bytes_read).toBeDefined();
expect(result.stats?.storage_bytes_write).toBeDefined();
Expand Down
6 changes: 5 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
ConstraintFailure,
QueryFailure,
QueryInfo,
QueryStats,
QueryValue,
} from "./wire-protocol";

Expand Down Expand Up @@ -226,8 +227,11 @@ export class ThrottlingError extends ServiceError {
export class QueryTimeoutError extends ServiceError {
/**
* Statistics regarding the query.
*
* TODO: Deprecate this `stats` field. All `ServiceError`s already provide
* access to stats through `queryInfo.stats`
*/
readonly stats?: { [key: string]: number };
readonly stats?: QueryStats;

constructor(failure: QueryFailure, httpStatus?: number) {
super(failure, httpStatus);
Expand Down
5 changes: 5 additions & 0 deletions src/wire-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export type QueryStats = {
contention_retries: number;
/** The number query attempts made due to retryable errors. */
attempts: number;
/**
* A list of rate limits hit.
* Included with QueryFailure responses when the query is rate limited.
*/
rate_limits_hit?: ("read" | "write" | "compute")[];
};

export type QueryInfo = {
Expand Down

0 comments on commit d4e2e33

Please sign in to comment.