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

Add rate_limits_hit to QueryStats type #293

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading