Skip to content

fix: fatal log removed #5043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions api/router/GrafanaRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type GrafanaRouterImpl struct {
grafanaProxy func(writer http.ResponseWriter, request *http.Request)
}

func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config) *GrafanaRouterImpl {
func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config) (*GrafanaRouterImpl, error) {
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Expand All @@ -31,12 +31,15 @@ func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config)
ExpectContinueTimeout: 1 * time.Second,
},
}
grafanaProxy := grafana.NewGrafanaHTTPReverseProxy(fmt.Sprintf("http://%s:%s", grafanaCfg.Host, grafanaCfg.Port), client.Transport)
grafanaProxy, err := grafana.NewGrafanaHTTPReverseProxy(fmt.Sprintf("http://%s:%s", grafanaCfg.Host, grafanaCfg.Port), client.Transport)
if err != nil {
return nil, err
}
router := &GrafanaRouterImpl{
grafanaProxy: grafanaProxy,
logger: logger,
}
return router
return router, nil
}

func (router GrafanaRouterImpl) initGrafanaRouter(grafanaRouter *mux.Router) {
Expand Down
1 change: 0 additions & 1 deletion client/argocdServer/connection/Tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func GetTLS(cert *tls.Certificate) credentials.TransportCredentials {
//These certificates are to be read from secret create by argocd
//cert, err := tls.X509KeyPair([]byte(TLSCert), []byte(TLSKey))
//if err != nil {
// log.Fatal(err)
//}
certPool := x509.NewCertPool()
pemCertBytes, _ := EncodeX509KeyPair(*cert)
Expand Down
195 changes: 0 additions & 195 deletions client/argocdServer/connection/proxy.go

This file was deleted.

63 changes: 0 additions & 63 deletions client/argocdServer/connection/proxy_test.go

This file was deleted.

9 changes: 6 additions & 3 deletions client/dashboard/DashboardRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DashboardRouterImpl struct {
dashboardProxy func(writer http.ResponseWriter, request *http.Request)
}

func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *Config) *DashboardRouterImpl {
func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *Config) (*DashboardRouterImpl, error) {
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Expand All @@ -32,12 +32,15 @@ func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *Config) *Da
ExpectContinueTimeout: 1 * time.Second,
},
}
dashboardProxy := proxy.NewDashboardHTTPReverseProxy(fmt.Sprintf("http://%s:%s", dashboardCfg.Host, dashboardCfg.Port), client.Transport)
dashboardProxy, err := proxy.NewDashboardHTTPReverseProxy(fmt.Sprintf("http://%s:%s", dashboardCfg.Host, dashboardCfg.Port), client.Transport)
if err != nil {
return nil, err
}
router := &DashboardRouterImpl{
dashboardProxy: dashboardProxy,
logger: logger,
}
return router
return router, nil
}

func (router DashboardRouterImpl) InitDashboardRouter(dashboardRouter *mux.Router) {
Expand Down
7 changes: 4 additions & 3 deletions client/grafana/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"net/url"
)

func NewGrafanaHTTPReverseProxy(serverAddr string, transport http.RoundTripper) func(writer http.ResponseWriter, request *http.Request) {
func NewGrafanaHTTPReverseProxy(serverAddr string, transport http.RoundTripper) (func(writer http.ResponseWriter, request *http.Request), error) {
target, err := url.Parse(serverAddr)
if err != nil {
log.Fatal(err)
log.Println(err)
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.Transport = transport

return func(w http.ResponseWriter, r *http.Request) {
proxy.ServeHTTP(w, r)
}
}, nil
}
25 changes: 16 additions & 9 deletions client/proxy/Proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ import (
const Dashboard = "dashboard"
const Proxy = "proxy"

func NewDashboardHTTPReverseProxy(serverAddr string, transport http.RoundTripper) func(writer http.ResponseWriter, request *http.Request) {
proxy := GetProxyServer(serverAddr, transport, Dashboard)
func NewDashboardHTTPReverseProxy(serverAddr string, transport http.RoundTripper) (func(writer http.ResponseWriter, request *http.Request), error) {
proxy, err := GetProxyServer(serverAddr, transport, Dashboard)
if err != nil {
return nil, err
}
return func(w http.ResponseWriter, r *http.Request) {
proxy.ServeHTTP(w, r)
}
}, nil
}

func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclude string) *httputil.ReverseProxy {
func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclude string) (*httputil.ReverseProxy, error) {
target, err := url.Parse(serverAddr)
if err != nil {
log.Fatal(err)
log.Println(err)
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.Transport = transport
Expand All @@ -35,7 +39,7 @@ func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclud
request.URL.Path = rewriteRequestUrl(path, pathToExclude)
fmt.Printf("%s\n", request.URL.Path)
}
return proxy
return proxy, nil
}

func rewriteRequestUrl(path string, pathToExclude string) string {
Expand All @@ -50,8 +54,11 @@ func rewriteRequestUrl(path string, pathToExclude string) string {
return strings.Join(finalParts, "/")
}

func NewHTTPReverseProxy(serverAddr string, transport http.RoundTripper, enforcer casbin.Enforcer) func(writer http.ResponseWriter, request *http.Request) {
proxy := GetProxyServer(serverAddr, transport, Proxy)
func NewHTTPReverseProxy(serverAddr string, transport http.RoundTripper, enforcer casbin.Enforcer) (func(writer http.ResponseWriter, request *http.Request), error) {
proxy, err := GetProxyServer(serverAddr, transport, Proxy)
if err != nil {
return nil, err
}
return func(w http.ResponseWriter, r *http.Request) {

token := r.Header.Get("token")
Expand All @@ -60,5 +67,5 @@ func NewHTTPReverseProxy(serverAddr string, transport http.RoundTripper, enforce
return
}
proxy.ServeHTTP(w, r)
}
}, nil
}
Loading
Loading