]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/aws/aws-sdk-go/aws/csm/reporter.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / aws / aws-sdk-go / aws / csm / reporter.go
index 11082e5ed6d82066b2d4b5039cc2981578ed259e..0b5571acfbf1b282da78f82e83b9a86acc0ca98c 100644 (file)
@@ -82,14 +82,15 @@ func (rep *Reporter) sendAPICallAttemptMetric(r *request.Request) {
 
        if r.Error != nil {
                if awserr, ok := r.Error.(awserr.Error); ok {
-                       setError(&m, awserr)
+                       m.SetException(getMetricException(awserr))
                }
        }
 
+       m.TruncateFields()
        rep.metricsCh.Push(m)
 }
 
-func setError(m *metric, err awserr.Error) {
+func getMetricException(err awserr.Error) metricException {
        msg := err.Error()
        code := err.Code()
 
@@ -97,11 +98,13 @@ func setError(m *metric, err awserr.Error) {
        case "RequestError",
                "SerializationError",
                request.CanceledErrorCode:
-               m.SDKException = &code
-               m.SDKExceptionMessage = &msg
+               return sdkException{
+                       requestException{exception: code, message: msg},
+               }
        default:
-               m.AWSException = &code
-               m.AWSExceptionMessage = &msg
+               return awsException{
+                       requestException{exception: code, message: msg},
+               }
        }
 }
 
@@ -112,16 +115,31 @@ func (rep *Reporter) sendAPICallMetric(r *request.Request) {
 
        now := time.Now()
        m := metric{
-               ClientID:      aws.String(rep.clientID),
-               API:           aws.String(r.Operation.Name),
-               Service:       aws.String(r.ClientInfo.ServiceID),
-               Timestamp:     (*metricTime)(&now),
-               Type:          aws.String("ApiCall"),
-               AttemptCount:  aws.Int(r.RetryCount + 1),
-               Latency:       aws.Int(int(time.Now().Sub(r.Time) / time.Millisecond)),
-               XAmzRequestID: aws.String(r.RequestID),
+               ClientID:           aws.String(rep.clientID),
+               API:                aws.String(r.Operation.Name),
+               Service:            aws.String(r.ClientInfo.ServiceID),
+               Timestamp:          (*metricTime)(&now),
+               UserAgent:          aws.String(r.HTTPRequest.Header.Get("User-Agent")),
+               Type:               aws.String("ApiCall"),
+               AttemptCount:       aws.Int(r.RetryCount + 1),
+               Region:             r.Config.Region,
+               Latency:            aws.Int(int(time.Now().Sub(r.Time) / time.Millisecond)),
+               XAmzRequestID:      aws.String(r.RequestID),
+               MaxRetriesExceeded: aws.Int(boolIntValue(r.RetryCount >= r.MaxRetries())),
+       }
+
+       if r.HTTPResponse != nil {
+               m.FinalHTTPStatusCode = aws.Int(r.HTTPResponse.StatusCode)
        }
 
+       if r.Error != nil {
+               if awserr, ok := r.Error.(awserr.Error); ok {
+                       m.SetFinalException(getMetricException(awserr))
+               }
+       }
+
+       m.TruncateFields()
+
        // TODO: Probably want to figure something out for logging dropped
        // metrics
        rep.metricsCh.Push(m)
@@ -221,11 +239,22 @@ func (rep *Reporter) InjectHandlers(handlers *request.Handlers) {
                return
        }
 
-       apiCallHandler := request.NamedHandler{Name: APICallMetricHandlerName, Fn: rep.sendAPICallMetric}
-       apiCallAttemptHandler := request.NamedHandler{Name: APICallAttemptMetricHandlerName, Fn: rep.sendAPICallAttemptMetric}
+       handlers.Complete.PushFrontNamed(request.NamedHandler{
+               Name: APICallMetricHandlerName,
+               Fn:   rep.sendAPICallMetric,
+       })
 
-       handlers.Complete.PushFrontNamed(apiCallHandler)
-       handlers.Complete.PushFrontNamed(apiCallAttemptHandler)
+       handlers.CompleteAttempt.PushFrontNamed(request.NamedHandler{
+               Name: APICallAttemptMetricHandlerName,
+               Fn:   rep.sendAPICallAttemptMetric,
+       })
+}
+
+// boolIntValue return 1 for true and 0 for false.
+func boolIntValue(b bool) int {
+       if b {
+               return 1
+       }
 
-       handlers.AfterRetry.PushFrontNamed(apiCallAttemptHandler)
+       return 0
 }