Skip to content

Commit 8f80d90

Browse files
authored
feat: allow timeout to be configurable (#16)
1 parent 406fa58 commit 8f80d90

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ For a complete list of variables check the section below.
2929
| `PYROSCOPE_AUTH_TOKEN` | `""` | authorization key (token authentication) |
3030
| `PYROSCOPE_SELF_PROFILING` | `false` | whether to profile the extension itself or not |
3131
| `PYROSCOPE_LOG_LEVEL` | `info` | `error` or `info` or `debug` or `trace` |
32+
| `PYROSCOPE_TIMEOUT` | `10s` | http client timeout ([go duration format](https://pkg.go.dev/time#Duration)) |
3233

3334
# How it works
3435
The profiler will run as normal, and periodically will send data to the relay server (the server running at `http://localhost:4040`).

main.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111
"strconv"
1212
"syscall"
13+
"time"
1314

1415
"github.com/pyroscope-io/pyroscope-lambda-extension/extension"
1516
"github.com/pyroscope-io/pyroscope-lambda-extension/relay"
@@ -31,6 +32,7 @@ var (
3132
remoteAddress = getEnvStrOr("PYROSCOPE_REMOTE_ADDRESS", "https://ingest.pyroscope.cloud")
3233

3334
authToken = getEnvStrOr("PYROSCOPE_AUTH_TOKEN", "")
35+
timeout = getEnvDurationOr("PYROSCOPE_TIMEOUT", time.Second*10)
3436

3537
// profile the extension?
3638
selfProfiling = getEnvBool("PYROSCOPE_SELF_PROFILING")
@@ -41,7 +43,7 @@ func main() {
4143
ctx, cancel := context.WithCancel(context.Background())
4244

4345
// Init components
44-
remoteClient := relay.NewRemoteClient(logger, &relay.RemoteClientCfg{Address: remoteAddress, AuthToken: authToken})
46+
remoteClient := relay.NewRemoteClient(logger, &relay.RemoteClientCfg{Address: remoteAddress, AuthToken: authToken, Timeout: timeout})
4547
// TODO(eh-am): a find a better default for num of workers
4648
queue := relay.NewRemoteQueue(logger, &relay.RemoteQueueCfg{NumWorkers: 4}, remoteClient)
4749
ctrl := relay.NewController(logger, queue)
@@ -168,3 +170,19 @@ func getEnvBool(key string) bool {
168170

169171
return v
170172
}
173+
174+
func getEnvDurationOr(key string, fallback time.Duration) time.Duration {
175+
k, ok := os.LookupEnv(key)
176+
177+
// has an explicit value
178+
if ok && k != "" {
179+
dur, err := time.ParseDuration(k)
180+
if err != nil {
181+
return fallback
182+
}
183+
184+
return dur
185+
}
186+
187+
return fallback
188+
}

relay/client.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func NewRemoteClient(log *logrus.Entry, config *RemoteClientCfg) *RemoteClient {
3838
return &RemoteClient{
3939
log: log,
4040
config: config,
41-
// TODO(eh-am): improve this client with timeouts and whatnot
4241
client: &http.Client{
4342
Timeout: timeout,
4443
},

0 commit comments

Comments
 (0)