Skip to content

Commit d31b2df

Browse files
committed
Added a generic file timeout
1 parent 84b2310 commit d31b2df

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

internal/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,11 @@ func registerClientFlags(fs *flag.FlagSet) {
648648
DefMaxFileSize,
649649
"Max file size in bytes.",
650650
)
651+
fs.Duration(
652+
ClientFileDownloadTimeoutKey,
653+
DefClientFileDownloadTimeout,
654+
"Timeout value in seconds, to downloading file for config apply.",
655+
)
651656
}
652657

653658
func registerCommandFlags(fs *flag.FlagSet) {
@@ -1133,6 +1138,7 @@ func resolveClient() *Client {
11331138
RandomizationFactor: viperInstance.GetFloat64(ClientBackoffRandomizationFactorKey),
11341139
Multiplier: viperInstance.GetFloat64(ClientBackoffMultiplierKey),
11351140
},
1141+
FileDownloadTimeout: viperInstance.GetDuration(ClientFileDownloadTimeoutKey),
11361142
}
11371143
}
11381144

internal/config/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const (
8181
DefBackoffMaxInterval = 20 * time.Second
8282
DefBackoffMaxElapsedTime = 1 * time.Minute
8383

84+
DefClientFileDownloadTimeout = 60 * time.Second
85+
8486
// Watcher defaults
8587
DefInstanceWatcherMonitoringFrequency = 5 * time.Second
8688
DefInstanceHealthWatcherMonitoringFrequency = 5 * time.Second

internal/config/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
ClientBackoffMaxElapsedTimeKey = pre(ClientRootKey) + "backoff_max_elapsed_time"
4848
ClientBackoffRandomizationFactorKey = pre(ClientRootKey) + "backoff_randomization_factor"
4949
ClientBackoffMultiplierKey = pre(ClientRootKey) + "backoff_multiplier"
50+
ClientFileDownloadTimeoutKey = pre(ClientRootKey) + "file_download_timeout"
5051

5152
CollectorConfigPathKey = pre(CollectorRootKey) + "config_path"
5253
CollectorAdditionalConfigPathsKey = pre(CollectorRootKey) + "additional_config_paths"

internal/config/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ type (
7575
}
7676

7777
Client struct {
78-
HTTP *HTTP `yaml:"http" mapstructure:"http"`
79-
Grpc *GRPC `yaml:"grpc" mapstructure:"grpc"`
80-
Backoff *BackOff `yaml:"backoff" mapstructure:"backoff"`
78+
HTTP *HTTP `yaml:"http" mapstructure:"http"`
79+
Grpc *GRPC `yaml:"grpc" mapstructure:"grpc"`
80+
Backoff *BackOff `yaml:"backoff" mapstructure:"backoff"`
81+
FileDownloadTimeout time.Duration `yaml:"file_download_timeout" mapstructure:"file_download_timeout"`
8182
}
8283

8384
HTTP struct {

internal/file/file_manager_service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"strconv"
2121
"strings"
2222
"sync"
23-
"time"
2423

2524
"google.golang.org/grpc"
2625

@@ -44,8 +43,6 @@ const (
4443
executePerm = 0o111
4544
)
4645

47-
const fileDownloadTimeout = 60 * time.Second
48-
4946
type DownloadHeaders struct {
5047
ETag string
5148
LastModified string
@@ -961,7 +958,7 @@ func (fms *FileManagerService) setupHTTPClient(ctx context.Context, proxyURLStri
961958

962959
httpClient := &http.Client{
963960
Transport: transport,
964-
Timeout: fileDownloadTimeout,
961+
Timeout: fms.agentConfig.Client.FileDownloadTimeout,
965962
}
966963

967964
return httpClient, nil

0 commit comments

Comments
 (0)