Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ var (
- format: epochany
pattern: |
/Date\((\d+)\)

# Example: time="2025-02-12T18:12:58.715528Z"
# Source: argocd
- format: rfc3339
pattern: |
time="([^"]+)"
`

windowConfig = `window: %s`
Expand Down
19 changes: 15 additions & 4 deletions internal/pkg/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ const (
prequelRulesSha256Suffix = ".sha2"
prequelRulesSigSuffix = ".sig"
tmpDirPrefix = "preq-update"
defaultLocalCheckDur = 24 * time.Hour * 2 // 2 days
defaultLocalCheckDur = 24 * time.Hour * 1 // 1 day
)

const (
retries = uint(1)
rulesFilenameFmt = prefix.PrequelPublicRulesPrefix + "%s" + prequelRulesSuffix
fastCheckTimeout = 100 * time.Millisecond
fastCheckTimeout = 150 * time.Millisecond
slowCheckTimeout = 300 * time.Millisecond
noRulesTimeout = 5 * time.Second
downloadTimeout = 30 * time.Second
)

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

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

// If we don't have any rules installed, then bump the timeout and force a full checkin
if currRulesPath == "" {
timeout = noRulesTimeout
localCheckUpdate = true
log.Warn().
Str("timeout", timeout.String()).
Msg("No rules installed yet. Increasing timeout and forcing a full checkin")
}

// If we don't need to do a full check in, do a fast one (~30ms)
if !localCheckUpdate {
if tinyResp, err = fastUpdateSync(ctx, fmt.Sprintf("%s:%d", udpBaseAddr, udpPort), fastCheckTimeout); err != nil {
return currRulesPath, err
}
} else {
// Otherwise, do a full check in (~130ms). Uses slowCheckTimeout
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, slowCheckTimeout); err != nil {
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, timeout); err != nil {
return currRulesPath, err
}
}
Expand All @@ -181,7 +192,7 @@ func syncUpdates(ctx context.Context, conf *config.Config, configDir, token, upd
// Ok, we need to do one or more updates. But we don't know if we have a full response.
if fullResp == nil {
// Otherwise, do a full check in (~130ms). Uses slowCheckTimeout
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, slowCheckTimeout); err != nil {
if fullResp, err = checkin(ctx, apiUrl, token, currRulesVer, timeout); err != nil {
return currRulesPath, err
}
}
Expand Down