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

feat: constrained extensions #56

Merged
merged 3 commits into from
Sep 1, 2023

Conversation

steve-chavez
Copy link
Member

@steve-chavez steve-chavez commented Aug 3, 2023

Rendered documentation

Define a setting:

supautils.constrained_extensions = '{"plrust": {"cpu": 16, "mem": "1GB", "disk": "500MB"}, {"anotherone": { "cpu":64}}'

And extensions that don't comply the minimum resources will fail:

create extension plrust;
ERROR:  not enough resources for using this extension

Tasks

  • Use pg_parse_json for the config
  • Constrain based on CPU
  • Constrain based on MEM
  • Constrain based on DISK
  • Conditionally enable the feature for pg 12 (doesn't support pg JSON API)

@steve-chavez steve-chavez force-pushed the constrained-exts branch 4 times, most recently from 4f4ade6 to 7d79673 Compare August 3, 2023 18:35
This is only needed for extensions and we no longer are one.
@steve-chavez steve-chavez force-pushed the constrained-exts branch 2 times, most recently from c305c9d to 883a020 Compare August 31, 2023 07:44
@steve-chavez steve-chavez marked this pull request as ready for review August 31, 2023 07:47
@@ -0,0 +1,231 @@
#include "utils.h"

#if PG13_GTE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made sure this feature only works for pg 13 onwards while not breaking pg 12 compat with other features. Check 883a020 commit message for more details.

It's considerable work to do this, we should consider dropping support for pg 12 later.

case JCE_EXPECT_CPU:
case JCE_EXPECT_MEM:
case JCE_EXPECT_DISK:
parse->error_msg = "unexpected object for cpu, mem or disk, expected a value";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested these parse errors manually. Our test suite doesn't have a way to run with different configs for now.

@olirice olirice self-requested a review August 31, 2023 18:13
@olirice
Copy link
Collaborator

olirice commented Aug 31, 2023

awesome!!

great work on the tests too 👀

Adds resource constraints for cpu, memory and disk for extensions.

Compat with pg 12 is done by omitting constrainted extensions code using
if macro directives checking the PostgreSQL version.

Since all the tests are ran for all the pg versions, a variant comparison
file for pg12 is used:

https://www.postgresql.org/docs/current/regress-variant.html

The variant test checks that all the extensions are created and
that this only happens for pg 12. This way we ensure that the pg12
test output is not matched by accident for pg >= 13 and we
get test failures if the constrained extensions code fails.
@steve-chavez steve-chavez merged commit 9156c39 into supabase:master Sep 1, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants