Skip to content

Commit

Permalink
Merge pull request #16 from conbench/aus/paginate
Browse files Browse the repository at this point in the history
change benchmark_results to use pagination
  • Loading branch information
boshek authored Oct 18, 2023
2 parents 34f8e7e + 3572702 commit 121c202
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 190 deletions.
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
Package: conbenchcoms
Title: An API wrapper for conbench communications
Version: 0.0.5
Version: 0.0.6
Authors@R: c(
person("Jonathan", "Keane", , "[email protected]", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0001-7087-9776")),
person("Sam", "Albers", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9270-7884")),
person("Edward", "Visel", , "[email protected]", role = c("aut", "ctb"),
comment = c(ORCID = "0000-0002-2811-6254")),
person("Austin", "Dickey", , "[email protected]", role = c("aut", "ctb")),
person(given = "Voltron Data",
role = c("cph", "fnd"))
)
Description: An R interface to the conbench API.
License: Apache License (>= 2)
Depends:
Depends:
R (>= 4.1.0)
Imports:
dplyr,
glue,
httr2 (>= 0.2.2),
yaml
Suggests:
Suggests:
httptest2,
testthat (>= 3.0.0),
withr
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 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`
* `benchmark_results` now always returns a `tibble`
* The `run_id` argument of `benchmark_results` can now only take 1 ID
* `benchmark_results` now is able to accept any combination of filters instead of requiring 1 at a time
* `benchmark_results` now paginates until *all* matching data is returned, which works only with Conbench servers of at least version [6c1b93](https://github.com/conbench/conbench/commit/6c1b93)

# conbenchcoms 0.0.5
* display more verbose errors when the Conbench API returns an error

Expand Down
111 changes: 62 additions & 49 deletions R/benchmark-results.R
Original file line number Diff line number Diff line change
@@ -1,72 +1,85 @@
#' Get a list of benchmark results
#'
#' @param run_id the run_id to get benchmarks for (default: `NULL`, list all)
#' @param batch_id the batch_id to get benchmarks for (default: `NULL`, list all)
#' @param run_reason a string to specify the run reason (default: `NULL`, list all)
#' @param limit the number of results to return for a specific `run_reason` is also specified (default: `NULL`, list all)
#' @param days the number of days to look back from today for benchmark results. (default: `NULL`, list all)
#' @inheritParams runs
#'
#' @return a data.frame of benchmark results
#' @export
benchmark_results <- function(
run_id = NULL,
batch_id = NULL,
run_reason = NULL,
limit = NULL,
days = NULL,
simplifyVector = TRUE,
flatten = TRUE,
...) {
## Assert that run_id is a vector of length 5 or less
if (length(unique(run_id)) > 5) {
stop("Too many run_ids, please limit to 5 or less or consider making separate requests.", call. = FALSE)
}

## Assert that only one of run_id, batch_id or run_reason is non-NULL
non_null_count <- Filter(Negate(is.null), list(run_id, batch_id, run_reason))
.construct_request <- function(
run_id, run_reason, earliest_timestamp, latest_timestamp, cursor
) {
req <- req_url_path_append(conbench_request(), "benchmark-results")
req <- req_url_query(req, page_size = 1000)

if (length(non_null_count) >= 2) {
stop("Only one of run_id, batch_id or run_reason can be non-NULL", call. = FALSE)
if (!is.null(run_id)) {
req <- req_url_query(req, run_id = run_id)
}

req <- req_url_path_append(conbench_request(), "benchmark-results")

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

if (!is.null(days)) {
days <- integer_messager(days, label = "days")
req <- req_url_query(req, days = days)
if (!is.null(earliest_timestamp)) {
req <- req_url_query(req, earliest_timestamp = earliest_timestamp)
}

if (!is.null(limit) && !is.null(run_reason)) {
limit <- integer_messager(limit, label = "limit")
req <- req_url_query(req, limit = limit)
}

if (!is.null(limit) && is.null(run_reason)) {
stop("you are setting a limit without setting run_reason. please set run_reason and try again", call. = TRUE)
if (!is.null(latest_timestamp)) {
req <- req_url_query(req, latest_timestamp = latest_timestamp)
}

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

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

#' Get a list of benchmark results
#'
#' @param run_id the run_id to get benchmarks for (default: `NULL`, list all)
#' @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,
...) {
## Assert that run_id is a string
if (length(run_id) > 1) {
stop("Too many run_ids, please limit to 1.", call. = FALSE)
}

req <- .construct_request(
run_id = run_id,
run_reason = run_reason,
earliest_timestamp = earliest_timestamp,
latest_timestamp = latest_timestamp,
cursor = NULL
)
resp <- conbench_perform(req)
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE, ...)
data <- dplyr::as_tibble(json[["data"]])

while (!is.null(json[["metadata"]][["next_page_cursor"]])) {
req <- .construct_request(
run_id = run_id,
run_reason = run_reason,
earliest_timestamp = earliest_timestamp,
latest_timestamp = latest_timestamp,
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_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
data
}

#' `benchmarks` is deprecated method of getting benchmark results and will be
#' `benchmarks` is deprecated method of getting benchmark results and will be
#' retired in a future release. Please use `benchmark_results` instead.
#' @rdname benchmark_results
#' @export
#' @param batch_id deprecated
#' @export
benchmarks <- function(run_id = NULL, batch_id = NULL, run_reason = NULL, simplifyVector = TRUE, flatten = TRUE, ...) {
.Deprecated("benchmark_results")

Expand All @@ -86,4 +99,4 @@ benchmarks <- function(run_id = NULL, batch_id = NULL, run_reason = NULL, simpli
resp <- conbench_perform(req)

resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...)
}
}
21 changes: 9 additions & 12 deletions man/benchmark_results.Rd

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

6 changes: 4 additions & 2 deletions man/compare.Rd

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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"data": [
{
"run_id": "5a1ad",
"timestamp": "2022-05-06T03:39:44.222350"
}
],
"metadata": {
"next_page_cursor": null
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": [
{
"run_id": "5eaf00d",
"timestamp": "2022-05-07T03:39:44.222350",
"tags": {
"c": "d"
}
}
],
"metadata": {
"next_page_cursor": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"data": [
{
"batch_id": "abba0123",
"timestamp": "2022-05-06T03:39:44.222350"
}
],
"metadata": {
"next_page_cursor": null
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": [
{
"timestamp": "2022-05-06T03:39:44.222350"
}
],
"metadata": {
"next_page_cursor": null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": [
{
"run_id": "5eaf00d",
"timestamp": "2022-05-06T03:39:44.222350",
"tags": {
"a": "b"
}
}
],
"metadata": {
"next_page_cursor": "cursor"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 121c202

Please sign in to comment.