Skip to content
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

Add workaround to ZT systems rate limit bug. #192

Merged
merged 1 commit into from
Aug 20, 2022
Merged
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
34 changes: 32 additions & 2 deletions oem/zt/eventservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package zt
import (
"encoding/json"
"fmt"
"log"
"net/http"
"time"

"github.com/stmcginnis/gofish/common"
"github.com/stmcginnis/gofish/redfish"
Expand Down Expand Up @@ -80,15 +82,43 @@ func (eventservice *EventService) Subscribe(eventsReceiverURL string, protocol r
}

// SubmitTestEvent sends event according to msgId and returns error.
// ZT systems redfish current firmware limits the SubmitTestEvent() request rate.
// The first request will be OK, but if another request is sent with-in 5-15 sec, it will get a 400 error response.
// This issue is reported at https://bugzilla.redhat.com/show_bug.cgi?id=2094842
// To work around this limit, we retry sending the request until we get a good response.
func (eventservice *EventService) SubmitTestEvent(msgID string) error {
const (
retryInterval = 5 * time.Second
retryAttempts = 6
retryReportThreshold = 2
)
var err error
var resp *http.Response

p := eventPayload{
MessageID: msgID,
}

resp, err := eventservice.Client.Post(eventservice.SubmitTestEventTarget, p)
for retryCounter := 0; retryCounter < retryAttempts; retryCounter++ {
resp, err = eventservice.Client.Post(eventservice.SubmitTestEventTarget, p)
if err == nil {
if retryCounter > retryReportThreshold {
log.Printf("Had to retry %v times to send SubmitTestEvent()", retryCounter)
}

break
}

if resp != nil {
_ = resp.Body.Close()
}

time.Sleep(retryInterval)
}
if err != nil {
return fmt.Errorf("failed to send submitTestEvent in SubmitTestEvent() due to: %w", err)
return err
}

defer resp.Body.Close()

valid := map[int]bool{http.StatusAccepted: true}
Expand Down