Skip to content
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

Reworking the datasource format #84

Merged
merged 18 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
fix review
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
  • Loading branch information
Nexucis committed Sep 26, 2021
commit b326e93ad7df237cc1fec47dad3a91c6692f133a
9 changes: 5 additions & 4 deletions internal/api/core/middleware/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func getGlobalDatasourceAndPath(dao globaldatasource.DAO, requestPath string) (v
if err != nil {
if etcd.IsKeyNotFound(err) {
logrus.Debugf("unable to find the Datasource '%s'", datasourceName)
return nil, "", echo.NewHTTPError(http.StatusBadGateway, fmt.Sprintf("unable to forward the request to the datasource '%s', datasource doesn't exist", datasourceName))
return nil, "", echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("unable to forward the request to the datasource '%s', datasource doesn't exist", datasourceName))
}
logrus.WithError(err).Errorf("unable to find the datasource '%s', something wrong with the database", datasourceName)
return nil, "", echo.NewHTTPError(http.StatusInternalServerError, "internal server error")
Expand All @@ -107,7 +107,7 @@ func getLocalDatasourceAndPath(dao datasource.DAO, requestPath string) (v1.Datas
if err != nil {
if etcd.IsKeyNotFound(err) {
logrus.Debugf("unable to find the Datasource '%s' in project '%s'", datasourceName, projectName)
return nil, "", echo.NewHTTPError(http.StatusBadGateway, fmt.Sprintf("unable to forward the request to the datasource '%s', datasource doesn't exist", datasourceName))
return nil, "", echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("unable to forward the request to the datasource '%s', datasource doesn't exist", datasourceName))
}
logrus.WithError(err).Errorf("unable to find the datasource '%s', something wrong with the database", datasourceName)
return nil, "", echo.NewHTTPError(http.StatusInternalServerError, "internal server error")
Expand All @@ -134,6 +134,8 @@ func newProxy(spec v1.DatasourceSpec, path string) (proxy, error) {
}
}

// TODO take in consideration the `HTTPAllowedEndpoint`

type httpProxy struct {
config datasourcev1.HTTPConfig
path string
Expand All @@ -155,8 +157,7 @@ func (h *httpProxy) serve(c echo.Context) error {
reverseProxy := httputil.NewSingleHostReverseProxy(h.config.URL)
reverseProxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, err error) {
desc := h.config.URL.String()
proxyErr = fmt.Errorf("error proxying, remote unreachable: target=%s, err=%w", desc, err)
logrus.Errorf(proxyErr.Error())
logrus.WithError(err).Errorf("error proxying, remote unreachable: target=%s, err=%v", desc, err)
proxyErr = err
Copy link

@robskillington robskillington Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm this seems to clobber the definition proxyErr assignment on line 158?

Perhaps use a different variable if you want to retain the error, i.e.

logrus.WithError(err).Errorf("error proxying, remote unreachable: target=%s, err=%w", desc, err)
proxyErr = err

or just

proxyErr = fmt.Errorf("error proxying, remote unreachable: target=%s, err=%w", desc, err)
logrus.Errorf(proxyErr.Error())

}
// use a dedicated HTTP transport to avoid any TLS encryption issues
Expand Down
1 change: 1 addition & 0 deletions pkg/model/api/v1/datasource/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var defaultPrometheusAllowedEndpoints = []HTTPAllowedEndpoint{
Endpoint: "/api/v1/query_range",
Method: http.MethodPost,
},
// TODO manage variable in endpoint
}

type Prometheus struct {
Expand Down