Skip to content

Commit

Permalink
Set storedRequestTimeoutMillis as cutomizable config variable:stored_…
Browse files Browse the repository at this point in the history
…requests.http.fetcher_timeout
  • Loading branch information
amaurybrisou committed Oct 10, 2020
1 parent c27ec73 commit 080bd03
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ func SetupViper(v *viper.Viper, filename string) {
v.SetDefault("stored_requests.postgres.poll_for_updates.amp_query", "")
v.SetDefault("stored_requests.http.endpoint", "")
v.SetDefault("stored_requests.http.amp_endpoint", "")
v.SetDefault("stored_requests.http.fetcher_timeout", 50)
v.SetDefault("stored_requests.in_memory_cache.type", "none")
v.SetDefault("stored_requests.in_memory_cache.ttl_seconds", 0)
v.SetDefault("stored_requests.in_memory_cache.request_cache_size_bytes", 0)
Expand Down
5 changes: 3 additions & 2 deletions config/stored_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ type FileFetcherConfig struct {

// HTTPFetcherConfig configures a stored_requests/backends/http_fetcher/fetcher.go
type HTTPFetcherConfig struct {
Endpoint string `mapstructure:"endpoint"`
AmpEndpoint string `mapstructure:"amp_endpoint"`
Endpoint string `mapstructure:"endpoint"`
AmpEndpoint string `mapstructure:"amp_endpoint"`
FetcherTimeout uint16 `mapstructure:"request_timeout"`
}

// Migrate combined stored_requests+amp configuration to separate simple config sections
Expand Down
2 changes: 1 addition & 1 deletion endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (deps *endpointDeps) loadRequestJSONForAmp(httpRequest *http.Request) (req
return
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(storedRequestTimeoutMillis)*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration((*deps.cfg).StoredRequests.HTTP.FetcherTimeout)*time.Millisecond)
defer cancel()

storedRequests, _, errs := deps.storedReqFetcher.FetchRequests(ctx, []string{ampID}, nil)
Expand Down
4 changes: 1 addition & 3 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import (
"golang.org/x/net/publicsuffix"
)

const storedRequestTimeoutMillis = 50

var (
dntKey string = http.CanonicalHeaderKey("DNT")
dntDisabled int8 = 0
Expand Down Expand Up @@ -226,7 +224,7 @@ func (deps *endpointDeps) parseRequest(httpRequest *http.Request) (req *openrtb.
}
}

timeout := parseTimeout(requestJson, time.Duration(storedRequestTimeoutMillis)*time.Millisecond)
timeout := parseTimeout(requestJson, time.Duration((*deps.cfg).StoredRequests.HTTP.FetcherTimeout)*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func createImpressionTemplate(imp openrtb.Imp, video *openrtb.Video) openrtb.Imp
}

func (deps *endpointDeps) loadStoredImp(storedImpId string) (openrtb.Imp, []error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(storedRequestTimeoutMillis)*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration((*deps.cfg).StoredRequests.HTTP.FetcherTimeout)*time.Millisecond)
defer cancel()

impr := openrtb.Imp{}
Expand Down

0 comments on commit 080bd03

Please sign in to comment.