-
Notifications
You must be signed in to change notification settings - Fork 480
/
GrafanaRouter.go
44 lines (39 loc) · 1.11 KB
/
GrafanaRouter.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
package router
import (
"fmt"
"github.com/devtron-labs/devtron/client/grafana"
"github.com/gorilla/mux"
"go.uber.org/zap"
"net"
"net/http"
"time"
)
type GrafanaRouter interface {
initGrafanaRouter(router *mux.Router)
}
type GrafanaRouterImpl struct {
logger *zap.SugaredLogger
grafanaProxy func(writer http.ResponseWriter, request *http.Request)
}
func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config) *GrafanaRouterImpl {
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}
grafanaProxy := grafana.NewGrafanaHTTPReverseProxy(fmt.Sprintf("http://%s:%s", grafanaCfg.Host, grafanaCfg.Port), client.Transport)
router := &GrafanaRouterImpl{
grafanaProxy: grafanaProxy,
logger: logger,
}
return router
}
func (router GrafanaRouterImpl) initGrafanaRouter(grafanaRouter *mux.Router) {
grafanaRouter.PathPrefix("").HandlerFunc(router.grafanaProxy)
}