Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffe84fd331 |
@@ -4,7 +4,7 @@ org.gradle.caching=true
|
|||||||
|
|
||||||
rbcs.version = 0.5.0
|
rbcs.version = 0.5.0
|
||||||
|
|
||||||
lys.version = 2026.03.26
|
lys.version = 2026.04.28
|
||||||
|
|
||||||
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
|
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
|
||||||
docker.registry.url=gitea.woggioni.net
|
docker.registry.url=gitea.woggioni.net
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@Value
|
@Value
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
boolean enableTelemetry;
|
||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
boolean proxyProtocolEnabled;
|
boolean proxyProtocolEnabled;
|
||||||
@@ -150,6 +151,7 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Configuration of(
|
public static Configuration of(
|
||||||
|
boolean enableTelemetry,
|
||||||
String host,
|
String host,
|
||||||
int port,
|
int port,
|
||||||
boolean proxyProtocolEnabled,
|
boolean proxyProtocolEnabled,
|
||||||
@@ -166,6 +168,7 @@ public class Configuration {
|
|||||||
Tls tls
|
Tls tls
|
||||||
) {
|
) {
|
||||||
return new Configuration(
|
return new Configuration(
|
||||||
|
enableTelemetry,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
proxyProtocolEnabled,
|
proxyProtocolEnabled,
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ dependencies {
|
|||||||
implementation catalog.netty.buffer
|
implementation catalog.netty.buffer
|
||||||
implementation catalog.netty.transport
|
implementation catalog.netty.transport
|
||||||
implementation catalog.netty.codec.haproxy
|
implementation catalog.netty.codec.haproxy
|
||||||
|
compileOnly catalog.opentelemetry.netty['4']['1']
|
||||||
|
compileOnly catalog.opentelemetry.sdk.extension.autoconfigure
|
||||||
|
compileOnly catalog.opentelemetry.logback.appender['1']['0']
|
||||||
|
compileOnly catalog.opentelemetry.extension.trace.propagators
|
||||||
|
compileOnly catalog.logback.classic
|
||||||
|
|
||||||
api project(':rbcs-common')
|
api project(':rbcs-common')
|
||||||
api project(':rbcs-api')
|
api project(':rbcs-api')
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ module net.woggioni.rbcs.server {
|
|||||||
requires io.netty.common;
|
requires io.netty.common;
|
||||||
requires io.netty.codec;
|
requires io.netty.codec;
|
||||||
requires io.netty.codec.haproxy;
|
requires io.netty.codec.haproxy;
|
||||||
|
requires static io.opentelemetry.api;
|
||||||
|
requires static io.opentelemetry.instrumentation.netty_4_1;
|
||||||
|
requires static io.opentelemetry.sdk.autoconfigure;
|
||||||
|
requires static io.opentelemetry.instrumentation.logback_appender_1_0;
|
||||||
|
requires static io.opentelemetry.extension.trace.propagation;
|
||||||
requires org.slf4j;
|
requires org.slf4j;
|
||||||
|
|
||||||
exports net.woggioni.rbcs.server;
|
exports net.woggioni.rbcs.server;
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ import net.woggioni.rbcs.common.Xml
|
|||||||
import net.woggioni.rbcs.common.createLogger
|
import net.woggioni.rbcs.common.createLogger
|
||||||
import net.woggioni.rbcs.common.debug
|
import net.woggioni.rbcs.common.debug
|
||||||
import net.woggioni.rbcs.common.info
|
import net.woggioni.rbcs.common.info
|
||||||
|
import net.woggioni.rbcs.server.otel.OtelIntegration
|
||||||
|
import net.woggioni.rbcs.server.otel.OtelSdkIntegration
|
||||||
import net.woggioni.rbcs.server.auth.AbstractNettyHttpAuthenticator
|
import net.woggioni.rbcs.server.auth.AbstractNettyHttpAuthenticator
|
||||||
import net.woggioni.rbcs.server.auth.Authorizer
|
import net.woggioni.rbcs.server.auth.Authorizer
|
||||||
import net.woggioni.rbcs.server.auth.RoleAuthorizer
|
import net.woggioni.rbcs.server.auth.RoleAuthorizer
|
||||||
@@ -431,6 +433,7 @@ class RemoteBuildCacheServer(private val cfg: Configuration) {
|
|||||||
maxChunkSize = cfg.connection.chunkSize
|
maxChunkSize = cfg.connection.chunkSize
|
||||||
}
|
}
|
||||||
pipeline.addLast(HttpServerCodec(httpDecoderConfig))
|
pipeline.addLast(HttpServerCodec(httpDecoderConfig))
|
||||||
|
OtelIntegration.createHandler(cfg.isEnableTelemetry)?.let { pipeline.addLast(it) }
|
||||||
pipeline.addLast(ReadTriggerDuplexHandler.NAME, ReadTriggerDuplexHandler())
|
pipeline.addLast(ReadTriggerDuplexHandler.NAME, ReadTriggerDuplexHandler())
|
||||||
pipeline.addLast(MaxRequestSizeHandler.NAME, MaxRequestSizeHandler(cfg.connection.maxRequestSize))
|
pipeline.addLast(MaxRequestSizeHandler.NAME, MaxRequestSizeHandler(cfg.connection.maxRequestSize))
|
||||||
pipeline.addLast(HttpChunkContentCompressor(1024))
|
pipeline.addLast(HttpChunkContentCompressor(1024))
|
||||||
@@ -525,6 +528,7 @@ class RemoteBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun run(): ServerHandle {
|
fun run(): ServerHandle {
|
||||||
|
OtelSdkIntegration.initialize(cfg.isEnableTelemetry)
|
||||||
// Create the multithreaded event loops for the server
|
// Create the multithreaded event loops for the server
|
||||||
val bossGroup = MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory())
|
val bossGroup = MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory())
|
||||||
val channelFactory = ChannelFactory<SocketChannel> { NioSocketChannel() }
|
val channelFactory = ChannelFactory<SocketChannel> { NioSocketChannel() }
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ object Parser {
|
|||||||
var groups = emptyMap<String, Group>()
|
var groups = emptyMap<String, Group>()
|
||||||
var tls: Tls? = null
|
var tls: Tls? = null
|
||||||
val serverPath = root.renderAttribute("path")
|
val serverPath = root.renderAttribute("path")
|
||||||
|
var enableTelemetry = root.renderAttribute("enable-telemetry")
|
||||||
|
?.let(String::toBoolean) ?: false
|
||||||
var incomingConnectionsBacklogSize = 1024
|
var incomingConnectionsBacklogSize = 1024
|
||||||
var authentication: Authentication? = null
|
var authentication: Authentication? = null
|
||||||
for (child in root.asIterable()) {
|
for (child in root.asIterable()) {
|
||||||
@@ -233,6 +235,7 @@ object Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Configuration.of(
|
return Configuration.of(
|
||||||
|
enableTelemetry,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
proxyProtocolEnabled,
|
proxyProtocolEnabled,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ object Serializer {
|
|||||||
?.let { serverPath ->
|
?.let { serverPath ->
|
||||||
attr("path", serverPath)
|
attr("path", serverPath)
|
||||||
}
|
}
|
||||||
|
attr("enable-telemetry", conf.isEnableTelemetry.toString())
|
||||||
node("bind") {
|
node("bind") {
|
||||||
attr("host", conf.host)
|
attr("host", conf.host)
|
||||||
attr("port", conf.port.toString())
|
attr("port", conf.port.toString())
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package net.woggioni.rbcs.server.otel
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandler
|
||||||
|
import io.opentelemetry.api.GlobalOpenTelemetry
|
||||||
|
import io.opentelemetry.instrumentation.netty.v4_1.NettyServerTelemetry
|
||||||
|
import net.woggioni.rbcs.common.createLogger
|
||||||
|
import net.woggioni.rbcs.common.warn
|
||||||
|
|
||||||
|
object OtelIntegration {
|
||||||
|
|
||||||
|
private val log = createLogger<OtelIntegration>()
|
||||||
|
|
||||||
|
val isAvailable: Boolean by lazy {
|
||||||
|
runCatching {
|
||||||
|
Class.forName("io.opentelemetry.api.OpenTelemetry")
|
||||||
|
}.fold(
|
||||||
|
onSuccess = { true },
|
||||||
|
onFailure = {
|
||||||
|
log.warn { "OpenTelemetry classes not on classpath, instrumentation disabled" }
|
||||||
|
false
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createHandler(enabled: Boolean): ChannelHandler? {
|
||||||
|
return if (enabled && isAvailable) createHandlerInternal() else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createHandlerInternal(): ChannelHandler {
|
||||||
|
return NettyServerTelemetry.create(GlobalOpenTelemetry.get()).createCombinedHandler()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package net.woggioni.rbcs.server.otel
|
||||||
|
|
||||||
|
import net.woggioni.rbcs.common.createLogger
|
||||||
|
import net.woggioni.rbcs.common.info
|
||||||
|
|
||||||
|
object OtelSdkIntegration {
|
||||||
|
|
||||||
|
private val log = createLogger<OtelSdkIntegration>()
|
||||||
|
|
||||||
|
private val isAvailable: Boolean by lazy {
|
||||||
|
runCatching {
|
||||||
|
Class.forName("io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk")
|
||||||
|
}.fold(
|
||||||
|
onSuccess = { true },
|
||||||
|
onFailure = {
|
||||||
|
log.info { "OpenTelemetry SDK autoconfigure not on classpath" }
|
||||||
|
false
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val appenderAvailable: Boolean by lazy {
|
||||||
|
runCatching {
|
||||||
|
Class.forName("io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender")
|
||||||
|
}.fold(
|
||||||
|
onSuccess = { true },
|
||||||
|
onFailure = {
|
||||||
|
log.info { "OpenTelemetry logback appender not on classpath" }
|
||||||
|
false
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun initialize(enabled: Boolean) {
|
||||||
|
if (!enabled || !isAvailable) return
|
||||||
|
|
||||||
|
log.info { "Initializing OpenTelemetry SDK with auto-configuration" }
|
||||||
|
|
||||||
|
val sdk = io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk.builder()
|
||||||
|
.setResultAsGlobal()
|
||||||
|
.build()
|
||||||
|
.openTelemetrySdk
|
||||||
|
|
||||||
|
if (appenderAvailable) {
|
||||||
|
runCatching {
|
||||||
|
val clazz = Class.forName("io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender")
|
||||||
|
clazz.getMethod("install", Class.forName("io.opentelemetry.api.OpenTelemetry"))
|
||||||
|
.invoke(null, sdk)
|
||||||
|
log.info { "OpenTelemetry logback appender installed" }
|
||||||
|
}.onFailure { ex ->
|
||||||
|
val msg = ex.localizedMessage ?: ex.javaClass.name
|
||||||
|
log.info { "Failed to install OpenTelemetry logback appender: $msg" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info { "OpenTelemetry SDK initialized successfully" }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
<rbcs:server
|
<rbcs:server
|
||||||
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:rbcs="urn:net.woggioni.rbcs.server"
|
xmlns:rbcs="urn:net.woggioni.rbcs.server"
|
||||||
xs:schemaLocation="urn:net.woggioni.rbcs.server jpms://net.woggioni.rbcs.server/net/woggioni/rbcs/server/schema/rbcs-server.xsd">
|
xs:schemaLocation="urn:net.woggioni.rbcs.server jpms://net.woggioni.rbcs.server/net/woggioni/rbcs/server/schema/rbcs-server.xsd"
|
||||||
|
enable-telemetry="false">
|
||||||
<bind host="127.0.0.1" port="8080" incoming-connections-backlog-size="1024"/>
|
<bind host="127.0.0.1" port="8080" incoming-connections-backlog-size="1024"/>
|
||||||
<cache xs:type="rbcs:fileSystemCacheType" path="${sys:java.io.tmpdir}/rbcs" max-age="P7D"/>
|
<cache xs:type="rbcs:fileSystemCacheType" path="${sys:java.io.tmpdir}/rbcs" max-age="P7D"/>
|
||||||
</rbcs:server>
|
</rbcs:server>
|
||||||
@@ -59,6 +59,14 @@
|
|||||||
</xs:documentation>
|
</xs:documentation>
|
||||||
</xs:annotation>
|
</xs:annotation>
|
||||||
</xs:attribute>
|
</xs:attribute>
|
||||||
|
<xs:attribute name="enable-telemetry" type="xs:boolean" use="optional" default="false">
|
||||||
|
<xs:annotation>
|
||||||
|
<xs:documentation>
|
||||||
|
Enable OpenTelemetry distributed tracing for the server.
|
||||||
|
Even when enabled, telemetry only activates if OpenTelemetry classes are present on the classpath.
|
||||||
|
</xs:documentation>
|
||||||
|
</xs:annotation>
|
||||||
|
</xs:attribute>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="bindType">
|
<xs:complexType name="bindType">
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ abstract class AbstractBasicAuthServerTest : AbstractServerTest() {
|
|||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
this.cacheDir = testDir.resolve("cache")
|
this.cacheDir = testDir.resolve("cache")
|
||||||
cfg = Configuration.of(
|
cfg = Configuration.of(
|
||||||
|
false,
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
getFreePort(),
|
getFreePort(),
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ abstract class AbstractTlsServerTest : AbstractServerTest() {
|
|||||||
this.cacheDir = testDir.resolve("cache")
|
this.cacheDir = testDir.resolve("cache")
|
||||||
createKeyStoreAndTrustStore()
|
createKeyStoreAndTrustStore()
|
||||||
cfg = Configuration(
|
cfg = Configuration(
|
||||||
|
false,
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
getFreePort(),
|
getFreePort(),
|
||||||
false,
|
false,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class NoAuthServerTest : AbstractServerTest() {
|
|||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
this.cacheDir = testDir.resolve("cache")
|
this.cacheDir = testDir.resolve("cache")
|
||||||
cfg = Configuration(
|
cfg = Configuration(
|
||||||
|
false,
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
getFreePort(),
|
getFreePort(),
|
||||||
false,
|
false,
|
||||||
|
|||||||
Reference in New Issue
Block a user