Add system caches list and delete subcommands to manage runtime caches#384
Conversation
system caches list and delete subcommands to manage runtime caches
d6c626a to
53bf085
Compare
ca4828b to
a3e264d
Compare
Co-authored-by: Bincheng Wu <bcwu@users.noreply.github.com>
Co-authored-by: Bincheng Wu <bcwu@users.noreply.github.com>
tdstein
left a comment
There was a problem hiding this comment.
Tests that depend on docker are isolated from unit tests within the project structure. In my opinion, the integration tests should be moved to another directory to separate them from the unit tests. Then a command should be added to the Makefile, which invokes them independently.
That way, I should be able to run make integration-tests from my machine and get the same results as running the same command in GitHub Actions.
Also, this is the first time I've seen setup and teardown Docker commands invoked as part of the unit test lifecycle. I have always utilized shell scripts to achieve this. Are there any pros or cons to running the Docker commands via the Python os package?
There was a problem hiding this comment.
Thank you! This refactor was needed!
| python -m unittest tests.test_main_system_caches | ||
| pytest -m 'vetiver' |
There was a problem hiding this comment.
| python -m unittest tests.test_main_system_caches | |
| pytest -m 'vetiver' | |
| pytest tests/test_main_system_caches.py | |
| pytest -m 'vetiver' |
This should also work.
Yeah, having these tests as unit tests that are just skipped if the docker service isn't available seems really hacky. I agree that there should be a single There's already an |
A separate PR makes sense. For now, feel free to make as much (or as little) change you feel is needed to get the feature ready. That is to say, if we can get the tests pass CI, feel free to leave them in the PR. |
|
@bcwu @tdstein Right now the Vetiver integration test workflow uses the local The RSC_API_KEYS=vetiver-testing/rsconnect_api_keys.json
...
dev: vetiver-testing/rsconnect_api_keys.json
dev-start:
docker-compose up -d
docker-compose exec -T rsconnect bash < vetiver-testing/setup-rsconnect/add-users.sh
# curl fails with error 52 without a short sleep....
sleep 5
curl -s --retry 10 --retry-connrefused http://localhost:3939
...
$(RSC_API_KEYS): dev-start
python vetiver-testing/setup-rsconnect/dump_api_keys.py $@But the GitHub Actions I've honestly hardly ever used |
c7f1037 to
c27fbf8
Compare
19fc913 to
d29db3b
Compare
| ## Unreleased | ||
|
|
||
| ### Added | ||
| - Added `system caches list` and `system caches delete` commands which allow administrators to enumerate and delete R and Python runtime caches from Connect servers. |
There was a problem hiding this comment.
We will want to indicate the minimum Connect release having this functionality.
| { | ||
| "language": "Python", | ||
| "version": "3.8.12", | ||
| "image_name": "teapot" |
There was a problem hiding this comment.
Same for Python - maybe use one of the Python images to reference a real one? https://hub.docker.com/_/python/
| You should run this command for each cache you wish to delete. | ||
|
|
||
| To determine whether your a deletion request would fail without risking | ||
| deletion, you can use the dry run option (`-d, --dry-run`) to surface any errors |
There was a problem hiding this comment.
Suggest the dry-run as an integral part of the workflow, not an afterthought.
- dry-run (with example)
- delete (with example)
6f26820 to
4668804
Compare
- language is case insensitive - image-name is optional, default “Local” - docs add more detail about parameters
Title-casing the language doesn't harm functionality, but it might confuse my future self.
|
Just noting here that @aronatkins, @ChaitaC and I verified this on Thursday, March 30th in our Refinement meeting. I failed to record that when it happened. This is holding till the required Connect functionality releases. |
Intent
Add new subcommands to call Connect's forthcoming runtime cache management API.
Type of Change
Approach
Note: CI is failing because of one of the Connect-in-Docker integration tests I wrote, where I try to use Python's
system()to run commands in the Docker container. See below for more details. I'll take another shot at it on Monday.There are three main functional components:
RSConnectClientthat call the endpoints and return the response.RSConnectExecutor.The
listcommand is very simple: it either serializes the JSON response from the server, or prints the error.The
deletecommand is more complex, because it has a dry-run case, which doesn't result in a server-side task, and a non-dry-run case, which does result in the creation of a task. The logic to handle this is inRSConnectExecutor.delete_runtime_cache().deletecontain"task_id": null. In this case, we print "Dry run finished", as the server doesn't log anything. If the command is called with-v, the result will also be printed. In the dry run case, if the deletion wouldn't happen for any reason (e.g. the cache doesn't exist) the endpoint will return an error.deletewill have a non-nulltask_id. The endpoint will callclient.wait_for_task()and log server messages from that task, which include a start and a success message. The task status object is silently returned at the end, but it'll be printed with-v.Automated Tests
The API is tested on two levels:
test_api.pyhttprettyto mock responses to confirm that the endpoints function as desired when given the right inputs.vetivertests, in-test_main_system_caches.pyclick.CliRunner()to test the end-to-end functionality.QA Notes
We'll manually test that we can enumerate and delete caches.
mkdir pip/1.2.3within the python-environments directory.rsconnect system caches listto list the runtime caches.rsconnect system caches delete --language Python --version 1.2.3 --image-name Localto delete the cache directory.Checklist
I have not updated
CHANGELOG.mdyet. Will do so before this merges.