Repository navigation
feat: add simple retries for status requests #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ package db | |
| import ( | ||
| "bufio" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "regexp" | ||
| "strconv" | ||
|
|
@@ -100,7 +101,18 @@ func getFdb() fdb.Database { | |
| return db | ||
| } | ||
|
|
||
| func GetStatus() (*models.FullStatus, error) { | ||
| func IsStatusIncomplete(status *models.FullStatus) bool { | ||
| if status.Cluster == nil || | ||
| status.Cluster.DatabaseLockState == nil || | ||
| status.Cluster.FaultTolerance == nil || | ||
| status.Cluster.Data == nil || | ||
| status.Cluster.DatabaseAvailable == false { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func getStatusOnce() (*models.FullStatus, error) { | ||
| start := time.Now() | ||
| conn := getFdb() | ||
| var status models.FullStatus | ||
|
|
@@ -122,11 +134,7 @@ func GetStatus() (*models.FullStatus, error) { | |
| } | ||
|
|
||
| if os.Getenv("DEBUG_LOG_INCOMPLETE_STATUS") == "true" { | ||
| if status.Cluster == nil || | ||
| status.Cluster.DatabaseLockState == nil || | ||
| status.Cluster.FaultTolerance == nil || | ||
| status.Cluster.Data == nil || | ||
| status.Cluster.DatabaseAvailable == false { | ||
| if IsStatusIncomplete(&status) { | ||
| statusString := string(statusJson.([]byte)) | ||
| log.Debug().Str("status_json", statusString).Msg("status json is missing cluster fields") | ||
|
|
||
|
|
@@ -135,13 +143,25 @@ func GetStatus() (*models.FullStatus, error) { | |
| Dur("took", d). | ||
| Str("status_json", statusString). | ||
| Msg("status json is missing cluster fields") | ||
|
|
||
| return nil, fmt.Errorf("incomplete status") | ||
|
||
| } | ||
| } | ||
|
|
||
| return &status, nil | ||
| } | ||
|
|
||
| func GetStatus() (*models.FullStatus, error) { | ||
| status, err := getStatusOnce() | ||
| if err != nil { | ||
| log.Error().Err(err).Msg("failed to get status, retrying") | ||
| time.Sleep(1 * time.Second) | ||
|
||
| status, err = getStatusOnce() | ||
| if err != nil { | ||
| log.Error().Err(err).Msg("failed to get status, retry failed") | ||
| } | ||
| } | ||
| return status, err | ||
| } | ||
|
Comment on lines
+152
to
+163
|
||
|
|
||
| func isTLSmode(c *string) bool { | ||
| // Find if must run in TLS mode | ||
| file, err := os.Open(*c) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -54,10 +54,8 @@ func (m *MetricProvider) Close() { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Periodic data collection, called from main in a goroutine | ||||||
| func (mp *MetricProvider) Collect() { | ||||||
| // TODO make this configurable | ||||||
| interval := 10 * time.Second | ||||||
| interval := 4 * time.Second | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: collection interval reduced from 10s to 4s - combined with the 1s retry delay in
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: metrics/metric_provider.go
Line: 58:58
Comment:
**style:** collection interval reduced from 10s to 4s - combined with the 1s retry delay in `GetStatus()`, overlapping collection attempts could occur if status requests consistently take >4s
```suggestion
interval := 6 * time.Second
```
How can I resolve this? If you propose a fix, please make it concise.
|
||||||
| ticker := time.NewTicker(interval) | ||||||
|
|
||||||
| if err := mp.reporter.collectOnce(); err != nil { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: incomplete status now returns error when
DEBUG_LOG_INCOMPLETE_STATUSis set, which triggers retry - verify this behavior change is intentional since previously it would return the incomplete status without error. was the previous behavior (returning incomplete status without error) a bug, or is this new retry behavior a breaking change?Prompt To Fix With AI