Repository navigation
feat: add get_processes() for GET /v1/system/processes; deprecate get_procs() - #533
Conversation
get_processes() requests the v1 endpoint as CSV and supports its content_guid, owner_guid, and hostname filters. On Connect versions without it (404 with no error code), it falls back to the unversioned /metrics/procs endpoint, maps the columns and placeholder values to the v1 conventions, and applies the filters client-side. get_procs() is deprecated in favor of get_processes(). The shared request logic no longer goes through get_procs(), so the fallback does not raise the deprecation warning. get_procs() now returns the server's pid instead of the row index and parses its datetime columns (#532). endpoint_does_not_exist() now passes an explicit encoding, so falling back on a text/plain 404 no longer prints an encoding message.
4ac8206 to
87fc404
Compare
Address review feedback on #533: - On Connect without GET /v1/system/processes, an unknown content_guid or owner_guid now raises a 404, as the v1 endpoint does, instead of returning no processes. The fallback checks them with GET /v1/content/{guid} and GET /v1/users/{guid} before fetching /metrics/procs. - Deprecate the Connect$procs() R6 method in favor of get_processes(). - Type the result once: the fallback path already calls type_processes(), so get_processes() no longer calls it again. - The integration test stops its process with withr::defer(), so a failing expectation doesn't leave it running, and checks that unknown content and owner GUIDs are errors.
nealrichardson
left a comment
There was a problem hiding this comment.
Thanks for doing this, left a few suggestions
| } | ||
|
|
||
| #' Get Real-Time Process Data | ||
| #' Get running processes |
There was a problem hiding this comment.
How about we move all of this process code to a new processes.R? get.R seems like a catch-all and this has enough code to deserve its own I think.
There was a problem hiding this comment.
🤖 Done: get_processes(), get_procs(), and their helpers are now in R/processes.R. The integration test has also moved out of tests/integrated/test-get.R into a new tests/integrated/test-processes.R, which matches the unit tests in tests/testthat/test-processes.R.
| # Give a processes table its documented column types, adding any missing | ||
| # columns so that empty results have the same shape as non-empty ones. Columns | ||
| # the server sends that we don't know about are kept at the end. | ||
| type_processes <- function(df) { |
There was a problem hiding this comment.
Why not do this in colClasses in read.csv() and get it all right from the start?
There was a problem hiding this comment.
🤖 I tried this. colClasses can only take over part of the typing, so I've left the typing in type_processes():
type_processes()also types theGET /metrics/procsfallback. That data comes from JSON with different types (for example,pidcomes from the object's names as a string), so we need the function either way. UsingcolClassesfor the CSV path would mean typing these columns in two places.start_time/heartbeatcan't be set there:colClasses = c(start_time = "POSIXct")silently drops the time from"2026-11-09T10:00:00Z"and keeps only the date.ramcan't either, because there's no colClass forfs_bytes. Those columns would still need converting afterwards.- Columns not named in
colClassesget their types guessed, so all-NA columns become logical. Naming a column the server doesn't send triggers a warning, so we'd also have to read the header first.
I've added a comment above parse_processes_csv() explaining this so it isn't a mystery later. If you still want pid/cpu_current/ram in colClasses for the CSV path, I can do that.
| # The v1 endpoint returns null for values Connect doesn't know, where the | ||
| # unversioned endpoint uses placeholders. Match the v1 endpoint, whose CSV | ||
| # output also cannot distinguish an empty string from null. | ||
| for (col in names(df)[vapply(df, is.character, logical(1))]) { |
There was a problem hiding this comment.
you use purrr::map_chr() above, so map_lgl here?
There was a problem hiding this comment.
🤖 Done: switched to purrr::map_lgl(df, is.character).
| test_that("get_procs works", { | ||
| scoped_experimental_silence() | ||
| proc_data <- get_procs(client) | ||
| # Deploy a dependency-free Python API and keep a process for it running, so |
There was a problem hiding this comment.
Is this simpler than deploying something with R? Are we already deploying a shiny app above?
There was a problem hiding this comment.
🤖 Yes, it's simpler, and no, nothing deployed earlier keeps a process running. The other integration tests only deploy static content. The tests/testthat/examples/shiny fixture isn't used in the integration tests (test-get.R notes that "No shiny apps are deployed in integration tests").
To get a process to show up, the content has to keep a process running. On the R side that means Shiny or Plumber, so Connect would have to install those packages and their dependencies when deploying. The shiny fixture's manifest also pins R 3.6.3 and a long list of dependencies. The Python WSGI app with an empty requirements.txt installs nothing.
I've added a comment saying this above deploy_running_python_api(). It now also skips when the server has no Python installation, so it won't fail on images without one.
There was a problem hiding this comment.
🤖 Correction to my reply above: the Shiny fixture is used, in test-run-as.R, but that file skips on Connect > 2024.03.0 because the manifest pins R 3.6.3. The other integration tests deploy static and R Markdown content, which don't keep a process running. The reasoning holds: a Python WSGI app with an empty requirements.txt needs nothing installed. I've updated the code comment to match.
- Move get_processes(), get_procs() and helpers from R/get.R to R/processes.R, and their integration test to tests/integrated/test-processes.R. - Use purrr::map_lgl() instead of vapply() in legacy_processes(). - Explain why parse_processes_csv() reads everything as character rather than typing columns via colClasses. - Explain why the integration test deploys a Python API, and skip it when the server has no Python installation.
- get_processes() now errors on an empty content_guid, owner_guid, or hostname. Before, "" passed validation: the fallback's GUID checks requested the v1/content/ and v1/users/ list endpoints, so no 404 was raised, and the v1 endpoint was sent an empty query parameter. - Correct the integration test comment on why it deploys a Python API: other tests also deploy R Markdown, and the Shiny example is used by test-run-as.R but pins R 3.6.3.
|
@nealrichardson Thanks for the review! I made some changes based on your feedback and replied to the things Claude felt were best to leave as-is. This should be good to go now, I'll merge this once CI passes. |
Fixes #531. Fixes #532. Builds on #530 (merged); rebased onto
main.Connect 2026.11.0 adds
GET /v1/system/processes(posit-dev/connect#47671), a supported replacement for the internalGET /metrics/procs. This PR wraps it and deprecatesget_procs().Changes
get_processes(src, content_guid = NULL, owner_guid = NULL, hostname = NULL)GET /v1/system/processeswithAccept: text/csvand the endpoint's three filters (ANDed, same as the server).pidinteger,cpu_currentdouble,ramfs_bytes,start_time/heartbeatPOSIXct. Every CSV column is read as character first, so types don't depend on which values are present. Empty results are a typed, zero-row tibble with the same columns. Columns added by later Connect versions are kept.endpoint_does_not_exist()pattern), it calls/metrics/procsinstead. It renamesapp_*→content_*, dropsapp_id, and turns the old endpoint's placeholders ("unknown","unknown host","",pid0) intoNA, matching the v1 endpoint's nulls. Filters are applied client-side, andowner_guidis resolved throughGET /v1/content?owner_guid=. A 404 with a code (e.g. an unknowncontent_guid) is raised as an error, not treated as a reason to fall back.get_procs()is deprecated withlifecycle::deprecate_warn("0.13.0", "get_procs()", "get_processes()")and moved to@keywords internal. The request logic now lives in an internalfetch_legacy_procs(), which the fallback calls directly, soget_processes()never raises the deprecation warning.get_procs()usedimap()as if the response were keyed by PID. Current Connect returns an array, sopidwas the row index. It now returns the server'spid. The old keyed-by-PID shape is still handled.start_time/heartbeatare now parsed as datetimes.@returndocs now list the columns the endpoint actually returns.endpoint_does_not_exist()now passesencoding = "UTF-8". Without it, falling back on old Connect'stext/plain404 printedNo encoding supplied: defaulting to UTF-8.. This affects the other fallbacks that use the helper too.Verification
No published image has the endpoint yet: today's
connect-preview:dailywas built from39012c1, which predates the merge (git merge-base --is-ancestorsays no). I built the Connect server fromposit-dev/connect@5f81b53(currentmain, which includes #47671) in Connect's compilation container, and layered it ontoconnect-preview:daily. Then I ran the same tests against that build and against the current release, 2026.10.0, both started withwith-connect.Integration tests,
tests/integratedwithfilter = "get"andload_package = "installed". The new test deploys a dependency-free Python WSGI API, setsmin_processes = 1, and checks the columns, types, values, each filter, and thatget_procs()is deprecated and returns the same process with the realpid:2026.11.0-dev+main.5f81b53189(has the endpoint)[ FAIL 0 | WARN 0 | SKIP 1 | PASS 75 ]2026.10.0(fallback)[ FAIL 0 | WARN 0 | SKIP 1 | PASS 75 ](The skip is the existing
content_list_by_tag"not yet tested" placeholder.)Requests made, captured by tracing
httr::GETduring a script run against each server. New Connect makes one CSV request per call:Connect 2026.10.0 gets a 404 on v1, then falls back:
On both servers the result had the same 13 columns and classes:
get_procs()on both servers warns:It also returns the same
pidasget_processes()(548 on the new build, 610 on 2026.10.0) instead of1.I also checked the raw responses with
curl. New Connect returns a header-only CSV (text/csv; charset=utf-8) when nothing is running, and{"code":4,...}with a 404 for an unknowncontent_guid. 2026.10.0 returns404 page not foundastext/plainfor/v1/system/processes.Unit tests (
tests/testthat/test-processes.R, 104 expectations) useMockConnect, with a small subclass that records the headers and query of each request. They cover:Accept: text/csvheader and filter query paramsowner_guidget_procs(): deprecation, realpid, and the old keyed-by-PID formatThe test that the fallback doesn't warn passes
class = "lifecycle_warning_deprecated", becauseexpect_no_warning()ignores deprecation warnings by default. I confirmed it fails if the fallback is changed to callget_procs().devtools::lint()(same as CI): 0 lintsR CMD check --no-manual: 0 errors, 0 warnings, 0 notes