-
Notifications
You must be signed in to change notification settings - Fork 58
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
buiding a new body for conflict reponses #1068
Changes from 2 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 |
---|---|---|
|
@@ -139,6 +139,23 @@ func fulcioWriteEndpoint(ctx context.Context, priv *ecdsa.PrivateKey) (*x509.Cer | |
return cert[0], nil | ||
} | ||
|
||
func makeRekorRequest(cert *x509.Certificate, priv *ecdsa.PrivateKey, hostPath string) (*http.Response, time.Time, error) { | ||
body, err := rekorEntryRequest(cert, priv) | ||
t := time.Now() | ||
if err != nil { | ||
return nil, t, fmt.Errorf("rekor entry: %w", err) | ||
} | ||
req, err := retryablehttp.NewRequest(http.MethodPost, hostPath, bytes.NewBuffer(body)) | ||
if err != nil { | ||
return nil, t, fmt.Errorf("new request: %w", err) | ||
} | ||
setHeaders(req, "") | ||
|
||
t = time.Now() | ||
resp, err := retryableClient.Do(req) | ||
return resp, t, err | ||
} | ||
|
||
// rekorWriteEndpoint tests the write endpoint for rekor, which is | ||
// /api/v1/log/entries and adds an entry to the log | ||
// if a certificate is provided, the Rekor entry will contain that certificate, | ||
|
@@ -151,24 +168,23 @@ func rekorWriteEndpoint(ctx context.Context, cert *x509.Certificate, priv *ecdsa | |
verificationCounter.With(prometheus.Labels{verifiedLabel: verified}).Inc() | ||
}() | ||
|
||
body, err := rekorEntryRequest(cert, priv) | ||
if err != nil { | ||
return fmt.Errorf("rekor entry: %w", err) | ||
} | ||
req, err := retryablehttp.NewRequest(http.MethodPost, hostPath, bytes.NewBuffer(body)) | ||
if err != nil { | ||
return fmt.Errorf("new request: %w", err) | ||
} | ||
|
||
setHeaders(req, "") | ||
|
||
t := time.Now() | ||
resp, err := retryableClient.Do(req) | ||
latency := time.Since(t).Milliseconds() | ||
resp, t, err := makeRekorRequest(cert, priv, hostPath) | ||
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. Can we move this into the for loop? |
||
if err != nil { | ||
return fmt.Errorf("error adding entry: %w", err) | ||
} | ||
defer resp.Body.Close() | ||
// A new body should be created when it is conflicted | ||
for { | ||
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. Can we put a reasonable limit, let's say 10, on this loop? |
||
if resp.StatusCode != http.StatusConflict { | ||
break | ||
} | ||
resp, t, err = makeRekorRequest(cert, priv, hostPath) | ||
if err != nil { | ||
return fmt.Errorf("error adding entry: %w", err) | ||
} | ||
defer resp.Body.Close() | ||
} | ||
latency := time.Since(t).Milliseconds() | ||
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. Can we record latency and response data for each request to Rekor? This would measure the total time for all requests. 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. You mean we should also record the responses that has |
||
exportDataToPrometheus(resp, rekorURL, endpoint, POST, latency) | ||
|
||
if resp.StatusCode != http.StatusCreated { | ||
|
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.
I'd suggest returning the latency calculation
latency := time.Since(t).Milliseconds()
rather than the time object.