Skip to content

Commit 18d0aaa

Browse files
fix: fatal log removed (#5043)
* log.Fatal Removed * code review comments incorporated * code review comments incorporated * code review comments incorporated * code review comments incorporated * code review comments incorporated * common lib updated * fix * fix * fix * wire file written * code review comments incorporated * code review comments incorporated * code review comments incorporated - error handled * code review comments incorporated - error handled * merged main * code refactored
1 parent 5a75ad9 commit 18d0aaa

File tree

57 files changed

+954
-1745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+954
-1745
lines changed

api/router/GrafanaRouter.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type GrafanaRouterImpl struct {
1919
grafanaProxy func(writer http.ResponseWriter, request *http.Request)
2020
}
2121

22-
func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config) *GrafanaRouterImpl {
22+
func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config) (*GrafanaRouterImpl, error) {
2323
client := &http.Client{
2424
Transport: &http.Transport{
2525
Proxy: http.ProxyFromEnvironment,
@@ -31,12 +31,15 @@ func NewGrafanaRouterImpl(logger *zap.SugaredLogger, grafanaCfg *grafana.Config)
3131
ExpectContinueTimeout: 1 * time.Second,
3232
},
3333
}
34-
grafanaProxy := grafana.NewGrafanaHTTPReverseProxy(fmt.Sprintf("http://%s:%s", grafanaCfg.Host, grafanaCfg.Port), client.Transport)
34+
grafanaProxy, err := grafana.NewGrafanaHTTPReverseProxy(fmt.Sprintf("http://%s:%s", grafanaCfg.Host, grafanaCfg.Port), client.Transport)
35+
if err != nil {
36+
return nil, err
37+
}
3538
router := &GrafanaRouterImpl{
3639
grafanaProxy: grafanaProxy,
3740
logger: logger,
3841
}
39-
return router
42+
return router, nil
4043
}
4144

4245
func (router GrafanaRouterImpl) initGrafanaRouter(grafanaRouter *mux.Router) {

client/argocdServer/connection/Tls.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func GetTLS(cert *tls.Certificate) credentials.TransportCredentials {
3232
//These certificates are to be read from secret create by argocd
3333
//cert, err := tls.X509KeyPair([]byte(TLSCert), []byte(TLSKey))
3434
//if err != nil {
35-
// log.Fatal(err)
3635
//}
3736
certPool := x509.NewCertPool()
3837
pemCertBytes, _ := EncodeX509KeyPair(*cert)

client/argocdServer/connection/proxy.go

Lines changed: 0 additions & 195 deletions
This file was deleted.

client/argocdServer/connection/proxy_test.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

client/dashboard/DashboardRouter.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type DashboardRouterImpl struct {
2020
dashboardProxy func(writer http.ResponseWriter, request *http.Request)
2121
}
2222

23-
func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *Config) *DashboardRouterImpl {
23+
func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *Config) (*DashboardRouterImpl, error) {
2424
client := &http.Client{
2525
Transport: &http.Transport{
2626
Proxy: http.ProxyFromEnvironment,
@@ -32,12 +32,15 @@ func NewDashboardRouterImpl(logger *zap.SugaredLogger, dashboardCfg *Config) *Da
3232
ExpectContinueTimeout: 1 * time.Second,
3333
},
3434
}
35-
dashboardProxy := proxy.NewDashboardHTTPReverseProxy(fmt.Sprintf("http://%s:%s", dashboardCfg.Host, dashboardCfg.Port), client.Transport)
35+
dashboardProxy, err := proxy.NewDashboardHTTPReverseProxy(fmt.Sprintf("http://%s:%s", dashboardCfg.Host, dashboardCfg.Port), client.Transport)
36+
if err != nil {
37+
return nil, err
38+
}
3639
router := &DashboardRouterImpl{
3740
dashboardProxy: dashboardProxy,
3841
logger: logger,
3942
}
40-
return router
43+
return router, nil
4144
}
4245

4346
func (router DashboardRouterImpl) InitDashboardRouter(dashboardRouter *mux.Router) {

client/grafana/proxy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import (
77
"net/url"
88
)
99

10-
func NewGrafanaHTTPReverseProxy(serverAddr string, transport http.RoundTripper) func(writer http.ResponseWriter, request *http.Request) {
10+
func NewGrafanaHTTPReverseProxy(serverAddr string, transport http.RoundTripper) (func(writer http.ResponseWriter, request *http.Request), error) {
1111
target, err := url.Parse(serverAddr)
1212
if err != nil {
13-
log.Fatal(err)
13+
log.Println(err)
14+
return nil, err
1415
}
1516
proxy := httputil.NewSingleHostReverseProxy(target)
1617
proxy.Transport = transport
1718

1819
return func(w http.ResponseWriter, r *http.Request) {
1920
proxy.ServeHTTP(w, r)
20-
}
21+
}, nil
2122
}

client/proxy/Proxy.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ import (
1414
const Dashboard = "dashboard"
1515
const Proxy = "proxy"
1616

17-
func NewDashboardHTTPReverseProxy(serverAddr string, transport http.RoundTripper) func(writer http.ResponseWriter, request *http.Request) {
18-
proxy := GetProxyServer(serverAddr, transport, Dashboard)
17+
func NewDashboardHTTPReverseProxy(serverAddr string, transport http.RoundTripper) (func(writer http.ResponseWriter, request *http.Request), error) {
18+
proxy, err := GetProxyServer(serverAddr, transport, Dashboard)
19+
if err != nil {
20+
return nil, err
21+
}
1922
return func(w http.ResponseWriter, r *http.Request) {
2023
proxy.ServeHTTP(w, r)
21-
}
24+
}, nil
2225
}
2326

24-
func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclude string) *httputil.ReverseProxy {
27+
func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclude string) (*httputil.ReverseProxy, error) {
2528
target, err := url.Parse(serverAddr)
2629
if err != nil {
27-
log.Fatal(err)
30+
log.Println(err)
31+
return nil, err
2832
}
2933
proxy := httputil.NewSingleHostReverseProxy(target)
3034
proxy.Transport = transport
@@ -35,7 +39,7 @@ func GetProxyServer(serverAddr string, transport http.RoundTripper, pathToExclud
3539
request.URL.Path = rewriteRequestUrl(path, pathToExclude)
3640
fmt.Printf("%s\n", request.URL.Path)
3741
}
38-
return proxy
42+
return proxy, nil
3943
}
4044

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

53-
func NewHTTPReverseProxy(serverAddr string, transport http.RoundTripper, enforcer casbin.Enforcer) func(writer http.ResponseWriter, request *http.Request) {
54-
proxy := GetProxyServer(serverAddr, transport, Proxy)
57+
func NewHTTPReverseProxy(serverAddr string, transport http.RoundTripper, enforcer casbin.Enforcer) (func(writer http.ResponseWriter, request *http.Request), error) {
58+
proxy, err := GetProxyServer(serverAddr, transport, Proxy)
59+
if err != nil {
60+
return nil, err
61+
}
5562
return func(w http.ResponseWriter, r *http.Request) {
5663

5764
token := r.Header.Get("token")
@@ -60,5 +67,5 @@ func NewHTTPReverseProxy(serverAddr string, transport http.RoundTripper, enforce
6067
return
6168
}
6269
proxy.ServeHTTP(w, r)
63-
}
70+
}, nil
6471
}

0 commit comments

Comments
 (0)