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

SNOW-981533 Add 503 and contentType check for monitoring query response #981

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 14 additions & 4 deletions monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"database/sql/driver"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
)
Expand Down Expand Up @@ -144,11 +145,20 @@
logger.WithContext(ctx).Errorf("failed to get response. err: %v", err)
return nil, err
}
defer res.Body.Close()
var statusResp = statusResponse{}
if err = json.NewDecoder(res.Body).Decode(&statusResp); err != nil {
logger.WithContext(ctx).Errorf("failed to decode JSON. err: %v", err)
return nil, err
var contentType = res.Header.Get(httpHeaderContentType)
if res.StatusCode != http.StatusServiceUnavailable || contentType != headerContentTypeApplicationJSON {
defer res.Body.Close()
if err = json.NewDecoder(res.Body).Decode(&statusResp); err != nil {
logger.WithContext(ctx).Errorf("failed to decode JSON. err: %v", err)
return nil, err
}
} else {
return nil, (&SnowflakeError{
Number: ErrQueryStatus,
Message: fmt.Sprintf("status query returned response with a HTTP status [%v] and content type [%v]",
res.StatusCode, contentType),
}).exceptionTelemetry(sc)

Check warning on line 161 in monitoring.go

View check run for this annotation

Codecov / codecov/patch

monitoring.go#L156-L161

Added lines #L156 - L161 were not covered by tests
}

if !statusResp.Success || len(statusResp.Data.Queries) == 0 {
Expand Down
Loading