Skip to content

Commit

Permalink
feat: ambiorix middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Feb 28, 2022
1 parent 6ca55d3 commit e4b8be7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -18,7 +18,7 @@ License: AGPL-3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Imports:
R6,
shiny,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -23,5 +23,6 @@ export(previewMetrics)
export(renderMetrics)
export(setAuthentication)
export(setTitanNamespace)
export(titan)
export(titanApp)
importFrom(utils,getFromNamespace)
4 changes: 4 additions & 0 deletions NEWS.md
@@ -1,3 +1,7 @@
# titan 2.0.1

- Added ambiorix middleware

# titan 2.0.0

- Refactor entire source code.
Expand Down
18 changes: 18 additions & 0 deletions R/ambiorix.R
@@ -0,0 +1,18 @@
#' Ambiorix Middleware
#'
#' Middleware for ambiorix.
#'
#' @param path Path on which to serve the metrics.
#' Default recommended.
#'
#' @export
titan <- function(
path = "metrics"
) {
function(req, res) {
if(!req$PATH_INFO == "/metrics")
return()

res$test(renderMetrics())
}
}
8 changes: 3 additions & 5 deletions docs/guide/ambiorix.md
Expand Up @@ -11,7 +11,7 @@ Then again, the metrics themselves and their usage does not differ, only the way

With [ambiorix](https://github.com/JohnCoene/ambiorix), create a new `get` method on the `/metrics` endpoint, and have it return the results of `renderMetrics`.

```r hl_lines="23 24 25"
```r hl_lines="11"
library(titan)
library(ambiorix)

Expand All @@ -24,6 +24,8 @@ c <- Counter$new(

app <- Ambiorix$new()

app$use(titan())

app$get("/", function(req, res){
c$inc(path = "/")
res$send("Using {titan} with {ambiorix}!")
Expand All @@ -34,9 +36,5 @@ app$get("/about", function(req, res){
res$send("About {titan} and {ambiorix}!")
})

app$get("/metrics", function(req, res){
res$text(renderMetrics())
})

app$start()
```
15 changes: 15 additions & 0 deletions man/titan.Rd

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

0 comments on commit e4b8be7

Please sign in to comment.