Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDK and API metrics to GlueHiveMetastore #15355

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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://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.metastore.glue;

import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.handlers.AsyncHandler;
import com.facebook.airlift.stats.CounterStat;
import com.facebook.airlift.stats.TimeStat;
import org.weakref.jmx.Managed;
import org.weakref.jmx.Nested;

import javax.annotation.concurrent.ThreadSafe;

import java.util.function.Supplier;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

@ThreadSafe
public class GlueCatalogApiStats
{
private final TimeStat time = new TimeStat(MILLISECONDS);
private final CounterStat totalFailures = new CounterStat();

public <T> T record(Supplier<T> action)
{
try (TimeStat.BlockTimer timer = time.time()) {
return action.get();
}
catch (Exception e) {
recordException(e);
throw e;
}
}

public void record(Runnable action)
{
try (TimeStat.BlockTimer timer = time.time()) {
action.run();
}
catch (Exception e) {
recordException(e);
throw e;
}
}

public <R extends AmazonWebServiceRequest, T> AsyncHandler<R, T> metricsAsyncHandler()
{
return new AsyncHandler<R, T>() {
private final TimeStat.BlockTimer timer = time.time();
@Override
public void onError(Exception exception)
{
timer.close();
recordException(exception);
}

@Override
public void onSuccess(R request, T result)
{
timer.close();
}
};
}

@Managed
@Nested
public TimeStat getTime()
{
return time;
}

@Managed
@Nested
public CounterStat getTotalFailures()
{
return totalFailures;
}

private void recordException(Exception e)
{
totalFailures.update(1);
}
}
Loading