/** * Returned the best-guessed throughput metric type for the given request, * or null if there is none or if metric is disabled. */ public static ThroughputMetricType guessThroughputMetricType( final Request<?> req, final String metricNameSuffix, final String byteCountMetricNameSuffix) { if (!AwsSdkMetrics.isMetricsEnabled()) return null; // metric disabled Object orig = req.getOriginalRequestObject(); if (orig.getClass().getName().startsWith("com.amazonaws.services.s3")) { return new SimpleThroughputMetricType( "S3" + metricNameSuffix, req.getServiceName(), "S3" + byteCountMetricNameSuffix); } return null; } }
private void collectMetrics0(Request<?> request, Response<?> response) { AWSRequestMetrics arm = request.getAWSRequestMetrics(); if (arm == null || !arm.isEnabled()) { return; } for (MetricType type: AwsSdkMetrics.getPredefinedMetrics()) { if (!(type instanceof RequestMetricType)) continue; PredefinedMetricTransformer transformer = getTransformer(); for (MetricDatum datum : transformer.toMetricData(type, request, response)) { try { if (!addMetricsToQueue(datum)) { if (log.isDebugEnabled()) { log.debug("Failed to add to the metrics queue (due to no space available) for " + type.name() + ":" + request.getServiceName()); } } } catch(RuntimeException ex) { log.warn("Failed to add to the metrics queue for " + type.name() + ":" + request.getServiceName(), ex); } } } }
} else { return Collections.singletonList(new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(new Dimension() .withName(Dimensions.MetricType.name())
.withValue(tableName)); MetricDatum datum = new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(dims) .withUnit(StandardUnit.Count)
protected List<MetricDatum> metricOfCount( Field metricType, Request<?> req, Object resp) { AWSRequestMetrics m = req.getAWSRequestMetrics(); TimingInfo ti = m.getTimingInfo(); Number counter = ti.getCounter(metricType.name()); if (counter == null) { return Collections.emptyList(); } final double count = counter.doubleValue(); if (count < 1) { return Collections.emptyList(); } else { return Collections.singletonList(new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(new Dimension() .withName(Dimensions.MetricType.name()) .withValue(metricType.name())) .withUnit(StandardUnit.Count) .withValue(Double.valueOf(count)) .withTimestamp(endTimestamp(ti))) ; } }
.withMetricName(req.getServiceName()) .withDimensions(metricDimension) .withUnit(StandardUnit.Count)
/** * Returns a request type specific metrics for * {@link Field#ClientExecuteTime} which is special in the sense that it * makes a more accurate measurement by taking the {@link TimingInfo} at the * root into account. */ protected List<MetricDatum> latencyOfClientExecuteTime(Request<?> req, Object response) { AWSRequestMetrics m = req.getAWSRequestMetrics(); TimingInfo root = m.getTimingInfo(); final String metricName = Field.ClientExecuteTime.name(); if (root.isEndTimeKnown()) { // being defensive List<Dimension> dims = new ArrayList<Dimension>(); dims.add(new Dimension() .withName(Dimensions.MetricType.name()) .withValue(metricName)); // request type specific dims.add(new Dimension() .withName(Dimensions.RequestType.name()) .withValue(requestType(req))); MetricDatum datum = new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(dims) .withUnit(StandardUnit.Milliseconds) .withValue(root.getTimeTakenMillisIfKnown()); return Collections.singletonList(datum); } return Collections.emptyList(); }
.withMetricName(req.getServiceName()) .withDimensions(dims) .withUnit(StandardUnit.Milliseconds)
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { final AmazonServiceException ase = handleAse(response); ase.setStatusCode(response.getStatusCode()); ase.setServiceName(response.getRequest().getServiceName()); awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId()) .addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode()) .addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode()); return ase; }
private AmazonServiceException handleAse(HttpResponse response) throws Exception { final int statusCode = response.getStatusCode(); try { return delegate.handle(response); } catch(InterruptedException e) { throw e; } catch (Exception e) { // If the errorResponseHandler doesn't work, then check for error responses that don't have any content if (statusCode == 413) { AmazonServiceException exception = new AmazonServiceException("Request entity too large"); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Client); exception.setErrorCode("Request entity too large"); return exception; } else if (statusCode >= 500 && statusCode < 600) { AmazonServiceException exception = new AmazonServiceException(response.getStatusText()); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Service); exception.setErrorCode(response.getStatusText()); return exception; } else { throw e; } } }
.addPropertyWith(Field.ServiceName, request.getServiceName()) .addPropertyWith(Field.ServiceEndpoint, request.getEndpoint());
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }
/** * Returned the best-guessed throughput metric type for the given request, * or null if there is none or if metric is disabled. */ public static ThroughputMetricType guessThroughputMetricType( final Request<?> req, final String metricNameSuffix, final String byteCountMetricNameSuffix) { if (!AwsSdkMetrics.isMetricsEnabled()) return null; // metric disabled AmazonWebServiceRequest orig = req.getOriginalRequest(); if (orig.getClass().getName().startsWith("com.amazonaws.services.s3")) { return new SimpleThroughputMetricType( "S3" + metricNameSuffix, req.getServiceName(), "S3" + byteCountMetricNameSuffix); } return null; } }
/** * Returned the best-guessed throughput metric type for the given request, * or null if there is none or if metric is disabled. */ public static ThroughputMetricType guessThroughputMetricType( final Request<?> req, final String metricNameSuffix, final String byteCountMetricNameSuffix) { if (!AwsSdkMetrics.isMetricsEnabled()) return null; // metric disabled Object orig = req.getOriginalRequestObject(); if (orig.getClass().getName().startsWith("com.amazonaws.services.s3")) { return new SimpleThroughputMetricType( "S3" + metricNameSuffix, req.getServiceName(), "S3" + byteCountMetricNameSuffix); } return null; } }
ase.setRequestId(requestId); ase.setExtendedRequestId(hostId); ase.setServiceName(request.getServiceName()); ase.setStatusCode(200);
ase.setRequestId(requestId); ase.setExtendedRequestId(hostId); ase.setServiceName(request.getServiceName()); ase.setStatusCode(200);
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { final AmazonServiceException ase = handleAse(response); ase.setStatusCode(response.getStatusCode()); ase.setServiceName(response.getRequest().getServiceName()); awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId()) .addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode()) .addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode()); return ase; }
private AmazonServiceException handleAse(HttpResponse response) throws Exception { final int statusCode = response.getStatusCode(); try { return delegate.handle(response); } catch(InterruptedException e) { throw e; } catch (Exception e) { // If the errorResponseHandler doesn't work, then check for error responses that don't have any content if (statusCode == 413) { AmazonServiceException exception = new AmazonServiceException("Request entity too large"); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Client); exception.setErrorCode("Request entity too large"); return exception; } else if (statusCode >= 500 && statusCode < 600) { AmazonServiceException exception = new AmazonServiceException(response.getStatusText()); exception.setServiceName(response.getRequest().getServiceName()); exception.setStatusCode(statusCode); exception.setErrorType(AmazonServiceException.ErrorType.Service); exception.setErrorCode(response.getStatusText()); return exception; } else { throw e; } } }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); AmazonServiceException ase = new AmazonServiceException("Test"); ase.setErrorCode("TestError"); ase.setErrorType(ErrorType.Service); ase.setServiceName(request.getServiceName()); ase.setStatusCode(response.getStatusCode()); return ase; }
@Override public AmazonServiceException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); String errorCode = errorCodeParser.parseErrorCode(response, jsonContent); AmazonServiceException ase = createException(errorCode, jsonContent); // Jackson has special-casing for 'message' values when deserializing // Throwables, but sometimes the service passes the error message in // other JSON fields - handle it here. if (ase.getErrorMessage() == null) { ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode())); } ase.setErrorCode(errorCode); ase.setServiceName(response.getRequest().getServiceName()); ase.setStatusCode(response.getStatusCode()); ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode())); ase.setRawResponse(jsonContent.getRawContent()); String requestId = getRequestIdFromHeaders(response.getHeaders()); if (requestId != null) { ase.setRequestId(requestId); } ase.setHttpHeaders(response.getHeaders()); return ase; }