cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.92k stars 3.78k forks source link

Option to report query cost with results via a NoticeResponse #37316

Open BenHutchisonSeek opened 5 years ago

BenHutchisonSeek commented 5 years ago

Problem: Databases exposed to the internet via intermediate services can be vulnerable to "getting DOSed", ie accidentally, or even deliberately, having all their compute or IO capacity consumed by a small number of client(s) issuing a lot of expensive operations.

Rate limiting by client ID or IP address is a typical way to defend against such scenarios. In the case of database queries however, they can differ hugely in cost, so limiting purely on the number of requests may be insufficient.

A key step in rationing access to a shared database would be the ability to report on how much a given query cost (or even an estimate of that).

Desired Feature: A database-wide setting to enable cost data to be reported alongside query results, by emitting a NoticeResponse containing the cost number as structured text or JSON, in eg the same units used by the internal cost optimizer.

Alternatives:

Jira issue: CRDB-4437

andreimatei commented 5 years ago

We have a number of efforts in this area. However, doing anything with NoticeResponses is not something we've considered before. I'm very skeptical that reporting info over this channel would be useful, unless you tell me otherwise. How would you even get these reports? The client drivers generally discard these packages. And even if you do manage to get the reports, what exactly would an app do with them?

We're trying improve the statements page that we already have in the Admin UI to include more information on the cost of queries. There's also various ideas for allowing users to configure limits per query / per transaction / per client application, but nothing very concrete yet. Separately, @ajwerner is trying to make CRDB behave better under "DOS". Like, don't crash and ideally maintain good throughput. cc @awoods187

BenHutchisonSeek commented 5 years ago

So the Postgres JDBC driver exposes NoticeResponse as a SQLWarning rather than discarding it

What would I do with it? parse it back into an number in the servicer layer and add it to the relevant client's rate limit.

asubiotto commented 4 years ago

cc @otan

otan commented 4 years ago

We support notices now but would like clarification of requirements. I thought we were floating supporting something like this in future but didn't realise there was a task. Cc @awoods187

github-actions[bot] commented 2 years ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!

github-actions[bot] commented 1 year ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!