Skip to content

Commit e33a219

Browse files
committed
Move everything to the new labels API internally.
1 parent e416d36 commit e33a219

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

R/plumber.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ register_plumber_metrics <- function(app, registry = global_registry()) {
4141
# * https://www.npmjs.com/package/prometheus-api-metrics
4242
# * https://github.com/tdeekens/promster
4343
requests <- counter_metric(
44-
"http_request", "Running total of HTTP requests.", path = "/",
45-
method = "GET", status = "200", registry = registry
44+
"http_request", "Running total of HTTP requests.",
45+
labels = c("path", "method", "status"), registry = registry
4646
)
4747
duration <- histogram_metric(
4848
"http_request_duration_seconds", "Duration of HTTP requests, in seconds.",
4949
# These are what node.js's prom-client uses.
5050
buckets = c(0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10),
51-
path = "/", method = "GET", status = "200", registry = registry
51+
labels = c("path", "method", "status"), registry = registry
5252
)
5353

5454
preroute_hook <- function(req, res) {

tests/testthat/test-metrics.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ testthat::test_that("Metrics with labels work as expected", {
8585
testthat::expect_equal(length(collect_metrics(reg)), 0)
8686

8787
counter <- counter_metric(
88-
"count", "Custom counter.", method = "GET", endpoint = "/", registry = reg
88+
"count", "Custom counter.", labels = c("method", "endpoint"),
89+
registry = reg
8990
)
9091
testthat::expect_equal(counter$inc(5, method = "GET", endpoint = "/"), 5)
9192
testthat::expect_equal(
@@ -94,7 +95,7 @@ testthat::test_that("Metrics with labels work as expected", {
9495
testthat::expect_equal(counter$inc(method = "POST", endpoint = "/"), 1)
9596

9697
gauge <- gauge_metric(
97-
"value", "Custom gauge.", method = "GET", endpoint = "/", registry = reg
98+
"value", "Custom gauge.", labels = c("method", "endpoint"), registry = reg
9899
)
99100
testthat::expect_equal(gauge$set(5, method = "GET", endpoint = "/"), 5)
100101
testthat::expect_equal(
@@ -103,7 +104,8 @@ testthat::test_that("Metrics with labels work as expected", {
103104
testthat::expect_equal(gauge$inc(method = "POST", endpoint = "/"), 1)
104105

105106
hist <- histogram_metric(
106-
"dist", "Custom histogram.", method = "GET", endpoint = "/", registry = reg
107+
"dist", "Custom histogram.", labels = c("method", "endpoint"),
108+
registry = reg
107109
)
108110
testthat::expect_equal(
109111
hist$observe(51.7, method = "GET", endpoint = "/"), 51.7
@@ -214,7 +216,8 @@ testthat::test_that("Histogram metrics render correctly in legacy format", {
214216
reg <- registry()
215217

216218
hist <- histogram_metric(
217-
"dist", "Custom histogram.", method = "GET", endpoint = "/", registry = reg
219+
"dist", "Custom histogram.", labels = c("method", "endpoint"),
220+
registry = reg
218221
)
219222
hist$observe(51.7, method = "GET", endpoint = "/")
220223
hist$observe(10, method = "GET", endpoint = "/",ignored = "value")

tests/testthat/test-pushgateway.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ testthat::test_that("Pushgateway interaction works as expected", {
77
)
88
counter$inc(5)
99
hist <- histogram_metric(
10-
"dist", "Custom histogram.", method = "GET", endpoint = "/", registry = reg
10+
"dist", "Custom histogram.", labels = c("method", "endpoint"),
11+
registry = reg
1112
)
1213
hist$observe(51.7, method = "GET", endpoint = "/")
1314
hist$observe(10, method = "GET", endpoint = "/",ignored = "value")

0 commit comments

Comments
 (0)