use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.
the class AmbryBlobStorageService method handleOptions.
@Override
public void handleOptions(RestRequest restRequest, RestResponseChannel restResponseChannel) {
long processingStartTime = System.currentTimeMillis();
handlePrechecks(restRequest, restResponseChannel);
RestRequestMetrics requestMetrics = restRequest.getSSLSession() != null ? frontendMetrics.optionsSSLMetrics : frontendMetrics.optionsMetrics;
restRequest.getMetricsTracker().injectMetrics(requestMetrics);
Exception exception = null;
try {
logger.trace("Handling OPTIONS request - {}", restRequest.getUri());
checkAvailable();
// TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
securityService.preProcessRequest(restRequest).get();
long preProcessingEndTime = System.currentTimeMillis();
frontendMetrics.optionsPreProcessingTimeInMs.update(preProcessingEndTime - processingStartTime);
// making this blocking for now. TODO: convert to non blocking
securityService.processRequest(restRequest).get();
long securityRequestProcessingEndTime = System.currentTimeMillis();
frontendMetrics.optionsSecurityRequestTimeInMs.update(securityRequestProcessingEndTime - preProcessingEndTime);
restResponseChannel.setStatus(ResponseStatus.Ok);
restResponseChannel.setHeader(RestUtils.Headers.DATE, new GregorianCalendar().getTime());
restResponseChannel.setHeader(RestUtils.Headers.CONTENT_LENGTH, 0);
restResponseChannel.setHeader(Headers.ACCESS_CONTROL_ALLOW_METHODS, frontendConfig.frontendOptionsAllowMethods);
restResponseChannel.setHeader(Headers.ACCESS_CONTROL_MAX_AGE, frontendConfig.frontendOptionsValiditySeconds);
securityService.processResponse(restRequest, restResponseChannel, null).get();
long securityResponseProcessingEndTime = System.currentTimeMillis();
frontendMetrics.optionsSecurityResponseTimeInMs.update(securityResponseProcessingEndTime - securityRequestProcessingEndTime);
} catch (Exception e) {
exception = extractExecutionExceptionCause(e);
}
submitResponse(restRequest, restResponseChannel, null, exception);
}
use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.
the class AmbryBlobStorageService method handleDelete.
@Override
public void handleDelete(RestRequest restRequest, RestResponseChannel restResponseChannel) {
long processingStartTime = System.currentTimeMillis();
long preProcessingTime = 0;
handlePrechecks(restRequest, restResponseChannel);
RestRequestMetrics requestMetrics = restRequest.getSSLSession() != null ? frontendMetrics.deleteBlobSSLMetrics : frontendMetrics.deleteBlobMetrics;
restRequest.getMetricsTracker().injectMetrics(requestMetrics);
try {
logger.trace("Handling DELETE request - {}", restRequest.getUri());
checkAvailable();
// TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
securityService.preProcessRequest(restRequest).get();
DeleteCallback routerCallback = new DeleteCallback(restRequest, restResponseChannel);
preProcessingTime = System.currentTimeMillis() - processingStartTime;
SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, routerCallback);
securityService.processRequest(restRequest, securityCallback);
} catch (Exception e) {
submitResponse(restRequest, restResponseChannel, null, extractExecutionExceptionCause(e));
} finally {
frontendMetrics.deletePreProcessingTimeInMs.update(preProcessingTime);
}
}
use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.
the class GetSignedUrlHandler method handle.
/**
* Handles a request for getting signed URLs.
* @param restRequest the {@link RestRequest} that contains the request parameters.
* @param restResponseChannel the {@link RestResponseChannel} where headers should be set.
* @param callback the {@link Callback} to invoke when the response is ready (or if there is an exception).
* @throws RestServiceException if required parameters are not found or are invalid
*/
void handle(RestRequest restRequest, RestResponseChannel restResponseChannel, Callback<ReadableStreamChannel> callback) throws RestServiceException {
RestRequestMetrics requestMetrics = restRequest.getSSLSession() != null ? metrics.getSignedUrlSSLMetrics : metrics.getSignedUrlMetrics;
restRequest.getMetricsTracker().injectMetrics(requestMetrics);
String restMethodInSignedUrlStr = RestUtils.getHeader(restRequest.getArgs(), RestUtils.Headers.URL_TYPE, true);
RestMethod restMethodInUrl;
try {
restMethodInUrl = RestMethod.valueOf(restMethodInSignedUrlStr);
} catch (IllegalArgumentException e) {
throw new RestServiceException("Unrecognized RestMethod: " + restMethodInSignedUrlStr, RestServiceErrorCode.InvalidArgs);
}
securityService.processRequest(restRequest, new SecurityProcessRequestCallback(restRequest, restMethodInUrl, restResponseChannel, callback));
}
use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.
the class AmbryBlobStorageService method handlePost.
@Override
public void handlePost(RestRequest restRequest, RestResponseChannel restResponseChannel) {
long processingStartTime = System.currentTimeMillis();
long preProcessingTime = 0;
handlePrechecks(restRequest, restResponseChannel);
boolean sslUsed = restRequest.getSSLSession() != null;
RestRequestMetrics metrics = frontendMetrics.postRequestMetricsGroup.getRestRequestMetrics(sslUsed, false);
restRequest.getMetricsTracker().injectMetrics(metrics);
try {
logger.trace("Handling POST request - {}", restRequest.getUri());
checkAvailable();
// TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
securityService.preProcessRequest(restRequest).get();
long propsBuildStartTime = System.currentTimeMillis();
accountAndContainerInjector.injectAccountAndContainerForPostRequest(restRequest);
BlobProperties blobProperties = RestUtils.buildBlobProperties(restRequest.getArgs());
if (blobProperties.getTimeToLiveInSeconds() + TimeUnit.MILLISECONDS.toSeconds(blobProperties.getCreationTimeInMs()) > Integer.MAX_VALUE) {
logger.debug("TTL set to very large value in POST request with BlobProperties {}", blobProperties);
frontendMetrics.ttlTooLargeError.inc();
}
// inject encryption metrics if applicable
if (blobProperties.isEncrypted()) {
metrics = frontendMetrics.postRequestMetricsGroup.getRestRequestMetrics(sslUsed, true);
restRequest.getMetricsTracker().injectMetrics(metrics);
}
byte[] usermetadata = RestUtils.buildUsermetadata(restRequest.getArgs());
frontendMetrics.blobPropsBuildTimeInMs.update(System.currentTimeMillis() - propsBuildStartTime);
logger.trace("Blob properties of blob being POSTed - {}", blobProperties);
PostCallback routerCallback = new PostCallback(restRequest, restResponseChannel, new BlobInfo(blobProperties, usermetadata));
preProcessingTime = System.currentTimeMillis() - processingStartTime;
SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, blobProperties, usermetadata, routerCallback);
securityService.processRequest(restRequest, securityCallback);
} catch (Exception e) {
submitResponse(restRequest, restResponseChannel, null, extractExecutionExceptionCause(e));
} finally {
frontendMetrics.postPreProcessingTimeInMs.update(preProcessingTime);
}
}
use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.
the class AmbryBlobStorageService method handleHead.
@Override
public void handleHead(RestRequest restRequest, RestResponseChannel restResponseChannel) {
long processingStartTime = System.currentTimeMillis();
long preProcessingTime = 0;
handlePrechecks(restRequest, restResponseChannel);
try {
RestRequestMetrics requestMetrics = frontendMetrics.headRequestMetricsGroup.getRestRequestMetrics(restRequest.getSSLSession() != null, false);
restRequest.getMetricsTracker().injectMetrics(requestMetrics);
logger.trace("Handling HEAD request - {}", restRequest.getUri());
checkAvailable();
// TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
securityService.preProcessRequest(restRequest).get();
HeadCallback routerCallback = new HeadCallback(restRequest, restResponseChannel);
preProcessingTime = System.currentTimeMillis() - processingStartTime;
SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, routerCallback);
securityService.processRequest(restRequest, securityCallback);
} catch (Exception e) {
submitResponse(restRequest, restResponseChannel, null, extractExecutionExceptionCause(e));
} finally {
frontendMetrics.headPreProcessingTimeInMs.update(preProcessingTime);
}
}
Aggregations