Skip to content

Commit

Permalink
Add TracingHiveMetastore
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Nov 15, 2023
1 parent 999a4ab commit ef63a5a
Show file tree
Hide file tree
Showing 8 changed files with 893 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.inject.Scopes;
import io.airlift.bootstrap.Bootstrap;
import io.airlift.json.JsonModule;
import io.opentelemetry.api.trace.Tracer;
import io.trino.filesystem.TrinoFileSystemFactory;
import io.trino.filesystem.hdfs.HdfsFileSystemFactory;
import io.trino.hdfs.HdfsEnvironment;
Expand Down Expand Up @@ -194,6 +195,7 @@ public void setUp()
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
binder.bind(Tracer.class).toInstance(context.getTracer());
},
// connector modules
new DeltaLakeMetastoreModule(),
Expand Down
16 changes: 10 additions & 6 deletions plugin/trino-hive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,21 @@
<artifactId>opentelemetry-api</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-aws-sdk-1.11</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-cache</artifactId>
Expand Down Expand Up @@ -283,12 +293,6 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.trino.plugin.hive.metastore.cache.SharedHiveMetastoreCache.CachingHiveMetastoreFactory;
import io.trino.plugin.hive.metastore.procedure.FlushMetadataCacheProcedure;
import io.trino.plugin.hive.metastore.recording.RecordingHiveMetastoreDecoratorModule;
import io.trino.plugin.hive.metastore.tracing.TracingHiveMetastoreDecorator;
import io.trino.spi.procedure.Procedure;
import io.trino.spi.security.ConnectorIdentity;

Expand Down Expand Up @@ -52,7 +53,8 @@ public DecoratedHiveMetastoreModule(boolean installFlushMetadataCacheProcedure)
@Override
protected void setup(Binder binder)
{
newSetBinder(binder, HiveMetastoreDecorator.class);
newSetBinder(binder, HiveMetastoreDecorator.class)
.addBinding().to(TracingHiveMetastoreDecorator.class).in(Scopes.SINGLETON);
install(new RecordingHiveMetastoreDecoratorModule());

configBinder(binder).bindConfig(CachingHiveMetastoreConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
public interface HiveMetastoreDecorator
{
int PRIORITY_PARTITION_PROJECTION = 50;
int PRIORITY_RECORDING = 100;
int PRIORITY_TRACING = 100;
int PRIORITY_RECORDING = 200;

int getPriority();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 io.trino.plugin.hive.metastore.tracing;

import io.opentelemetry.api.common.AttributeKey;

import static io.opentelemetry.api.common.AttributeKey.longKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey;

final class MetastoreAttributes
{
private MetastoreAttributes() {}

public static final AttributeKey<String> SCHEMA = stringKey("trino.schema");
public static final AttributeKey<Long> SCHEMA_RESPONSE_COUNT = longKey("trino.hive.response.schema_count");
public static final AttributeKey<String> TABLE = stringKey("trino.table");
public static final AttributeKey<Long> TABLE_RESPONSE_COUNT = longKey("trino.hive.response.table_count");
public static final AttributeKey<String> PARTITION = stringKey("trino.partition");
public static final AttributeKey<String> FUNCTION = stringKey("trino.function");
public static final AttributeKey<Long> FUNCTION_RESPONSE_COUNT = longKey("trino.hive.response.function_count");
public static final AttributeKey<String> ACID_TRANSACTION = stringKey("trino.hive.acid_transaction");
public static final AttributeKey<Long> PARTITION_REQUEST_COUNT = longKey("trino.hive.request.partition_count");
public static final AttributeKey<Long> PARTITION_RESPONSE_COUNT = longKey("trino.hive.response.partition_count");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 io.trino.plugin.hive.metastore.tracing;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;

import static io.opentelemetry.api.trace.StatusCode.ERROR;
import static io.opentelemetry.semconv.SemanticAttributes.EXCEPTION_ESCAPED;

final class Tracing
{
private Tracing() {}

public static <E extends Exception> void withTracing(Span span, CheckedRunnable<E> runnable)
throws E
{
withTracing(span, () -> {
runnable.run();
return null;
});
}

public static <T, E extends Exception> T withTracing(Span span, CheckedSupplier<T, E> supplier)
throws E
{
try (var ignored = span.makeCurrent()) {
return supplier.get();
}
catch (Throwable t) {
span.setStatus(ERROR, t.getMessage());
span.recordException(t, Attributes.of(EXCEPTION_ESCAPED, true));
throw t;
}
finally {
span.end();
}
}

public interface CheckedRunnable<E extends Exception>
{
void run()
throws E;
}

public interface CheckedSupplier<T, E extends Exception>
{
T get()
throws E;
}
}
Loading

0 comments on commit ef63a5a

Please sign in to comment.