Skip to content

Commit

Permalink
[#16] .Update minor fixes after pre review
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasObenaus committed Feb 18, 2020
1 parent 15ebfe9 commit aa7f184
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
5 changes: 1 addition & 4 deletions cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,9 @@ func updateRequestMetrics(respones []interfaces.Response, metrics *Metrics) {

numResponses := len(respones)
var requestChargePerQueryResponseAvg float64
if numResponses > 0 {
requestChargePerQueryResponseAvg = float64(requestChargePerQueryTotal) / float64(numResponses)
}

var serverTimePerQueryResponseAvg float64
if numResponses > 0 {
requestChargePerQueryResponseAvg = float64(requestChargePerQueryTotal) / float64(numResponses)
serverTimePerQueryResponseAvg = float64(serverTimePerQueryTotal.Milliseconds()) / float64(numResponses)
}

Expand Down
33 changes: 16 additions & 17 deletions cosmosResponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const (
)

// extractFirstError runs through the given responses and returns the first error it finds.
// All information (e.g.)
func extractFirstError(responses []interfaces.Response) error {

for _, response := range responses {
Expand All @@ -53,29 +52,29 @@ func extractFirstError(responses []interfaces.Response) error {
continue
}

// since all success codes are already skipped
// here we have an error

// Do specific a interpretation on the 500 errors if possible.
// Usually from CosmosDB we can use additional headers to extract more detail
if statusCode == interfaces.StatusServerError {
responseInfo, err := parseAttributeMap(response.Status.Attributes)
if err != nil {
// if we can't parse/ interpret the attribute map then we return the full/ unparsed error information
return fmt.Errorf("Failed parsing attributes of response: '%s'. Unparsed error: %d - %s", err.Error(), response.Status.Code, response.Status.Message)
}
return fmt.Errorf("%d (%d) - %s", responseInfo.statusCode, responseInfo.subStatusCode, responseInfo.statusDescription)
// since all success codes are already skipped, now we have an error

// For the non 500 error status codes, do the usual error detection mechanism based on the main status code.
if statusCode != interfaces.StatusServerError {
return extractError(response)
}

// Try to provide a more specific error message for the 500 errors if possible.
// Usually from CosmosDB we can use additional headers to extract more details.
responseInfo, err := parseAttributeMap(response.Status.Attributes)
if err != nil {
// if we can't parse/ interpret the attribute map then we return the full/ unparsed error information
return fmt.Errorf("Failed parsing attributes of response: '%s'. Unparsed error: %d - %s", err.Error(), response.Status.Code, response.Status.Message)
}
return fmt.Errorf("%d (%d) - %s", responseInfo.statusCode, responseInfo.subStatusCode, responseInfo.statusDescription)

// for the remaining error status codes do the usual error detection mechanism based on the main status code
return extractError(response)
}

// no error was found
return nil
}

// parseAttributeMap parses the given attribute map assuming that it contains
// CosmosDB specific headers.
// parseAttributeMap parses the given attribute map assuming that it contains CosmosDB specific headers.
func parseAttributeMap(attributes map[string]interface{}) (responseInformation, error) {
responseInfo := responseInformation{}

Expand Down
1 change: 1 addition & 0 deletions examples/cosmos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
gremcos.WithLogger(logger),
gremcos.NumMaxActiveConnections(10),
gremcos.ConnectionIdleTimeout(time.Second*30),
gremcos.MetricsPrefix("myservice"),
)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ sonar.organization=supplyon
sonar.projectKey=supplyon_gremcos
sonar.projectName=gremcos

sonar.sources=./
sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**,**/test/mocks/**

sonar.tests=./
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**,**/test/mocks/**
sonar.go.coverage.reportPaths=coverage.out
Expand Down

0 comments on commit aa7f184

Please sign in to comment.