forked from labbsr0x/mux-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
49 lines (38 loc) · 1.18 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gin_monitor_test
import (
"log"
"net/http"
"testing"
"time"
ginMonitor "github.com/bancodobrasil/gin-monitor"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
type FakeDependencyChecker struct{}
func (m *FakeDependencyChecker) GetDependencyName() string {
return "fake-dependency"
}
func (m *FakeDependencyChecker) Check() ginMonitor.DependencyStatus {
return ginMonitor.DOWN
}
func YourHandler(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("gin-monitor!\n"))
}
func TestMainHandler(t *testing.T) {
// Creates gin-monitor instance
monitor, err := ginMonitor.New("v1.0.0", ginMonitor.DefaultErrorMessageKey, ginMonitor.DefaultBuckets)
if err != nil {
panic(err)
}
dependencyChecker := &FakeDependencyChecker{}
monitor.AddDependencyChecker(dependencyChecker, time.Second*30)
r := gin.New()
// Register gin-monitor middleware
r.Use(monitor.Prometheus())
// Register metrics endpoint
r.GET("/metrics", gin.WrapH(promhttp.Handler()))
// Routes consist of a path and a handler function.
r.GET("/", gin.WrapF(YourHandler))
// Bind to a port and pass our router in
log.Fatal(http.ListenAndServe(":8000", r))
}