Skip to content

Commit

Permalink
Merge pull request #18 from conbench/aus/paginate2
Browse files Browse the repository at this point in the history
Add pagination to runs()
  • Loading branch information
boshek authored Oct 20, 2023
2 parents 121c202 + b844a83 commit d737097
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 118 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: conbenchcoms
Title: An API wrapper for conbench communications
Version: 0.0.6
Version: 0.0.7
Authors@R: c(
person("Jonathan", "Keane", , "[email protected]", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0001-7087-9776")),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# conbenchcoms 0.0.7
* Remove `sha`, `simplifyVector`, and `flatten` arguments from `runs`
* Add `commit_hashes` argument to `runs`
* `runs` now always returns a `tibble`
* `runs` now paginates until all matching data is returned, which works only with Conbench servers of at least version [7e4d9d0](https://github.com/conbench/conbench/commit/7e4d9d0)
* Make `benchmarks` defunct

# conbenchcoms 0.0.6
* Remove `batch_id`, `limit`, `days`, `simplifyVector`, and `flatten` arguments from `benchmark_results`
* Add `earliest_timestamp` and `latest_timestamp` arguments to `benchmark_results`
Expand Down
29 changes: 5 additions & 24 deletions R/benchmark-results.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@
#' @param run_reason a string to specify the run reason (default: `NULL`, list all)
#' @param earliest_timestamp the earliest benchmark result timestamp (default: `NULL`, go back as far as possible)
#' @param latest_timestamp the latest benchmark result timestamp (default: `NULL`, go up to the current time)
#' @inheritParams runs
#'
#' @return a tibble of benchmark results
#' @export
benchmark_results <- function(
run_id = NULL,
run_reason = NULL,
earliest_timestamp = NULL,
latest_timestamp = NULL,
...) {
latest_timestamp = NULL) {
## Assert that run_id is a string
if (length(run_id) > 1) {
stop("Too many run_ids, please limit to 1.", call. = FALSE)
Expand All @@ -56,7 +54,7 @@ benchmark_results <- function(
cursor = NULL
)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE, ...)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
data <- dplyr::as_tibble(json[["data"]])

while (!is.null(json[["metadata"]][["next_page_cursor"]])) {
Expand All @@ -68,7 +66,7 @@ benchmark_results <- function(
cursor = json[["metadata"]][["next_page_cursor"]]
)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE, ...)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
data <- dplyr::bind_rows(data, dplyr::as_tibble(json[["data"]]))
}

Expand All @@ -80,23 +78,6 @@ benchmark_results <- function(
#' @rdname benchmark_results
#' @param batch_id deprecated
#' @export
benchmarks <- function(run_id = NULL, batch_id = NULL, run_reason = NULL, simplifyVector = TRUE, flatten = TRUE, ...) {
.Deprecated("benchmark_results")

req <- req_url_path_append(conbench_request(), "benchmarks")

if (!is.null(run_reason)) {
req <- req_url_query(req, run_reason = run_reason)
}

if (!is.null(batch_id)) {
req <- req_url_query(req, batch_id = paste0(batch_id, collapse = ","))
}

if (!is.null(run_id)) {
req <- req_url_query(req, run_id = paste0(run_id, collapse = ","))
}
resp <- conbench_perform(req)

resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
benchmarks <- function(run_id = NULL, batch_id = NULL, run_reason = NULL) {
.Defunct("benchmark_results")
}
2 changes: 1 addition & 1 deletion R/hardware.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Get hardware
#'
#' @param id the id of one specific hardware to get data for.
#' @inheritParams runs
#' @inheritParams jsonlite::fromJSON
#'
#' @return the response
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/history.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Get history for a benchmark
#'
#' @param benchmark_id the hash of a benchmark to get the history for
#' @inheritParams runs
#' @inheritParams jsonlite::fromJSON
#'
#' @return the response
#' @export
Expand Down
4 changes: 1 addition & 3 deletions R/info.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Get a list of benchmark info
#'
#' @param id the info id for benchmark info
#' @inheritParams runs
#' @inheritParams jsonlite::fromJSON
#'
#' @return the response
#' @export
Expand All @@ -17,5 +17,3 @@ info <- function(id = NULL, simplifyVector = TRUE, flatten = TRUE, ...) {

resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
}


36 changes: 25 additions & 11 deletions R/runs.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
#' Get a list of runs
#' Get runs
#'
#' @param sha the hash of a commit to search for (default: `NULL`, list all)
#' @inheritParams jsonlite::fromJSON
#' @inheritDotParams httr2::resp_body_json
#' @param commit_hashes the commit hashes to search for (required)
#'
#' @return the response
#' @return a tibble of runs
#' @export
runs <- function(sha = NULL, simplifyVector = TRUE, flatten = TRUE, ...) {
runs <- function(commit_hashes) {
req <- req_url_path_append(conbench_request(), "runs")
req <- req_url_query(
req,
page_size = 1000,
commit_hash = paste0(commit_hashes, collapse = ",")
)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
data <- dplyr::as_tibble(json[["data"]])

if (!is.null(sha)) {
req <- req_url_query(req, sha = paste0(sha, collapse = ","))
while (!is.null(json[["metadata"]][["next_page_cursor"]])) {
req <- req_url_path_append(conbench_request(), "runs")
req <- req_url_query(
req,
page_size = 1000,
commit_hash = paste0(commit_hashes, collapse = ","),
cursor = json[["metadata"]][["next_page_cursor"]]
)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
data <- dplyr::bind_rows(data, dplyr::as_tibble(json[["data"]]))
}
resp <- conbench_perform(req)

resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
}
data
}
18 changes: 2 additions & 16 deletions man/benchmark_results.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/conbenchcoms-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 5 additions & 17 deletions man/runs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions tests/testthat/resp-class/localhost/api/runs-d269db.json

This file was deleted.

16 changes: 0 additions & 16 deletions tests/testthat/resp-class/localhost/api/runs-dce918.json

This file was deleted.

13 changes: 13 additions & 0 deletions tests/testthat/resp-class/localhost/api/runs-ebe91f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"data": [
{
"commit": {
"sha": "babb1ed",
"timestamp": "2022-03-20T21:05:12"
}
}
],
"metadata": {
"next_page_cursor": null
}
}
14 changes: 14 additions & 0 deletions tests/testthat/resp-class/localhost/api/runs-f23dbb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": [
{
"commit": {
"id": "id1",
"sha": "babb1ed",
"timestamp": "2022-03-20T21:05:12"
}
}
],
"metadata": {
"next_page_cursor": "curse"
}
}
14 changes: 14 additions & 0 deletions tests/testthat/resp-class/localhost/api/runs-f323bc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": [
{
"commit": {
"id": "id2",
"sha": "5eaf00d",
"timestamp": "2022-05-20T21:05:12"
}
}
],
"metadata": {
"next_page_cursor": null
}
}
27 changes: 7 additions & 20 deletions tests/testthat/test-runs.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
with_mock_dir(test_path("logged-in"), {
test_that("runs()", {
expect_GET(
runs(),
"http://localhost/api/runs"
)

expect_GET(
runs(sha = "C0C0A"),
"http://localhost/api/runs?sha=C0C0A"
runs(commit_hashes = c("C0C0A", "BEEF")),
"http://localhost/api/runs?page_size=1000&commit_hash=C0C0A%2CBEEF"
)
})
})

with_mock_dir(test_path("resp-class"), {
sha_1 <- "babb1ed"
sha_2 <- "5eaf00d"
test_that("runs() returns a data.frame", {
the_run <- runs(sha = sha_1)
test_that("runs() returns a tibble", {
the_run <- runs(commit_hashes = sha_1)
expect_s3_class(
the_run,
"data.frame"
"tbl_df"
)
expect_identical(sha_1, the_run$commit.sha)
})

test_that("runs() accepts and returns multiple values", {
shas <- c(sha_1, sha_2)
runs <- runs(sha = shas)
runs <- runs(commit_hashes = shas)
expect_s3_class(
runs,
"data.frame"
"tbl_df"
)
expect_identical(shas, unique(runs$commit.sha))
})

test_that("runs() returns a list", {
the_list_run <- runs(sha = sha_1, simplifyVector = FALSE, flatten = FALSE)
expect_type(
the_list_run,
"list"
)
expect_identical(sha_1, the_list_run[[1]]$commit$sha)
})
})

0 comments on commit d737097

Please sign in to comment.