Skip to content

Commit

Permalink
fix(provider): provider fixes from v0.14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrogen18 authored Oct 7, 2021
1 parent cbd9452 commit eaac1b8
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 77 deletions.
16 changes: 16 additions & 0 deletions provider/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const (
FlagMinimumBalance = "minimum-balance"
FlagBalanceCheckPeriod = "balance-check-period"
FlagProviderConfig = "provider-config"
FlagCachedResultMaxAge = "cached-result-max-age"
FlagRPCQueryTimeout = "rpc-query-timeout"
)

var (
Expand Down Expand Up @@ -285,6 +287,16 @@ func RunCmd() *cobra.Command {
return nil
}

cmd.Flags().Duration(FlagRPCQueryTimeout, time.Minute, "timeout for requests made to the RPC node")
if err := viper.BindPFlag(FlagRPCQueryTimeout, cmd.Flags().Lookup(FlagRPCQueryTimeout)); err != nil {
return nil
}

cmd.Flags().Duration(FlagCachedResultMaxAge, 5*time.Second, "max. cache age for results from the RPC node")
if err := viper.BindPFlag(FlagCachedResultMaxAge, cmd.Flags().Lookup(FlagCachedResultMaxAge)); err != nil {
return nil
}

return cmd
}

Expand Down Expand Up @@ -378,6 +390,8 @@ func doRunCmd(ctx context.Context, cmd *cobra.Command, _ []string) error {
manifestTimeout := viper.GetDuration(FlagManifestTimeout)
metricsListener := viper.GetString(FlagMetricsListener)
providerConfig := viper.GetString(FlagProviderConfig)
cachedResultMaxAge := viper.GetDuration(FlagCachedResultMaxAge)
rpcQueryTimeout := viper.GetDuration(FlagRPCQueryTimeout)

var metricsRouter http.Handler
if len(metricsListener) != 0 {
Expand Down Expand Up @@ -552,6 +566,8 @@ func doRunCmd(ctx context.Context, cmd *cobra.Command, _ []string) error {
return err
}
config.BidDeposit = bidDeposit
config.RPCQueryTimeout = rpcQueryTimeout
config.CachedResultMaxAge = cachedResultMaxAge

service, err := provider.NewService(ctx, cctx, info.GetAddress(), session, bus, cclient, config)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Config struct {
DeploymentIngressStaticHosts bool
DeploymentIngressDomain string
ClusterSettings map[interface{}]interface{}
RPCQueryTimeout time.Duration
CachedResultMaxAge time.Duration
}

func NewDefaultConfig() Config {
Expand Down
8 changes: 6 additions & 2 deletions provider/gateway/rest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
// errors from private use staring
websocketInternalServerErrorCode = 4000
websocketLeaseNotFound = 4001
manifestSubmitTimeout = 120 * time.Second
)

type wsStreamConfig struct {
Expand Down Expand Up @@ -383,7 +384,7 @@ func validateHandler(log log.Logger, cl provider.ValidateClient) http.HandlerFun
}
}

func createManifestHandler(_ log.Logger, mclient pmanifest.Client) http.HandlerFunc {
func createManifestHandler(log log.Logger, mclient pmanifest.Client) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
var mani manifest.Manifest
decoder := json.NewDecoder(req.Body)
Expand All @@ -396,7 +397,9 @@ func createManifestHandler(_ log.Logger, mclient pmanifest.Client) http.HandlerF
return
}

if err := mclient.Submit(req.Context(), requestDeploymentID(req), mani); err != nil {
subctx, cancel := context.WithTimeout(req.Context(), manifestSubmitTimeout)
defer cancel()
if err := mclient.Submit(subctx, requestDeploymentID(req), mani); err != nil {
if errors.Is(err, manifestValidation.ErrInvalidManifest) {
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
Expand All @@ -405,6 +408,7 @@ func createManifestHandler(_ log.Logger, mclient pmanifest.Client) http.HandlerF
http.Error(w, err.Error(), http.StatusNotFound)
return
}
log.Error("manifest submit failed", "err", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Expand Down
2 changes: 2 additions & 0 deletions provider/manifest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import "time"
type ServiceConfig struct {
HTTPServicesRequireAtLeastOneHost bool
ManifestTimeout time.Duration
RPCQueryTimeout time.Duration
CachedResultMaxAge time.Duration
}
Loading

0 comments on commit eaac1b8

Please sign in to comment.