Skip to content

Commit d1674d4

Browse files
committed
sub events
1 parent 84afd4b commit d1674d4

File tree

9 files changed

+622
-1219
lines changed

9 files changed

+622
-1219
lines changed

build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ val commonsIoVersion: String by project
2020
val auth0JwtVersion: String by project
2121
val protocolVersion: String by project
2222
val vertxVersion: String by project
23+
val graalVersion: String by project
2324

2425
group = cliGroup
2526
version = cliVersion
2627

2728
repositories {
2829
mavenCentral()
29-
jcenter()
3030
maven(url = "https://jitpack.io") { name = "jitpack" }
3131
}
3232

@@ -35,9 +35,13 @@ dependencies {
3535
implementation("com.apollographql.apollo:apollo-coroutines-support:$apolloVersion")
3636
api("com.apollographql.apollo:apollo-api:$apolloVersion")
3737

38-
implementation("com.github.sourceplusplus.protocol:protocol:$protocolVersion")
38+
implementation("com.github.sourceplusplus.protocol:protocol:724d961ceb")
3939

40+
implementation("org.slf4j:slf4j-api:1.7.32")
41+
implementation("org.slf4j:slf4j-nop:1.7.32")
4042
implementation("io.vertx:vertx-core:$vertxVersion")
43+
implementation("io.vertx:vertx-tcp-eventbus-bridge:$vertxVersion")
44+
implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion")
4145
implementation("org.apache.commons:commons-lang3:$commonsLang3Version")
4246
implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
4347
implementation("org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion")
@@ -75,7 +79,7 @@ tasks.create("createProperties") {
7579
tasks["processResources"].dependsOn("createProperties")
7680

7781
graal {
78-
//graalVersion(graalVersion.toString())
82+
graalVersion(project.properties["graalVersion"] as String)
7983
mainClass("spp.cli.Main")
8084
outputName("spp-cli")
8185
option("-H:+PrintClassInitialization")
@@ -100,7 +104,6 @@ tasks.getByName("build").dependsOn("shadowJar")
100104

101105
configurations.runtimeClasspath {
102106
exclude("ch.qos.logback", "logback-classic")
103-
exclude("org.slf4j", "slf4j-api")
104107
}
105108

106109
tasks.getByName<Test>("test") {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ protocolVersion=0.2.2
88
#SkyWalking 8.9.0-compatible
99
vertxVersion = 4.0.2
1010

11-
graalVersion = 20.2.0
11+
graalVersion = 21.3.0
1212
jacksonVersion = 2.12.5
1313
apolloVersion = 2.5.11
1414
commonsLang3Version = 3.12.0

src/main/kotlin/spp/cli/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ object Main {
6464
RemoveInstrument(),
6565
RemoveInstruments(),
6666
ClearInstruments(),
67+
SubscribeEvents(),
6768
//etc
6869
Version()
6970
).main(args)

src/main/kotlin/spp/cli/PlatformCLI.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import javax.net.ssl.X509TrustManager
3333
object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = true) {
3434

3535
val verbose by option("-v", "--verbose", help = "Enable verbose mode").flag()
36-
private val platformHost: String by option("-p", "--platform", help = "Source++ platform host")
36+
val platformHost: String by option("-p", "--platform", help = "Source++ platform host")
3737
.default(
3838
(if (System.getenv("SPP_DISABLE_TLS") != "true") "https://" else "http://")
3939
+ (System.getenv("SPP_PLATFORM_HOST") ?: "localhost") + ":5445"
@@ -44,6 +44,17 @@ object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = t
4444
.default(File("config/spp-platform.key"))
4545
private val accessToken by option("-a", "--access-token", help = "Developer access token")
4646
val apolloClient: ApolloClient by lazy { connectToPlatform() }
47+
val certFingerprint: String? by lazy {
48+
if (platformCertificate.exists()) {
49+
val crtFileData = platformCertificate.readText()
50+
val crtParser = PEMParser(StringReader(crtFileData))
51+
val crtHolder = crtParser.readObject() as X509CertificateHolder
52+
val certificate = JcaX509CertificateConverter().getCertificate(crtHolder)!!
53+
fingerprint(certificate)
54+
} else {
55+
null
56+
}
57+
}
4758

4859
override fun run() = Unit
4960

@@ -54,15 +65,6 @@ object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = t
5465
"https://$platformHost"
5566
}
5667

57-
var certFingerprint: String? = null
58-
if (platformCertificate.exists()) {
59-
val crtFileData = platformCertificate.readText()
60-
val crtParser = PEMParser(StringReader(crtFileData))
61-
val crtHolder = crtParser.readObject() as X509CertificateHolder
62-
val certificate = JcaX509CertificateConverter().getCertificate(crtHolder)!!
63-
certFingerprint = fingerprint(certificate)
64-
}
65-
6668
val httpClient = if (certFingerprint != null) {
6769
OkHttpClient().newBuilder()
6870
.hostnameVerifier { _, _ -> true }
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package spp.cli.commands.instrument
2+
3+
import com.github.ajalt.clikt.core.CliktCommand
4+
import com.github.ajalt.clikt.parameters.arguments.argument
5+
import com.github.ajalt.clikt.parameters.arguments.multiple
6+
import com.github.ajalt.clikt.parameters.options.flag
7+
import com.github.ajalt.clikt.parameters.options.option
8+
import eu.geekplace.javapinning.JavaPinning
9+
import eu.geekplace.javapinning.pin.Pin
10+
import io.vertx.core.Vertx
11+
import io.vertx.core.json.Json
12+
import io.vertx.core.json.JsonObject
13+
import io.vertx.core.net.NetClientOptions
14+
import io.vertx.core.net.TrustOptions
15+
import io.vertx.ext.bridge.BridgeEventType
16+
import io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameHelper
17+
import io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser
18+
import io.vertx.kotlin.coroutines.await
19+
import kotlinx.coroutines.runBlocking
20+
import spp.cli.PlatformCLI
21+
import spp.protocol.SourceMarkerServices
22+
import spp.protocol.extend.TCPServiceFrameParser
23+
import spp.protocol.instrument.LiveInstrumentEvent
24+
25+
class SubscribeEvents : CliktCommand(
26+
help = "Listens for and outputs live events. Subscribes to all events by default"
27+
) {
28+
29+
val instrumentIds by argument(
30+
name = "Instrument IDs",
31+
help = "Capture events from specific live instruments"
32+
).multiple()
33+
val includeBreakpoints by option("--breakpoints", "-b", help = "Include live breakpoint events")
34+
.flag(default = false)
35+
val includeLogs by option("--logs", "-l", help = "Include live log events")
36+
.flag(default = false)
37+
val includeMetrics by option("--metrics", "-m", help = "Include live metric events")
38+
.flag(default = false)
39+
val includeTraces by option("--traces", "-t", help = "Include live trace events")
40+
.flag(default = false)
41+
42+
override fun run() {
43+
if (!includeBreakpoints && !includeLogs && !includeMetrics && !includeTraces) {
44+
//listen for all events
45+
} else {
46+
//listen for specific events
47+
}
48+
49+
var eventCount = 1
50+
runBlocking {
51+
val vertx = Vertx.vertx()
52+
val client = if (PlatformCLI.certFingerprint != null) {
53+
val options = NetClientOptions()
54+
.setReconnectAttempts(Int.MAX_VALUE).setReconnectInterval(5000)
55+
.setSsl(PlatformCLI.platformHost.startsWith("https"))
56+
.setTrustOptions(
57+
TrustOptions.wrap(
58+
JavaPinning.trustManagerForPins(listOf(Pin.fromString("CERTSHA256:${PlatformCLI.certFingerprint}")))
59+
)
60+
)
61+
vertx.createNetClient(options)
62+
} else {
63+
val options = NetClientOptions()
64+
.setReconnectAttempts(Int.MAX_VALUE).setReconnectInterval(5000)
65+
.setSsl(PlatformCLI.platformHost.startsWith("https"))
66+
vertx.createNetClient(options)
67+
}
68+
val socket = client.connect(
69+
5455,
70+
PlatformCLI.platformHost.substringAfter("https://").substringAfter("http://")
71+
.substringBefore(":")
72+
).await()
73+
socket!!.handler(FrameParser(TCPServiceFrameParser(vertx, socket)))
74+
75+
vertx.eventBus().consumer<JsonObject>("local." + SourceMarkerServices.Provide.LIVE_INSTRUMENT_SUBSCRIBER) {
76+
val event = Json.decodeValue(it.body().toString(), LiveInstrumentEvent::class.java)
77+
println(
78+
"\nEvent (${eventCount++}):\n" +
79+
"\tType: ${event.eventType}\n" +
80+
"\tData: ${event.data}"
81+
)
82+
}
83+
84+
//register listener
85+
FrameHelper.sendFrame(
86+
BridgeEventType.REGISTER.name.toLowerCase(),
87+
SourceMarkerServices.Provide.LIVE_INSTRUMENT_SUBSCRIBER,
88+
JsonObject(),
89+
socket
90+
)
91+
println("Listening for events...")
92+
}
93+
}
94+
}
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
[]
1+
[
2+
{
3+
"name":"java.lang.Boolean",
4+
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]}
5+
,
6+
{
7+
"name":"java.lang.ClassLoader",
8+
"methods":[
9+
{"name":"getPlatformClassLoader","parameterTypes":[] },
10+
{"name":"loadClass","parameterTypes":["java.lang.String"] }
11+
]}
12+
,
13+
{
14+
"name":"jdk.internal.loader.ClassLoaders$PlatformClassLoader"}
15+
,
16+
{
17+
"name":"org.graalvm.nativebridge.jni.JNIExceptionWrapperEntryPoints",
18+
"methods":[{"name":"getClassName","parameterTypes":["java.lang.Class"] }]}
19+
,
20+
{
21+
"name":"sun.management.VMManagementImpl",
22+
"fields":[
23+
{"name":"compTimeMonitoringSupport"},
24+
{"name":"currentThreadCpuTimeSupport"},
25+
{"name":"objectMonitorUsageSupport"},
26+
{"name":"otherThreadCpuTimeSupport"},
27+
{"name":"remoteDiagnosticCommandsSupport"},
28+
{"name":"synchronizerUsageSupport"},
29+
{"name":"threadAllocatedMemorySupport"},
30+
{"name":"threadContentionMonitoringSupport"}
31+
]}
32+
33+
]
Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
1-
Args = -H:ReflectionConfigurationResources=${.}/reflect-config.json \
2-
--report-unsupported-elements-at-runtime \
3-
--no-fallback \
4-
--enable-http \
1+
Args = --enable-http \
52
--enable-https \
63
--allow-incomplete-classpath \
74
--enable-all-security-services \
8-
--initialize-at-run-time=\
9-
org.bouncycastle.crypto.prng.SP800SecureRandom\
10-
,org.bouncycastle.jcajce.provider.drbg.DRBG$Default\
11-
,org.bouncycastle.jcajce.provider.drbg.DRBG$NonceAndIV
5+
-H:EnableURLProtocols=http,https \
6+
--report-unsupported-elements-at-runtime \
7+
-H:ReflectionConfigurationResources=${.}/reflect-config.json \
8+
-H:JNIConfigurationResources=${.}/jni-config.json \
9+
-H:ResourceConfigurationResources=${.}/resource-config.json \
10+
--initialize-at-build-time=org.slf4j.LoggerFactory,\
11+
org.slf4j.impl.StaticLoggerBinder,\
12+
org.slf4j.LoggerFactory,\
13+
org.slf4j.impl.StaticLoggerBinder$ \
14+
--initialize-at-run-time=io.netty.channel.DefaultChannelId,\
15+
io.vertx.core.buffer.impl.PartialPooledByteBufAllocator,\
16+
io.netty.util.NetUtil,\
17+
io.netty.channel.socket.InternetProtocolFamily,\
18+
io.netty.resolver.HostsFileEntriesResolver,\
19+
io.netty.resolver.dns.DnsNameResolver,\
20+
io.netty.resolver.dns.DnsServerAddressStreamProviders,\
21+
io.netty.resolver.dns.PreferredAddressTypeComparator\$1,\
22+
io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider,\
23+
io.vertx.core.impl.AddressResolver,\
24+
io.vertx.core.dns.AddressResolverOptions,\
25+
io.netty.handler.codec.http.websocketx.extensions.compression.DeflateEncoder,\
26+
io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder,\
27+
io.netty.handler.codec.http.HttpObjectEncoder,\
28+
io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,\
29+
io.netty.handler.codec.http2.Http2CodecUtil,\
30+
io.netty.handler.codec.http2.Http2ConnectionHandler,\
31+
io.netty.handler.codec.http2.DefaultHttp2FrameWriter,\
32+
io.netty.util.internal.logging.Log4JLogger,\
33+
io.netty.handler.ssl.ReferenceCountedOpenSslServerContext,\
34+
io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,\
35+
io.netty.handler.ssl.ReferenceCountedOpenSslEngine,\
36+
io.netty.handler.ssl.ConscryptAlpnSslEngine,\
37+
io.netty.handler.ssl.JettyNpnSslEngine,\
38+
io.netty.handler.ssl.JettyAlpnSslEngine$ClientEngine,\
39+
io.netty.handler.ssl.JettyAlpnSslEngine$ServerEngine,\
40+
io.netty.handler.ssl.ReferenceCountedOpenSslContext,\
41+
io.netty.handler.ssl.ReferenceCountedOpenSslClientContext,\
42+
io.netty.buffer.ByteBufUtil$HexUtil,\
43+
io.vertx.core.buffer.impl.VertxByteBufAllocator,\
44+
io.vertx.core.net.impl.transport.EpollTransport,\
45+
io.vertx.core.net.impl.transport.KQueueTransport,\
46+
io.vertx.core.http.impl.VertxHttp2ClientUpgradeCodec,\
47+
io.netty.resolver.dns.DnsServerAddressStreamProviders$DefaultProviderHolder,\
48+
io.vertx.core.eventbus.impl.clustered.ClusteredEventBus,\
49+
io.netty.channel.unix,\
50+
io.netty.channel.epoll,\
51+
io.netty.buffer.ByteBufUtil$HexUtil

0 commit comments

Comments
 (0)