Skip to content

Commit

Permalink
Merge pull request #5977 from mysteriumnetwork/add-quality-cache
Browse files Browse the repository at this point in the history
Cache quality errors too and increase timeout
  • Loading branch information
soffokl authored Feb 20, 2024
2 parents b1b6e97 + b7a6fa1 commit 42d17fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmd/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ package cmd
import (
"fmt"
"net"

"github.com/mysteriumnetwork/node/core/monitoring"

"github.com/mysteriumnetwork/node/core/policy"
"github.com/mysteriumnetwork/node/core/policy/localcopy"

"net/http"
"net/url"
"path/filepath"
Expand All @@ -49,8 +43,11 @@ import (
"github.com/mysteriumnetwork/node/core/discovery/proposal"
"github.com/mysteriumnetwork/node/core/ip"
"github.com/mysteriumnetwork/node/core/location"
"github.com/mysteriumnetwork/node/core/monitoring"
"github.com/mysteriumnetwork/node/core/node"
nodevent "github.com/mysteriumnetwork/node/core/node/event"
"github.com/mysteriumnetwork/node/core/policy"
"github.com/mysteriumnetwork/node/core/policy/localcopy"
"github.com/mysteriumnetwork/node/core/port"
"github.com/mysteriumnetwork/node/core/quality"
"github.com/mysteriumnetwork/node/core/service"
Expand Down Expand Up @@ -892,7 +889,7 @@ func (di *Dependencies) bootstrapQualityComponents(options node.OptionsQuality)
}

di.QualityClient = quality.NewMorqaClient(
requests.NewHTTPClientWithTransport(di.HTTPTransport, 10*time.Second),
requests.NewHTTPClientWithTransport(di.HTTPTransport, 60*time.Second),
options.Address,
di.SignerFactory,
)
Expand Down
6 changes: 6 additions & 0 deletions core/quality/mysterium_morqa.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ func (m *MysteriumMORQA) newRequestBinary(method, path string, payload proto.Mes
}

func (m *MysteriumMORQA) doRequestAndCacheResponse(request *http.Request, ttl time.Duration, dto interface{}) error {
if err, ok := m.cache.Get("err" + request.URL.RequestURI()); ok {
return err.(error)
}

if resp, ok := m.cache.Get(request.URL.RequestURI()); ok {
serializedDTO, err := json.Marshal(resp)
if err != nil {
Expand All @@ -539,13 +543,15 @@ func (m *MysteriumMORQA) doRequestAndCacheResponse(request *http.Request, ttl ti

response, err := m.client.Do(request)
if err != nil {
m.cache.Set("err"+request.URL.RequestURI(), err, ttl)
log.Warn().Err(err).Msg("Failed to request proposals quality")

return nil
}
defer response.Body.Close()

if err := parseResponseJSON(response, dto); err != nil {
m.cache.Set("err"+request.URL.RequestURI(), err, ttl)
return err
}

Expand Down

0 comments on commit 42d17fd

Please sign in to comment.