diff --git a/console/config.go b/console/config.go index af6d4f05..5cc8a718 100644 --- a/console/config.go +++ b/console/config.go @@ -2,8 +2,6 @@ package console // Configuration describes the configuration for the console component. type Configuration struct { - // GrafanaURL is the URL to acess Grafana. - GrafanaURL string // ServeLiveFS serve files from the filesystem instead of the embedded versions. ServeLiveFS bool } diff --git a/console/root.go b/console/root.go index af475e3d..4aeb0867 100644 --- a/console/root.go +++ b/console/root.go @@ -2,21 +2,15 @@ package console import ( - "fmt" "html/template" "io/fs" - "log" netHTTP "net/http" - "net/http/httputil" - "net/url" "os" "path" "path/filepath" "runtime" "sync" - "github.com/rs/zerolog" - "akvorado/common/http" "akvorado/common/reporter" ) @@ -44,28 +38,6 @@ func New(reporter *reporter.Reporter, config Configuration, dependencies Depende config: config, } - // Grafana proxy - if c.config.GrafanaURL != "" { - // Provide a proxy for Grafana - url, err := url.Parse(config.GrafanaURL) - if err != nil { - return nil, fmt.Errorf("unable to parse Grafana URL %q: %w", config.GrafanaURL, err) - } - proxy := httputil.NewSingleHostReverseProxy(url) - proxy.Transport = &netHTTP.Transport{ - Proxy: nil, // Disable proxy - } - proxy.ErrorLog = log.New(c.r.With(). - Str("proxy", "grafana"). - Str("level", zerolog.LevelWarnValue). - Logger(), "", 0) - proxyHandler := netHTTP.HandlerFunc( - func(w netHTTP.ResponseWriter, r *netHTTP.Request) { - proxy.ServeHTTP(w, r) - }) - c.d.HTTP.AddHandler("/grafana/", proxyHandler) - } - c.d.HTTP.AddHandler("/", netHTTP.HandlerFunc(c.assetsHandlerFunc)) c.d.HTTP.AddHandler("/api/v0/docs/", netHTTP.HandlerFunc(c.docsHandlerFunc)) diff --git a/console/root_test.go b/console/root_test.go deleted file mode 100644 index f749354e..00000000 --- a/console/root_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package console - -import ( - "fmt" - "io/ioutil" - netHTTP "net/http" - "net/http/httptest" - "testing" - - "akvorado/common/helpers" - "akvorado/common/http" - "akvorado/common/reporter" -) - -func TestProxy(t *testing.T) { - // Mock HTTP server - server := httptest.NewServer( - netHTTP.HandlerFunc( - func(w netHTTP.ResponseWriter, r *netHTTP.Request) { - fmt.Fprintf(w, "hello world!") - })) - defer server.Close() - - r := reporter.NewMock(t) - h := http.NewMock(t, r) - _, err := New(r, Configuration{ - GrafanaURL: server.URL, - }, Dependencies{ - HTTP: h, - }) - if err != nil { - t.Fatalf("New() error:\n%+v", err) - } - - // Check the proxy works as expected - resp, err := netHTTP.Get(fmt.Sprintf("http://%s/grafana/test", h.Address)) - if err != nil { - t.Fatalf("GET /grafana/test:\n%+v", err) - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatalf("GET /grafana/test: cannot read body:\n%+v", err) - } - if resp.StatusCode != 200 { - t.Errorf("GET /grafana/test: got status code %d, not 200", resp.StatusCode) - } - if diff := helpers.Diff(string(body), "hello world!"); diff != "" { - t.Errorf("GET /grafana/test (-got, +want):\n%s", diff) - } -}