Adding Prometheus metrics, refactoring code
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
prometheus "http-broadcaster/Prometheus"
|
||||
varnish "http-broadcaster/Varnish"
|
||||
"io"
|
||||
"log"
|
||||
@@ -15,18 +16,19 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
tag := r.Header.Get("X-Cache-Tags")
|
||||
remoteAddr := r.RemoteAddr
|
||||
status := varnish.SendToVarnish(method, url, tag)
|
||||
prometheus.IncrementClientCounterVec(method)
|
||||
if status != "200 Purged" {
|
||||
w.WriteHeader(405)
|
||||
}
|
||||
if tag != "" {
|
||||
log.Println(remoteAddr + " Requested ban on X-Cache-Tags : " + tag + " , status: " + status)
|
||||
log.Println(remoteAddr + " Requested " + method + " on X-Cache-Tags : " + tag + " , status: " + status)
|
||||
} else {
|
||||
log.Println(remoteAddr + " Requested purge on URI :" + url + " , status: " + status)
|
||||
log.Println(remoteAddr + " Requested " + method + " on URI :" + url + " , status: " + status)
|
||||
}
|
||||
io.WriteString(w, status)
|
||||
_, _ = io.WriteString(w, status)
|
||||
}
|
||||
|
||||
// HealthHandler handles healthcheck requests and return 200.
|
||||
func HealthHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
io.WriteString(w, "OK")
|
||||
_, _ = io.WriteString(w, "OK")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user