Skip to content

Commit a1e63e0

Browse files
committed
Log IMDS response full text when status code not in 200 range
1 parent 64b92b3 commit a1e63e0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pkg/ec2metadata/ec2metadata.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,17 @@ func (e *Service) GetRebalanceRecommendationEvent() (rebalanceRec *RebalanceReco
196196
// GetMetadataInfo generic function for retrieving ec2 metadata
197197
func (e *Service) GetMetadataInfo(path string) (info string, err error) {
198198
resp, err := e.Request(path)
199-
if resp != nil && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
200-
return "", fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
201-
}
202-
if err != nil {
199+
if err != nil || resp == nil {
203200
return "", fmt.Errorf("Unable to parse metadata response: %w", err)
204201
}
205202
defer resp.Body.Close()
206203
body, err := ioutil.ReadAll(resp.Body)
207204
if err != nil {
208-
return "", fmt.Errorf("Unable to parse http response: %w", err)
205+
return "", fmt.Errorf("Unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
206+
}
207+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
208+
log.Debug().Msgf("Metadata response status code: %d. Body: %s", resp.StatusCode, string(body))
209+
return "", fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
209210
}
210211
return string(body), nil
211212
}

0 commit comments

Comments
 (0)