-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
running postgrest-loadtest with artificial latency #2682
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
final: prev: | ||
{ | ||
slocat = prev.buildGoModule { | ||
name = "slocat"; | ||
src = prev.fetchFromGitHub { | ||
owner = "robx"; | ||
repo = "slocat"; | ||
rev = "52e7512c6029fd00483e41ccce260a3b4b9b3b64"; | ||
sha256 = "sha256-qn6luuh5wqREu3s8RfuMCP5PKdS2WdwPrujRYTpfzQ8="; | ||
}; | ||
vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
{ bash-completion | ||
, buildToolbox | ||
, cabal-install | ||
, cabalTools | ||
, checkedShellScript | ||
, curl | ||
, devCabalOptions | ||
, git | ||
, lib | ||
, postgresqlVersions | ||
, postgrest | ||
, slocat | ||
, writeText | ||
}: | ||
let | ||
|
@@ -137,6 +139,81 @@ let | |
|
||
withPg = builtins.head withPgVersions; | ||
|
||
withSlowPg = | ||
checkedShellScript | ||
{ | ||
name = "postgrest-with-slow-pg"; | ||
docs = "Run the given command with simulated high latency postgresql"; | ||
args = | ||
[ | ||
"ARG_POSITIONAL_SINGLE([command], [Command to run])" | ||
"ARG_LEFTOVERS([command arguments])" | ||
"ARG_USE_ENV([PGHOST], [], [PG host (socket name)])" | ||
"ARG_USE_ENV([PGDELAY], [0ms], [extra PG latency (duration)])" | ||
]; | ||
positionalCompletion = "_command"; | ||
inRootDir = true; | ||
redirectTixFiles = false; | ||
withTmpDir = true; | ||
} | ||
'' | ||
delay="''${PGDELAY:-0ms}" | ||
echo "delaying data to/from postgres by $delay" | ||
|
||
REALPGHOST="$PGHOST" | ||
export PGHOST="$tmpdir/socket" | ||
mkdir -p "$PGHOST" | ||
|
||
${slocat}/bin/slocat -delay "$delay" -src "$PGHOST/.s.PGSQL.5432" -dst "$REALPGHOST/.s.PGSQL.5432" & | ||
SLOCAT_PID=$! | ||
# shellcheck disable=SC2317 | ||
stop_slocat() { | ||
kill "$SLOCAT_PID" || true | ||
wait "$SLOCAT_PID" || true | ||
} | ||
trap stop_slocat EXIT | ||
sleep 1 # should wait for socket file to appear instead | ||
|
||
("$_arg_command" "''${_arg_leftovers[@]}") | ||
''; | ||
|
||
withSlowPgrst = | ||
checkedShellScript | ||
{ | ||
name = "postgrest-with-slow-postgrest"; | ||
docs = "Run the given command with simulated high latency postgrest"; | ||
args = | ||
[ | ||
"ARG_POSITIONAL_SINGLE([command], [Command to run])" | ||
"ARG_LEFTOVERS([command arguments])" | ||
"ARG_USE_ENV([PGRST_SERVER_UNIX_SOCKET], [], [PostgREST host (socket name)])" | ||
"ARG_USE_ENV([PGRST_DELAY], [0ms], [extra PostgREST latency (duration)])" | ||
]; | ||
positionalCompletion = "_command"; | ||
inRootDir = true; | ||
redirectTixFiles = false; | ||
withTmpDir = true; | ||
} | ||
'' | ||
delay="''${PGRST_DELAY:-0ms}" | ||
echo "delaying data to/from PostgREST by $delay" | ||
|
||
REAL_PGRST_SERVER_UNIX_SOCKET="$PGRST_SERVER_UNIX_SOCKET" | ||
export PGRST_SERVER_UNIX_SOCKET="$tmpdir/postgrest.socket" | ||
|
||
${slocat}/bin/slocat -delay "$delay" -src "$PGRST_SERVER_UNIX_SOCKET" -dst "$REAL_PGRST_SERVER_UNIX_SOCKET" & | ||
SLOCAT_PID=$! | ||
# shellcheck disable=SC2317 | ||
stop_slocat() { | ||
kill "$SLOCAT_PID" || true | ||
wait "$SLOCAT_PID" || true | ||
} | ||
trap stop_slocat EXIT | ||
sleep 1 # should wait for socket file to appear instead | ||
|
||
("$_arg_command" "''${_arg_leftovers[@]}") | ||
''; | ||
|
||
withGit = | ||
let | ||
name = "postgrest-with-git"; | ||
|
@@ -257,16 +334,23 @@ let | |
export PGRST_SERVER_UNIX_SOCKET="$tmpdir"/postgrest.socket | ||
|
||
rm -f result | ||
echo -n "Building postgrest... " | ||
nix-build -A postgrestPackage > "$tmpdir"/build.log 2>&1 || { | ||
echo "failed, output:" | ||
cat "$tmpdir"/build.log | ||
exit 1 | ||
} | ||
if [ -z "''${PGRST_BUILD_CABAL:-}" ]; then | ||
echo -n "Building postgrest (nix)... " | ||
nix-build -A postgrestPackage > "$tmpdir"/build.log 2>&1 || { | ||
echo "failed, output:" | ||
cat "$tmpdir"/build.log | ||
exit 1 | ||
} | ||
PGRST_CMD=./result/bin/postgrest | ||
else | ||
echo -n "Building postgrest (cabal)... " | ||
postgrest-build | ||
PGRST_CMD=postgrest-run | ||
fi | ||
echo "done." | ||
|
||
echo -n "Starting postgrest... " | ||
./result/bin/postgrest ${legacyConfig} > "$tmpdir"/run.log 2>&1 & | ||
$PGRST_CMD ${legacyConfig} > "$tmpdir"/run.log 2>&1 & | ||
pid=$! | ||
Comment on lines
+353
to
354
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before the change to Aren't we back to getting the cabal pid, or even worse the bash pid from postgrest-run, which will prevent stopping postgrest properly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When |
||
# shellcheck disable=SC2317 | ||
cleanup() { | ||
|
@@ -288,7 +372,7 @@ in | |
buildToolbox | ||
{ | ||
name = "postgrest-with"; | ||
tools = [ withPgAll withGit withPgrst ] ++ withPgVersions; | ||
tools = [ withPgAll withGit withPgrst withSlowPg withSlowPgrst ] ++ withPgVersions; | ||
# make withTools available for other nix files | ||
extra = { inherit withGit withPg withPgAll withPgrst; }; | ||
extra = { inherit withGit withPg withPgAll withPgrst withSlowPg withSlowPgrst; }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
PGRST_BUILD_CABAL
really the right term?nix-build
does nothing different - it builds with cabal, too.The difference seems to be in:
main
?postgrest-build
does, right?I think
PGRST_BUILD_CABAL
is misleading. It's actually going back to using the current nix environment, so the dependency problem would still be present with that setting, correct?Overall, I think the fix in 0c5d2e5 was just not an improvement and we should revert it.
The suggestion I made in #2308 (comment) seems better. The loadtest-against / with-git infrastructure was designed to always use the current's branch nix environment on purpose. This does not cover some edge-cases, like the one you found - but it gives us some nice other properties, namely that we can update our tooling (nix commands for loadtest etc..) - and still run the new tools on older branches. This was necessary when I once ran loadtest through some months/years of commits to see patterns: #1812 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't particularly care what happens to this change as such -- I needed it to do my work here.
(It's unfortunate that our nix tooling is as rigid and obstructive as it is, it would be much preferable if changes such as this weren't needed. Ideally, it were possible to iterate quickly with local changes to the build scripts, but that's not where we're at.)