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

[Legend SQL] - Add metrics and tracing #2708

Merged
merged 28 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>legend-engine-xts-sql</artifactId>
<groupId>org.finos.legend.engine</groupId>
Expand Down Expand Up @@ -110,6 +111,7 @@
</profile>
</profiles>


<dependencies>
<dependency>
<groupId>io.netty</groupId>
Expand Down Expand Up @@ -172,11 +174,15 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<!-- JACKSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down Expand Up @@ -254,6 +260,42 @@
<artifactId>javax.ws.rs-api</artifactId>
</dependency>


<!-- OPEN TELEMETRY -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-trace-propagators</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-trace</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>
<!-- OPEN TELEMETRY -->

<!-- WIREMOCK -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
Expand Down Expand Up @@ -347,6 +389,28 @@
<artifactId>postgresql</artifactId>
<version>42.5.4</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.9.10</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>1.23.1-alpha</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>1.36.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
public class Messages
{

private Messages()
{
}

//private static final Logger LOGGER = LogManager.getLogger(Messages.class);
private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(Messages.class);

Expand Down Expand Up @@ -326,7 +330,7 @@ private static ChannelFuture sendErrorResponse(Channel channel,
* above length.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
static void sendDataRow(Channel channel, PostgresResultSet rs, List<PGType> columnTypes,
static void sendDataRow(Channel channel, PostgresResultSet rs, List<PGType<?>> columnTypes,
FormatCodes.FormatCode[] formatCodes) throws Exception
{
int length = 4 + 2;
Expand Down Expand Up @@ -608,14 +612,14 @@ static void sendAuthenticationCleartextPassword(Channel channel)
static void sendAuthenticationKerberos(Channel channel)
{
int integerLength = 8;
int AUTH_REQ_GSS = 7;
int authReqGss = 7;
int nullStopByteLength = 1;
int length = integerLength + nullStopByteLength;

ByteBuf buffer = channel.alloc().buffer(length);
buffer.writeByte('R');
buffer.writeInt(integerLength);
buffer.writeInt(AUTH_REQ_GSS);
buffer.writeInt(authReqGss);

ChannelFuture channelFuture = channel.writeAndFlush(buffer);
if (LOGGER.isTraceEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,37 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
import io.opentelemetry.extension.trace.propagation.B3Propagator;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.OpenTelemetrySdkBuilder;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.semconv.ResourceAttributes;
import org.apache.commons.lang3.StringUtils;
import org.finos.legend.engine.postgres.auth.AuthenticationMethod;
import org.finos.legend.engine.postgres.config.OpenTelemetryConfig;
import org.finos.legend.engine.postgres.config.ServerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

public class PostgresServerLauncher
{
private String configPath;
private final String configPath;

public PostgresServerLauncher(String configPath)
{
this.configPath = configPath;
}

public void launch() throws Exception
public void launch() throws IOException
{
//TODO ADD CLI

Expand All @@ -52,6 +66,8 @@ public void launch() throws Exception
System.setProperty("java.security.krb5.conf", serverConfig.getGss().getKerberosConfigFile());
}

setupOpenTelemetry(serverConfig.getOtelConfig());

//Log config has been initiated. We can create a logger now.
Logger logger = LoggerFactory.getLogger(PostgresServerLauncher.class);

Expand All @@ -61,13 +77,46 @@ public void launch() throws Exception
SessionsFactory sessionFactory = serverConfig.buildSessionFactory();
AuthenticationMethod authenticationMethod = serverConfig.buildAuthenticationMethod();

logger.info("Starting server in port: " + serverConfig.getPort());
logger.info("Starting server in port: {}", serverConfig.getPort());

new PostgresServer(serverConfig, sessionFactory, (user, connectionProperties) -> authenticationMethod).run();
}

public static void main(String[] args) throws Exception
private void setupOpenTelemetry(OpenTelemetryConfig otelConfig)
{
String zipkinEndpoint = otelConfig.getZipkinEndpoint();
String serviceName = otelConfig.getServiceName();

SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder();
OpenTelemetrySdkBuilder otelSdkBuilder = OpenTelemetrySdk.builder();
ContextPropagators propagators = ContextPropagators.noop();

if (StringUtils.isNotBlank(zipkinEndpoint))
{
ZipkinSpanExporter spanExporter = ZipkinSpanExporter.builder().setEndpoint(zipkinEndpoint).build();
tracerProviderBuilder.addSpanProcessor(SimpleSpanProcessor.create(spanExporter));
propagators = ContextPropagators.create(B3Propagator.injectingMultiHeaders());
}

if (StringUtils.isNotBlank(serviceName))
{
Resource serviceNameResource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, serviceName));
tracerProviderBuilder.setResource(serviceNameResource);
}

SdkTracerProvider tracerProvider = tracerProviderBuilder.build();

OpenTelemetrySdk openTelemetrySdk = otelSdkBuilder.setTracerProvider(tracerProvider)
.setPropagators(propagators)
.buildAndRegisterGlobal();

Runtime.getRuntime().addShutdownHook(new Thread(openTelemetrySdk::close));
}

public static void main(String[] args) throws IOException
{
String configPath = args[0];
new PostgresServerLauncher(configPath).launch();
}
}

Loading
Loading