Skip to content

ocdav makes download requests using the proxy, not the datagateway directly #6296

Open

Description

@butonic

The ocdav service currently sends PUT and TUS requests for uploads to the proxy again instead of directly going to the dataprovider ... or datagateway.

image

While this does not look too bad for small files, we are paying a latency cost for two extra network hops as well as having to copy the byte stream twice.

We could send it to a datagateway, which in ocis runs as part of the frontend, so it would be sth like:

+       // FIXME the gateway returns the frontend URL ... but we don't want to go through the proxy again ...
+       // the jwt token contains the actual target, go there directly
+       reg := registry.GetRegistry()
+       sel := selector.NewSelector(selector.Registry(reg))
+       // select next datagateway node
+       next, err := sel.Select("com.owncloud.web.frontend")
+       if err != nil {
+               log.Error().Err(err).Msg("error selecting datagateway service")
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+       node, err := next()
+       if err != nil {
+               log.Error().Err(err).Msg("error selecting next node")
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       epURL, err := url.Parse(ep)
+       if err != nil {
+               log.Error().Err(err).Msg("could not parse endpoint")
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       // replace frontend endpoint with internal address
+       epURL.Host = node.Address
+       // we may need a protocol switch
+       if node.Metadata["protocol"] != "" {
+               epURL.Scheme = node.Metadata["protocol"]
+       }
+       epURL.Path = "/data" // overwrite path, we know the datagateway uses the /data endpoint
+       ep = epURL.String()
+
        httpReq, err := rhttp.NewRequest(ctx, http.MethodPut, ep, r.Body)
        if err != nil {
                w.WriteHeader(http.StatusInternalServerError)
                return
        }
+       Propagator.Inject(ctx, propagation.HeaderCarrier(httpReq.Header))
        httpReq.Header.Set(datagateway.TokenTransportHeader, token)
 
        httpRes, err := s.client.Do(httpReq)

but this requires importing the ocis registry into reva ...

It should just send the request directly to the correct dataprovider ...

  • we could unpack the token, but it requires parsing the JWT transfertoken ... for that we would have to know the transfertokensecret
  • we could return an internal endpoint? but we don't really want to expose that ...

I prefer making parsing the transfer token optional. If it is set the ocdav service should parse it and directly talk to the correct dataprovider, skipping the proxy and the datagateway.

Activity

  1. YDKK commented on Jan 19, 2025

    @YDKK

    Is there an update to this issue?

    When hosting oCIS through cloudflared, I am seeing an increase in cloudflared CPU usage and request size limits when copying files in the web UI.

    I think this issue is related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions