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

Adoption/alpine support #164

Draft
wants to merge 15 commits into
base: merge/v0.9.0
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion bootstrap/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ kotlin {
all {
languageSettings.optIn("kotlin.ExperimentalStdlibApi")
languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
languageSettings.optIn("kotlin.time.ExperimentalTime")
languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
languageSettings.optIn("kotlinx.serialization.ExperimentalSerializationApi")
languageSettings.optIn("kotlinx.serialization.InternalSerializationApi")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ uuidVersion = 0.3.1
transmittableThreadLocalVersion = 2.12.2
shadowPluginVersion = 6.1.0

sharedLibsRef = main
sharedLibsRef = adoption/alpine-support
loggerSkipJvmTests = false
ptEmulateBigApp = false
nativeAgentLibName = drill-agent
Expand Down
3 changes: 2 additions & 1 deletion java-agent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ kotlin {
all {
languageSettings.optIn("kotlin.ExperimentalStdlibApi")
languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
languageSettings.optIn("kotlin.time.ExperimentalTime")
languageSettings.optIn("kotlin.contracts.ExperimentalContracts")
languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
languageSettings.optIn("kotlinx.serialization.ExperimentalSerializationApi")
languageSettings.optIn("kotlinx.serialization.InternalSerializationApi")
Expand All @@ -97,6 +97,7 @@ kotlin {
}
}
val jvmMain by getting {
languageSettings.optIn("kotlin.time.ExperimentalTime")
dependencies {
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
Expand Down
2 changes: 0 additions & 2 deletions java-agent/src/commonMain/kotlin/com/epam/drill/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package com.epam.drill
const val DRILL_PACKAGE = "com/epam/drill"
const val SPRING_BOOT_PREFIX = "BOOT-INF/classes/"
const val SYSTEM_CONFIG_PATH = "DRILL_AGENT_CONFIG_PATH"
const val SYSTEM_HTTP_HOOK_ENABLED = "DRILL_HTTP_HOOK_ENABLED"
const val SYSTEM_JAVA_APP_JAR = "JAVA_APP_JAR"
const val HTTP_HOOK_ENABLED = "drill.http.hook.enabled"

const val KAFKA_PRODUCER_INTERFACE = "org/apache/kafka/clients/producer/Producer"
const val KAFKA_CONSUMER_SPRING = "org/springframework/kafka/listener/KafkaMessageListenerContainer\$ListenerConsumer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
package com.epam.drill.agent

import kotlin.native.concurrent.*
import kotlin.time.*
import com.epam.drill.core.time.Duration

data class Config(
val classScanDelay: Duration = Duration.ZERO,
val classScanDelay: Duration = 0,
val isAsyncApp: Boolean = false,
val isWebApp: Boolean = false,
val isKafka: Boolean = false,
val isCadence: Boolean = false,
val isTlsApp: Boolean = false,
val webAppLoadingTimeout: Duration = Duration.seconds(1500),
val webAppLoadingTimeout: Duration = 1500000,
val webApps: List<String> = emptyList(),
val coreLibPath: String? = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import com.epam.drill.agent.serialization.*
import com.epam.drill.common.*
import com.epam.drill.common.ws.*
import com.epam.drill.core.*
import com.epam.drill.interceptor.*
import com.epam.drill.logger.*
import com.epam.drill.logger.api.*
import kotlinx.cinterop.*
import platform.posix.*
import kotlin.time.*

private val logger = Logging.logger("agent")

fun performAgentInitialization(initialParams: AgentParameters) {
val agentArguments = initialParams.parseAs<AgentArguments>()
Expand Down Expand Up @@ -62,8 +62,7 @@ fun updateConfigs(parameters: Map<String, AgentParameter>, initialParams: AgentP
?.takeIf { it.isNotBlank() }?.split(":", ",") ?: emptyList()
updateConfig {
copy(
classScanDelay = parameters[AgentArguments::classScanDelay.name]?.value
?.toLong()?.toDuration(DurationUnit.MILLISECONDS) ?: classScanDelay,
classScanDelay = parameters[AgentArguments::classScanDelay.name]?.value?.toLong() ?: classScanDelay,
isAsyncApp = parameters[AgentArguments::isAsyncApp.name]?.value.toBoolean(),
isWebApp = parameters[AgentArguments::isWebApp.name]?.value.toBoolean() || newWebApps.any(),
isKafka = parameters[AgentArguments::isKafka.name]?.value.toBoolean(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.epam.drill.agent

import kotlin.native.concurrent.*
import kotlin.time.*
import com.epam.drill.core.time.*

data class State(
val startMark: TimeMark = TimeSource.Monotonic.markNow(),
val startMark: TimeMark = TimeMark.markNow(),
val alive: Boolean = false, //true if the agent successfully received package prefixes
val webApps: Map<String, Boolean> = mapOf(),
val packagePrefixes: List<String> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.epam.drill.agent.classloading

import com.epam.drill.agent.*
import com.epam.drill.core.time.*
import com.epam.drill.logger.*
import kotlinx.coroutines.*
import kotlin.native.concurrent.*
import kotlin.time.*

actual object WebContainerSource {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.epam.drill.agent.classloading.*
import com.epam.drill.common.*
import com.epam.drill.common.serialization.*
import com.epam.drill.core.plugin.loader.*
import com.epam.drill.core.time.*
import com.epam.drill.logger.*
import com.epam.drill.plugin.*
import com.epam.drill.request.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ U| |_| |\| _ < | | \| |/__ \| |/__ |__ _| | |_| |_,-.
""".trimIndent()

object Agent : JvmtiAgent {
val isHttpHookEnabled: Boolean by lazy {
getenv(SYSTEM_HTTP_HOOK_ENABLED)?.toKString()?.toBoolean() ?: memScoped {
alloc<CPointerVar<ByteVar>>().apply {
GetSystemProperty(HTTP_HOOK_ENABLED, this.ptr)
}.value?.toKString()?.toBoolean() ?: true
}
}

override fun agentOnLoad(options: String): Int {
println(LOGO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import com.epam.drill.agent.*
import com.epam.drill.agent.classloading.source.*
import com.epam.drill.api.*
import com.epam.drill.core.callbacks.classloading.*
import com.epam.drill.core.time.*
import com.epam.drill.jvmapi.*
import com.epam.drill.jvmapi.gen.*
import com.epam.drill.logger.*
import kotlinx.cinterop.*
import kotlin.native.concurrent.*
import kotlin.time.*

@SharedImmutable
private val logger = Logging.logger("SymbolsRegister")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.epam.drill.agent.instrument.SSLTransformer.SSL_ENGINE_CLASS_NAME
import com.epam.drill.agent.instrument.http.apache.*
import com.epam.drill.agent.instrument.http.java.*
import com.epam.drill.agent.instrument.http.ok.*
import com.epam.drill.core.Agent.isHttpHookEnabled
import com.epam.drill.core.plugin.loader.*
import com.epam.drill.jvmapi.gen.*
import com.epam.drill.logger.*
Expand Down Expand Up @@ -114,21 +113,18 @@ fun classLoadEvent(
transformers += { bytes -> plugin.instrument(kClassName, bytes) }
}
}
if (!isHttpHookEnabled) {
if (kClassName.startsWith("org/apache/catalina/core/ApplicationFilterChain")) {
logger.info { "Http hook is off, starting transform tomcat class kClassName $kClassName..." }
transformers += { bytes ->
TomcatTransformer.transform(kClassName, bytes, loader, protection_domain)
}
if (kClassName.startsWith("org/apache/catalina/core/ApplicationFilterChain")) {
logger.info { "Http hook is off, starting transform tomcat class kClassName $kClassName..." }
transformers += { bytes ->
TomcatTransformer.transform(kClassName, bytes, loader, protection_domain)
}
}

strategys.forEach { strategy ->
if (strategy.permit(classReader)) {
transformers += { strategy.transform(kClassName, classBytes, loader, protection_domain) }
}
strategys.forEach { strategy ->
if (strategy.permit(classReader)) {
transformers += { strategy.transform(kClassName, classBytes, loader, protection_domain) }
}
}
// TODO Http hook does not work for Netty on linux system
if ('$' !in kClassName && kClassName.startsWith(NettyTransformer.HANDLER_CONTEXT)) {
logger.info { "Starting transform Netty class kClassName $kClassName..." }
transformers += { bytes ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.epam.drill.core.callbacks.vminit
import com.epam.drill.*
import com.epam.drill.agent.*
import com.epam.drill.core.*
import com.epam.drill.core.Agent.isHttpHookEnabled
import com.epam.drill.core.transport.*
import com.epam.drill.core.ws.*
import com.epam.drill.jvmapi.gen.*
Expand All @@ -35,12 +34,7 @@ private val logger = Logging.logger("VmInitEvent")
fun jvmtiEventVMInitEvent(env: CPointer<jvmtiEnvVar>?, jniEnv: CPointer<JNIEnvVar>?, thread: jthread?) {
initRuntimeIfNeeded()
SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, null)
if (isHttpHookEnabled) {
logger.info { "run with http hook" }
configureHttp()
} else {
logger.warn { "run without http hook" }
}
logger.warn { "run without http hook" }

config.coreLibPath?.let {
NativeRegistry.loadLibrary(it)
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ includeSharedLib("logger-test-agent")
includeSharedLib("logger")
includeSharedLib("common")
includeSharedLib("knasm")
includeSharedLib("drill-hook")
includeSharedLib("http-clients-instrumentation")
includeSharedLib("transport")
includeSharedLib("interceptor-http")
includeSharedLib("plugin-api-agent")
includeSharedLib("agent")
includeSharedLib("agent-runner-common")
Expand Down
Loading