Skip to content

Commit 84c2f70

Browse files
authored
Merge pull request #21 from conbench/aus/paginate3
paginate over compare runs endpoint
2 parents 4e0a932 + 2aaf8e1 commit 84c2f70

28 files changed

+228
-101
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: conbenchcoms
22
Title: An API wrapper for conbench communications
3-
Version: 0.0.8
3+
Version: 0.0.9
44
Authors@R: c(
55
person("Jonathan", "Keane", , "[email protected]", role = c("aut", "ctb"),
66
comment = c(ORCID = "0000-0001-7087-9776")),

NAMESPACE

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
export(benchmark_results)
44
export(benchmarks)
5-
export(compare)
5+
export(compare_results)
6+
export(compare_runs)
67
export(conbench_perform)
78
export(conbench_request)
89
export(hardware)

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# conbenchcoms 0.0.9
2+
* Remove `compare` function
3+
* Add `compare_results` function (similar to old `compare` but only works for comparing benchmark results)
4+
* Add `compare_runs` function, which returns a tibble, paginating until all matching data is returned, which works only with Conbench servers of at least version [ad06af9](https://github.com/conbench/conbench/commit/ad06af9)
5+
16
# conbenchcoms 0.0.8
27
* Remove `simplifyVector` and `flatten` arguments from `history`
38
* `history` now always returns a `tibble`

R/compare.R

+73-13
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
#' Compare runs, benchmarks, batches, or commits
1+
#' Compare benchmark results
22
#'
3-
#' @param type the type of comparison to make (one of: runs, benchmarks, batches, commits)
4-
#' @param baseline the baseline sha of the entity to compare
5-
#' @param contender the contender sha of the entity to compare
6-
#' @param zscore_threshold the zscore threshold to mark regressions and improvements.
3+
#' @param baseline the ID of the baseline result to compare
4+
#' @param contender the ID of the contender result to compare
5+
#' @param zscore_threshold the zscore threshold to mark regressions and improvements.
76
#' Default is defined at the Conbench api level.
87
#' @param pairwise_percent_threshold the pairwise_percent_threshold to mark regressions and improvements.
98
#' Default is defined at the Conbench api level.
109
#' @inheritDotParams httr2::resp_body_json
1110
#'
1211
#' @return the JSON response
1312
#' @export
14-
compare <- function(type = c("runs", "benchmarks", "batches", "commits"),
15-
baseline,
16-
contender,
17-
zscore_threshold = NULL,
18-
pairwise_percent_threshold = NULL,
19-
...) {
20-
type <- match.arg(type)
13+
compare_results <- function(baseline,
14+
contender,
15+
zscore_threshold = NULL,
16+
pairwise_percent_threshold = NULL,
17+
...) {
2118
stopifnot("zscore_threshold must be numeric" = is.numeric(zscore_threshold) || is.null(zscore_threshold))
2219
stopifnot("pairwise_percent_threshold must be numeric" = is.numeric(pairwise_percent_threshold) || is.null(pairwise_percent_threshold))
2320

2421
req <- req_url_path_append(
2522
conbench_request(),
2623
"compare",
27-
type,
24+
"benchmark-results",
2825
paste0(baseline, "...", contender)
2926
)
3027

@@ -40,3 +37,66 @@ compare <- function(type = c("runs", "benchmarks", "batches", "commits"),
4037

4138
resp_body_json(resp, ...)
4239
}
40+
41+
#' Compare runs
42+
#'
43+
#' @param baseline the ID of the baseline run to compare
44+
#' @param contender the ID of the contender run to compare
45+
#' @param zscore_threshold the zscore threshold to mark regressions and improvements.
46+
#' Default is defined at the Conbench api level.
47+
#' @param pairwise_percent_threshold the pairwise_percent_threshold to mark regressions and improvements.
48+
#' Default is defined at the Conbench api level.
49+
#'
50+
#' @return a tibble of run comparisons
51+
#' @export
52+
compare_runs <- function(baseline,
53+
contender,
54+
zscore_threshold = NULL,
55+
pairwise_percent_threshold = NULL) {
56+
stopifnot("zscore_threshold must be numeric" = is.numeric(zscore_threshold) || is.null(zscore_threshold))
57+
stopifnot("pairwise_percent_threshold must be numeric" = is.numeric(pairwise_percent_threshold) || is.null(pairwise_percent_threshold))
58+
59+
req <- req_url_path_append(
60+
conbench_request(),
61+
"compare",
62+
"runs",
63+
paste0(baseline, "...", contender)
64+
)
65+
req <- req_url_query(req, page_size = 500)
66+
if (!is.null(zscore_threshold)) {
67+
req <- req_url_query(req, threshold_z = zscore_threshold)
68+
}
69+
if (!is.null(pairwise_percent_threshold)) {
70+
req <- req_url_query(req, threshold = pairwise_percent_threshold)
71+
}
72+
73+
resp <- conbench_perform(req)
74+
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
75+
data <- dplyr::as_tibble(json[["data"]])
76+
77+
while (!is.null(json[["metadata"]][["next_page_cursor"]])) {
78+
req <- req_url_path_append(
79+
conbench_request(),
80+
"compare",
81+
"runs",
82+
paste0(baseline, "...", contender)
83+
)
84+
req <- req_url_query(
85+
req,
86+
page_size = 500,
87+
cursor = json[["metadata"]][["next_page_cursor"]]
88+
)
89+
if (!is.null(zscore_threshold)) {
90+
req <- req_url_query(req, threshold_z = zscore_threshold)
91+
}
92+
if (!is.null(pairwise_percent_threshold)) {
93+
req <- req_url_query(req, threshold = pairwise_percent_threshold)
94+
}
95+
96+
resp <- conbench_perform(req)
97+
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE)
98+
data <- dplyr::bind_rows(data, dplyr::as_tibble(json[["data"]]))
99+
}
100+
101+
data
102+
}

man/compare.Rd man/compare_results.Rd

+7-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/compare_runs.Rd

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/resp-class/localhost/api/compare/runs/10aded...0af-81f373.json

-18
This file was deleted.

tests/testthat/resp-class/localhost/api/compare/runs/ee1...f00d-dd5b56.json

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"analysis": {
3+
"lookback_z_score": {
4+
"improvement_indicated": false,
5+
"regression_indicated": false,
6+
"z_score": -0.5,
7+
"z_threshold": 11.1
8+
},
9+
"pairwise": {
10+
"improvement_indicated": false,
11+
"percent_change": -26,
12+
"percent_threshold": 20.2,
13+
"regression_indicated": true
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"data": [
3+
{
4+
"analysis": {
5+
"lookback_z_score": {
6+
"improvement_indicated": false,
7+
"regression_indicated": false,
8+
"z_score": -0.5,
9+
"z_threshold": 11.1
10+
},
11+
"pairwise": {
12+
"improvement_indicated": false,
13+
"percent_change": -26,
14+
"percent_threshold": 20.2,
15+
"regression_indicated": true
16+
}
17+
}
18+
}
19+
],
20+
"metadata": {
21+
"next_page_cursor": "curse"
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"data": [
3+
{
4+
"analysis": {
5+
"lookback_z_score": {
6+
"improvement_indicated": false,
7+
"regression_indicated": false,
8+
"z_score": -0.5,
9+
"z_threshold": 11.1
10+
},
11+
"pairwise": {
12+
"improvement_indicated": false,
13+
"percent_change": -26,
14+
"percent_threshold": 20.2,
15+
"regression_indicated": true
16+
}
17+
}
18+
}
19+
],
20+
"metadata": {
21+
"next_page_cursor": null
22+
}
23+
}

tests/testthat/test-benchmark-results.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ with_mock_dir(test_path("logged-in"), {
1212
})
1313
})
1414

15-
with_mock_dir(test_path("resp-class"), {
15+
with_mock_dir(test_path("resp"), {
1616
run_id_1 <- "5a1ad"
1717
run_id_2 <- "5eaf00d"
1818
batch_id_1 <- "abba0123"

0 commit comments

Comments
 (0)