Skip to content

Commit 56e1d89

Browse files
authored
Add timeout adjustments (#44)
* Add timeout adjustments * Revert fast timeout check * Revert slow timeout --------- Co-authored-by: Tony Meehan <tonymeehan@users.noreply.github.com>
1 parent e2af5d6 commit 56e1d89

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

internal/pkg/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ var (
164164
- format: epochany
165165
pattern: |
166166
/Date\((\d+)\)
167+
168+
# Example: time="2025-02-12T18:12:58.715528Z"
169+
# Source: argocd
170+
- format: rfc3339
171+
pattern: |
172+
time="([^"]+)"
167173
`
168174

169175
windowConfig = `window: %s`

internal/pkg/rules/rules.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ const (
3939
prequelRulesSha256Suffix = ".sha2"
4040
prequelRulesSigSuffix = ".sig"
4141
tmpDirPrefix = "preq-update"
42-
defaultLocalCheckDur = 24 * time.Hour * 2 // 2 days
42+
defaultLocalCheckDur = 24 * time.Hour * 1 // 1 day
4343
)
4444

4545
const (
4646
retries = uint(1)
4747
rulesFilenameFmt = prefix.PrequelPublicRulesPrefix + "%s" + prequelRulesSuffix
48-
fastCheckTimeout = 100 * time.Millisecond
48+
fastCheckTimeout = 150 * time.Millisecond
4949
slowCheckTimeout = 300 * time.Millisecond
50+
noRulesTimeout = 5 * time.Second
5051
downloadTimeout = 30 * time.Second
5152
)
5253

@@ -145,6 +146,7 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
145146
currRulesPath string
146147
apiUrl = fmt.Sprintf("https://%s:%d", baseAddr, tlsPort)
147148
dur = defaultLocalCheckDur
149+
timeout = slowCheckTimeout
148150
err error
149151
)
150152

@@ -164,14 +166,23 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
164166
return currRulesPath, err
165167
}
166168

169+
// If we don't have any rules installed, then bump the timeout and force a full checkin
170+
if currRulesPath == "" {
171+
timeout = noRulesTimeout
172+
localCheckUpdate = true
173+
log.Warn().
174+
Str("timeout", timeout.String()).
175+
Msg("No rules installed yet. Increasing timeout and forcing a full checkin")
176+
}
177+
167178
// If we don't need to do a full check in, do a fast one (~30ms)
168179
if !localCheckUpdate {
169180
if tinyResp, err = fastUpdateSync(ctx, fmt.Sprintf("%s:%d", udpBaseAddr, udpPort), fastCheckTimeout); err != nil {
170181
return currRulesPath, err
171182
}
172183
} else {
173184
// Otherwise, do a full check in (~130ms). Uses slowCheckTimeout
174-
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, slowCheckTimeout); err != nil {
185+
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, timeout); err != nil {
175186
return currRulesPath, err
176187
}
177188
}
@@ -181,7 +192,7 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
181192
// Ok, we need to do one or more updates. But we don't know if we have a full response.
182193
if fullResp == nil {
183194
// Otherwise, do a full check in (~130ms). Uses slowCheckTimeout
184-
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, slowCheckTimeout); err != nil {
195+
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, timeout); err != nil {
185196
return currRulesPath, err
186197
}
187198
}

0 commit comments

Comments
 (0)