Skip to content

Commit

Permalink
Collect more metrics from PrestoS3FileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
nezihyigitbasi authored and electrum committed Apr 30, 2015
1 parent 04ad885 commit ba1024a
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 14 deletions.
5 changes: 5 additions & 0 deletions presto-docs/src/main/sphinx/release/release-0.102.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ General Changes
---------------

* Support returning booleans as numbers in JDBC driver

Hive Changes
------------

* Collect more metrics from ``PrestoS3FileSystem``.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.amazonaws.AbortedException;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
Expand All @@ -24,6 +23,7 @@
import com.amazonaws.event.ProgressEvent;
import com.amazonaws.event.ProgressEventType;
import com.amazonaws.event.ProgressListener;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.AmazonS3Exception;
Expand Down Expand Up @@ -94,6 +94,7 @@ public class PrestoS3FileSystem
private static final Logger log = Logger.get(PrestoS3FileSystem.class);

private static final PrestoS3FileSystemStats STATS = new PrestoS3FileSystemStats();
private static final PrestoS3FileSystemMetricCollector METRIC_COLLECTOR = new PrestoS3FileSystemMetricCollector(STATS);

public static PrestoS3FileSystemStats getFileSystemStats()
{
Expand Down Expand Up @@ -402,12 +403,15 @@ private ObjectMetadata getS3ObjectMetadata(Path path)
STATS.newMetadataCall();
return s3.getObjectMetadata(uri.getHost(), keyFromPath(path));
}
catch (AmazonS3Exception e) {
if (e.getStatusCode() == SC_NOT_FOUND) {
return null;
}
else if (e.getStatusCode() == SC_FORBIDDEN) {
throw new UnrecoverableS3OperationException(e);
catch (RuntimeException e) {
STATS.newGetMetadataError();
if (e instanceof AmazonS3Exception) {
switch (((AmazonS3Exception) e).getStatusCode()) {
case SC_NOT_FOUND:
return null;
case SC_FORBIDDEN:
throw new UnrecoverableS3OperationException(e);
}
}
throw Throwables.propagate(e);
}
Expand Down Expand Up @@ -462,13 +466,13 @@ private AmazonS3Client createAmazonS3Client(URI uri, Configuration hadoopConfig,
{
// first try credentials from URI or static properties
try {
return new AmazonS3Client(getAwsCredentials(uri, hadoopConfig), clientConfig);
return new AmazonS3Client(new StaticCredentialsProvider(getAwsCredentials(uri, hadoopConfig)), clientConfig, METRIC_COLLECTOR);
}
catch (IllegalArgumentException ignored) {
}

if (useInstanceCredentials) {
return new AmazonS3Client(new InstanceProfileCredentialsProvider(), clientConfig);
return new AmazonS3Client(new InstanceProfileCredentialsProvider(), clientConfig, METRIC_COLLECTOR);
}

throw new RuntimeException("S3 credentials not configured");
Expand Down Expand Up @@ -553,6 +557,7 @@ public int read(byte[] buffer, int offset, int length)
return in.read(buffer, offset, length);
}
catch (Exception e) {
STATS.newReadError(e);
closeStream();
throw e;
}
Expand Down Expand Up @@ -628,9 +633,12 @@ private S3Object getS3Object(Path path, long start)
try {
return s3.getObject(new GetObjectRequest(host, keyFromPath(path)).withRange(start, Long.MAX_VALUE));
}
catch (AmazonServiceException e) {
if (e.getStatusCode() == SC_FORBIDDEN) {
throw new UnrecoverableS3OperationException(e);
catch (RuntimeException e) {
STATS.newGetObjectError();
if (e instanceof AmazonS3Exception) {
if (((AmazonS3Exception) e).getStatusCode() == SC_FORBIDDEN) {
throw new UnrecoverableS3OperationException(e);
}
}
throw Throwables.propagate(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.hive;

import com.amazonaws.Request;
import com.amazonaws.Response;
import com.amazonaws.metrics.RequestMetricCollector;
import com.amazonaws.util.AWSRequestMetrics;
import com.amazonaws.util.TimingInfo;

import static com.amazonaws.util.AWSRequestMetrics.Field;
import static com.google.common.base.Preconditions.checkNotNull;

public class PrestoS3FileSystemMetricCollector
extends RequestMetricCollector
{
private final PrestoS3FileSystemStats stats;

public PrestoS3FileSystemMetricCollector(PrestoS3FileSystemStats stats)
{
this.stats = checkNotNull(stats, "stats is null");
}

@Override
public void collectMetrics(Request<?> request, Response<?> response)
{
AWSRequestMetrics metrics = request.getAWSRequestMetrics();

TimingInfo timingInfo = metrics.getTimingInfo();
Number requestCounts = timingInfo.getCounter(Field.RequestCount.name());
Number retryCounts = timingInfo.getCounter(Field.HttpClientRetryCount.name());
Number throttleExceptions = timingInfo.getCounter(Field.ThrottleException.name());

if (requestCounts != null) {
stats.updateAwsRequestCount(requestCounts.longValue());
}

if (retryCounts != null) {
stats.updateAwsRetryCount(retryCounts.longValue());
}

if (throttleExceptions != null) {
stats.updateAwsThrottleExceptionsCount(throttleExceptions.longValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
*/
package com.facebook.presto.hive;

import com.amazonaws.AbortedException;
import io.airlift.stats.CounterStat;
import org.weakref.jmx.Managed;
import org.weakref.jmx.Nested;

import java.net.SocketException;
import java.net.SocketTimeoutException;

public class PrestoS3FileSystemStats
{
public PrestoS3FileSystemStats() {}

private final CounterStat activeConnections = new CounterStat();
private final CounterStat startedUploads = new CounterStat();
private final CounterStat failedUploads = new CounterStat();
Expand All @@ -29,6 +31,17 @@ public PrestoS3FileSystemStats() {}
private final CounterStat listStatusCalls = new CounterStat();
private final CounterStat listLocatedStatusCalls = new CounterStat();
private final CounterStat listObjectsCalls = new CounterStat();
private final CounterStat otherReadErrors = new CounterStat();
private final CounterStat awsAbortedExceptions = new CounterStat();
private final CounterStat socketExceptions = new CounterStat();
private final CounterStat socketTimeoutExceptions = new CounterStat();
private final CounterStat getObjectErrors = new CounterStat();
private final CounterStat getMetadataErrors = new CounterStat();

// see AWSRequestMetrics
private final CounterStat awsRequestCount = new CounterStat();
private final CounterStat awsRetryCount = new CounterStat();
private final CounterStat awsThrottleExceptions = new CounterStat();

@Managed
@Nested
Expand Down Expand Up @@ -86,6 +99,69 @@ public CounterStat getListObjectsCalls()
return listObjectsCalls;
}

@Managed
@Nested
public CounterStat getGetObjectErrors()
{
return getObjectErrors;
}

@Managed
@Nested
public CounterStat getGetMetadataErrors()
{
return getMetadataErrors;
}

@Managed
@Nested
public CounterStat getOtherReadErrors()
{
return otherReadErrors;
}

@Managed
@Nested
public CounterStat getSocketExceptions()
{
return socketExceptions;
}

@Managed
@Nested
public CounterStat getSocketTimeoutExceptions()
{
return socketTimeoutExceptions;
}

@Managed
@Nested
public CounterStat getAwsAbortedExceptions()
{
return awsAbortedExceptions;
}

@Managed
@Nested
public CounterStat getAwsRequestCount()
{
return awsRequestCount;
}

@Managed
@Nested
public CounterStat getAwsRetryCount()
{
return awsRetryCount;
}

@Managed
@Nested
public CounterStat getAwsThrottleExceptions()
{
return awsThrottleExceptions;
}

public void connectionOpened()
{
activeConnections.update(1);
Expand Down Expand Up @@ -130,4 +206,45 @@ public void newListObjectsCall()
{
listObjectsCalls.update(1);
}

public void newReadError(Exception e)
{
if (e instanceof SocketException) {
socketExceptions.update(1);
}
else if (e instanceof SocketTimeoutException) {
socketTimeoutExceptions.update(1);
}
else if (e instanceof AbortedException) {
awsAbortedExceptions.update(1);
}
else {
otherReadErrors.update(1);
}
}

public void newGetObjectError()
{
getObjectErrors.update(1);
}

public void newGetMetadataError()
{
getMetadataErrors.update(1);
}

public void updateAwsRequestCount(long requestCount)
{
awsRequestCount.update(requestCount);
}

public void updateAwsRetryCount(long retryCount)
{
awsRetryCount.update(retryCount);
}

public void updateAwsThrottleExceptionsCount(long throttleExceptionsCount)
{
awsThrottleExceptions.update(throttleExceptionsCount);
}
}

0 comments on commit ba1024a

Please sign in to comment.