-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allows saving of HTTP events into PostgreSQL (#150)
* feat: Allows saving of HTTP events into PostgreSQL * chore: Changes fields in postgresql schema * chore: Adds better plumber example * chore: Adds UUID to http events table * chore: Adds optional version to the namespace
- Loading branch information
1 parent
56f4430
commit b215aef
Showing
18 changed files
with
1,534 additions
and
133 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,61 @@ git clone https://github.com/ixpantia/faucet.git | |
cargo install --path . | ||
``` | ||
|
||
## HTTP Telemetry | ||
|
||
faucet now offers the option of saving HTTP events to a PostgreSQL database. | ||
This can be very helpful for tracking latency, total API calls and other | ||
important information. | ||
|
||
In order to use this feature you will need a PostgreSQL database with a table | ||
called `faucet_http_events`. You can create the table using this table with | ||
the following SQL query: | ||
|
||
```sql | ||
CREATE TABLE faucet_http_events ( | ||
request_uuid UUID, | ||
namespace TEXT, | ||
version TEXT, | ||
target TEXT, | ||
worker_route TEXT, | ||
worker_id INT, | ||
ip_addr INET, | ||
method TEXT, | ||
path TEXT, | ||
query_params TEXT, | ||
http_version TEXT, | ||
status SMALLINT, | ||
user_agent TEXT, | ||
elapsed BIGINT, | ||
time TIMESTAMPTZ | ||
); | ||
``` | ||
|
||
### Connection Strings | ||
|
||
In order to connect to the database you will need to pass the | ||
`FAUCET_TELEMETRY_POSTGRES_STRING` environment variable or the | ||
`--pg-con-string` CLI argument. | ||
|
||
This should include either a connection string or a URL with the `postgres://` | ||
protocol. | ||
|
||
#### Example connection strings | ||
|
||
```sh | ||
FAUCET_TELEMETRY_POSTGRES_STRING="host=localhost user=postgres connect_timeout=10 keepalives=0" | ||
FAUCET_TELEMETRY_POSTGRES_STRING="host=/var/lib/postgresql,localhost port=1234 user=postgres password='password with spaces'" | ||
FAUCET_TELEMETRY_POSTGRES_STRING="postgresql://user@localhost" | ||
FAUCET_TELEMETRY_POSTGRES_STRING="postgresql://user:[email protected]/mydb?connect_timeout=10" | ||
``` | ||
|
||
### Telemetry Namespaces | ||
|
||
It is likely you want to track different services on the same database. You | ||
can control the column `namespace` using the environment variable | ||
`FAUCET_TELEMETRY_NAMESPACE` or cli argument `--telemetry-namespace`. By | ||
default, this value is `"faucet"`. | ||
|
||
## Contributing | ||
|
||
If you want to contribute to `faucet` please read the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
library(shiny) | ||
library(bslib) | ||
|
||
# Define UI for app that draws a histogram ---- | ||
ui <- page_sidebar( | ||
# App title ---- | ||
title = "Hello Shiny!", | ||
# Sidebar panel for inputs ---- | ||
sidebar = sidebar( | ||
# Input: Slider for the number of bins ---- | ||
sliderInput( | ||
inputId = "bins", | ||
label = "Number of bins:", | ||
min = 1, | ||
max = 50, | ||
value = 30 | ||
) | ||
), | ||
# Output: Histogram ---- | ||
plotOutput(outputId = "distPlot") | ||
) | ||
|
||
# Define server logic required to draw a histogram ---- | ||
server <- function(input, output) { | ||
|
||
# Histogram of the Old Faithful Geyser Data ---- | ||
# with requested number of bins | ||
# This expression that generates a histogram is wrapped in a call | ||
# to renderPlot to indicate that: | ||
# | ||
# 1. It is "reactive" and therefore should be automatically | ||
# re-executed when inputs (input$bins) change | ||
# 2. Its output type is a plot | ||
output$distPlot <- renderPlot({ | ||
|
||
x <- faithful$waiting | ||
bins <- seq(min(x), max(x), length.out = input$bins + 1) | ||
|
||
hist(x, breaks = bins, col = "#007bc2", border = "white", | ||
xlab = "Waiting time to next eruption (in mins)", | ||
main = "Histogram of waiting times") | ||
|
||
}) | ||
|
||
} | ||
|
||
shinyApp(ui, server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
#* @get / | ||
function() { | ||
"Hello, world!" | ||
# plumber.R | ||
|
||
#* @param n Seconds to sleep | ||
#* @get /sleep | ||
function(n = 1L) { | ||
Sys.sleep(as.numeric(n)) | ||
} | ||
|
||
#* Echo the parameter that was sent in | ||
#* @param msg The message to echo back. | ||
#* @get /echo | ||
function(msg = "") { | ||
list(msg = paste0("The message is: '", msg, "'")) | ||
} | ||
|
||
#* Plot out data from the iris dataset | ||
#* @param spec If provided, filter the data to only this species (e.g. 'setosa') | ||
#* @get /plot | ||
#* @serializer png | ||
function(spec) { | ||
myData <- iris | ||
title <- "All Species" | ||
|
||
# Filter if the species was specified | ||
if (!missing(spec)) { | ||
title <- paste0("Only the '", spec, "' Species") | ||
myData <- subset(iris, Species == spec) | ||
} | ||
|
||
plot(myData$Sepal.Length, myData$Petal.Length, | ||
main = title, xlab = "Sepal Length", ylab = "Petal Length" | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CREATE TABLE faucet_http_events ( | ||
request_uuid UUID, | ||
namespace TEXT, | ||
version TEXT, | ||
target TEXT, | ||
worker_route TEXT, | ||
worker_id INT, | ||
ip_addr INET, | ||
method TEXT, | ||
path TEXT, | ||
query_params TEXT, | ||
http_version TEXT, | ||
status SMALLINT, | ||
user_agent TEXT, | ||
elapsed BIGINT, | ||
time TIMESTAMPTZ NOT NULL | ||
); | ||
|
||
-- For use in timescale | ||
-- SELECT create_hypertable('faucet_http_events', by_range('time')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.