From 901b7305fd71c14e78154974a470388ef586a571 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 26 Feb 2022 21:54:35 +0100 Subject: [PATCH 01/26] test --- .../kotlin/spp/protocol/ProtocolMarshaller.kt | 23 ++-- .../spp/protocol/ProtocolMarshallerTest.kt | 101 ++++++++++++++++++ 2 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt diff --git a/src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt index 19abd59f..616aebba 100644 --- a/src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt @@ -107,17 +107,7 @@ object ProtocolMarshaller { @JvmStatic fun serializeLiveInstrument(value: LiveInstrument): JsonObject { - val valueObject = JsonObject(Json.encode(value)) - //todo: don't use graalvm anymore, remove this - //force persistence of "type" as graalvm's native-image drops it for some reason - when (value) { - is LiveBreakpoint -> valueObject.put("type", LiveInstrumentType.BREAKPOINT.name) - is LiveLog -> valueObject.put("type", LiveInstrumentType.LOG.name) - is LiveMeter -> valueObject.put("type", LiveInstrumentType.METER.name) - is LiveSpan -> valueObject.put("type", LiveInstrumentType.SPAN.name) - else -> throw UnsupportedOperationException("Live instrument: $value") - } - return valueObject + return JsonObject(Json.encode(value)) } @JvmStatic @@ -260,7 +250,16 @@ object ProtocolMarshaller { fun deserializeLiveInstrumentRemoved(value: JsonObject): LiveInstrumentRemoved { return LiveInstrumentRemoved( deserializeLiveInstrument(value.getJsonObject("liveInstrument")), - Instant.fromEpochMilliseconds(value.getLong("occurredAt")), + value.let { + if (it.getValue("occurredAt") is Number) { + Instant.fromEpochMilliseconds(value.getLong("occurredAt")) + } else { + Instant.fromEpochSeconds( + value.getJsonObject("occurredAt").getLong("epochSeconds"), + value.getJsonObject("occurredAt").getInteger("nanosecondsOfSecond") + ) + } + }, value.getJsonObject("cause")?.let { Json.decodeValue(it.toString(), LiveStackTrace::class.java) } ) } diff --git a/src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt b/src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt new file mode 100644 index 00000000..c36722ab --- /dev/null +++ b/src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt @@ -0,0 +1,101 @@ +package spp.protocol + +import kotlinx.datetime.Clock +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import spp.protocol.artifact.exception.LiveStackTrace +import spp.protocol.instrument.LiveBreakpoint +import spp.protocol.instrument.LiveLog +import spp.protocol.instrument.LiveMeter +import spp.protocol.instrument.LiveSourceLocation +import spp.protocol.instrument.command.CommandType +import spp.protocol.instrument.command.LiveInstrumentCommand +import spp.protocol.instrument.event.LiveInstrumentRemoved +import spp.protocol.instrument.meter.MeterType +import spp.protocol.instrument.meter.MetricValue +import spp.protocol.instrument.meter.MetricValueType +import spp.protocol.instrument.throttle.InstrumentThrottle +import spp.protocol.instrument.throttle.ThrottleStep + +@RunWith(JUnit4::class) +class ProtocolMarshallerTest { + + @Test + fun testLiveInstrument() { + val liveInstrument = LiveMeter( + "meterName", + MeterType.COUNT, + MetricValue(MetricValueType.NUMBER, "1"), + LiveSourceLocation("source", 1), + "condition", + System.currentTimeMillis(), + 1, + "id", + applyImmediately = false, + applied = true, + pending = false, + InstrumentThrottle(5, ThrottleStep.SECOND), + mapOf("key" to "value") + ) + + val serialized = ProtocolMarshaller.serializeLiveInstrument(liveInstrument) + val deserialized = ProtocolMarshaller.deserializeLiveInstrument(serialized) + assertEquals(liveInstrument, deserialized) + } + + @Test + fun testLiveInstrumentCommand() { + val liveInstrumentCommand = LiveInstrumentCommand( + CommandType.ADD_LIVE_INSTRUMENT, + setOf( + LiveBreakpoint( + LiveSourceLocation("source", 1), + "condition", + System.currentTimeMillis(), + 1, + "id", + applyImmediately = false, + applied = true, + pending = false, + InstrumentThrottle(5, ThrottleStep.SECOND), + mapOf("key" to "value") + ) + ), + setOf( + LiveSourceLocation("source", 1) + ) + ) + + val serialized = ProtocolMarshaller.serializeLiveInstrumentCommand(liveInstrumentCommand) + val deserialized = ProtocolMarshaller.deserializeLiveInstrumentCommand(serialized) + assertEquals(liveInstrumentCommand, deserialized) + } + + @Test + fun testLiveInstrumentRemoved() { + val liveInstrumentRemoved = LiveInstrumentRemoved( + LiveLog( + "log {}", + listOf("foo"), + LiveSourceLocation("source", 2), + "foo == bar", + System.currentTimeMillis(), + 2, + "id", + applyImmediately = true, + applied = false, + pending = true, + InstrumentThrottle(1, ThrottleStep.DAY), + mapOf("key2" to "value2") + ), + Clock.System.now(), + LiveStackTrace("exception", "message", mutableListOf()) + ) + + val serialized = ProtocolMarshaller.serializeLiveInstrumentRemoved(liveInstrumentRemoved) + val deserialized = ProtocolMarshaller.deserializeLiveInstrumentRemoved(serialized) + assertEquals(liveInstrumentRemoved, deserialized) + } +} \ No newline at end of file From 78dd4875b5c84c744d4a0d4094e2fd9ea42e795c Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 26 Feb 2022 23:51:00 +0100 Subject: [PATCH 02/26] refactor --- .../{util => marshall}/KSerializers.kt | 2 +- .../{util => marshall}/LocalMessageCodec.kt | 2 +- .../{ => marshall}/ProtocolMarshaller.kt | 2 +- .../ServiceExceptionConverter.kt | 2 +- .../META-INF/vertx/json-mappers.properties | 56 +++++++++---------- .../{ => marshall}/ProtocolMarshallerTest.kt | 2 +- 6 files changed, 33 insertions(+), 33 deletions(-) rename src/jvmMain/kotlin/spp/protocol/{util => marshall}/KSerializers.kt (98%) rename src/jvmMain/kotlin/spp/protocol/{util => marshall}/LocalMessageCodec.kt (97%) rename src/jvmMain/kotlin/spp/protocol/{ => marshall}/ProtocolMarshaller.kt (99%) rename src/jvmMain/kotlin/spp/protocol/{util => marshall}/ServiceExceptionConverter.kt (98%) rename src/jvmTest/kotlin/spp/protocol/{ => marshall}/ProtocolMarshallerTest.kt (99%) diff --git a/src/jvmMain/kotlin/spp/protocol/util/KSerializers.kt b/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt similarity index 98% rename from src/jvmMain/kotlin/spp/protocol/util/KSerializers.kt rename to src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt index 3aa753a3..a509446b 100644 --- a/src/jvmMain/kotlin/spp/protocol/util/KSerializers.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package spp.protocol.util +package spp.protocol.marshall import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonParser diff --git a/src/jvmMain/kotlin/spp/protocol/util/LocalMessageCodec.kt b/src/jvmMain/kotlin/spp/protocol/marshall/LocalMessageCodec.kt similarity index 97% rename from src/jvmMain/kotlin/spp/protocol/util/LocalMessageCodec.kt rename to src/jvmMain/kotlin/spp/protocol/marshall/LocalMessageCodec.kt index acd1b8d0..23ca470a 100644 --- a/src/jvmMain/kotlin/spp/protocol/util/LocalMessageCodec.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/LocalMessageCodec.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package spp.protocol.util +package spp.protocol.marshall import io.vertx.core.buffer.Buffer import io.vertx.core.eventbus.MessageCodec diff --git a/src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt similarity index 99% rename from src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt rename to src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index 616aebba..099c1e71 100644 --- a/src/jvmMain/kotlin/spp/protocol/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package spp.protocol +package spp.protocol.marshall import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.SerializationFeature diff --git a/src/jvmMain/kotlin/spp/protocol/util/ServiceExceptionConverter.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ServiceExceptionConverter.kt similarity index 98% rename from src/jvmMain/kotlin/spp/protocol/util/ServiceExceptionConverter.kt rename to src/jvmMain/kotlin/spp/protocol/marshall/ServiceExceptionConverter.kt index 679996f8..6fbb2085 100644 --- a/src/jvmMain/kotlin/spp/protocol/util/ServiceExceptionConverter.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ServiceExceptionConverter.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package spp.protocol.util +package spp.protocol.marshall import io.vertx.serviceproxy.ServiceException import spp.protocol.service.error.LiveInstrumentException diff --git a/src/jvmMain/resources/META-INF/vertx/json-mappers.properties b/src/jvmMain/resources/META-INF/vertx/json-mappers.properties index 6c4b1707..1773468b 100644 --- a/src/jvmMain/resources/META-INF/vertx/json-mappers.properties +++ b/src/jvmMain/resources/META-INF/vertx/json-mappers.properties @@ -1,28 +1,28 @@ -spp.protocol.artifact.ArtifactQualifiedName.serializer=spp.protocol.ProtocolMarshaller#serializeArtifactQualifiedName -spp.protocol.artifact.ArtifactQualifiedName.deserializer=spp.protocol.ProtocolMarshaller#deserializeArtifactQualifiedName -spp.protocol.artifact.trace.TraceResult.serializer=spp.protocol.ProtocolMarshaller#serializeTraceResult -spp.protocol.artifact.trace.TraceResult.deserializer=spp.protocol.ProtocolMarshaller#deserializeTraceResult -kotlinx.datetime.Instant.serializer=spp.protocol.ProtocolMarshaller#serializeInstant -kotlinx.datetime.Instant.deserializer=spp.protocol.ProtocolMarshaller#deserializeInstant -spp.protocol.artifact.log.LogCountSummary.serializer=spp.protocol.ProtocolMarshaller#serializeLogCountSummary -spp.protocol.artifact.log.LogCountSummary.deserializer=spp.protocol.ProtocolMarshaller#deserializeLogCountSummary -spp.protocol.instrument.LiveInstrument.serializer=spp.protocol.ProtocolMarshaller#serializeLiveInstrument -spp.protocol.instrument.LiveInstrument.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveInstrument -spp.protocol.instrument.LiveSourceLocation.serializer=spp.protocol.ProtocolMarshaller#serializeLiveSourceLocation -spp.protocol.instrument.LiveSourceLocation.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveSourceLocation -spp.protocol.instrument.LiveBreakpoint.serializer=spp.protocol.ProtocolMarshaller#serializeLiveBreakpoint -spp.protocol.instrument.LiveBreakpoint.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveBreakpoint -spp.protocol.instrument.LiveLog.serializer=spp.protocol.ProtocolMarshaller#serializeLiveLog -spp.protocol.instrument.LiveLog.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveLog -spp.protocol.instrument.LiveMeter.serializer=spp.protocol.ProtocolMarshaller#serializeLiveMeter -spp.protocol.instrument.LiveMeter.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveMeter -spp.protocol.instrument.LiveSpan.serializer=spp.protocol.ProtocolMarshaller#serializeLiveSpan -spp.protocol.instrument.LiveSpan.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveSpan -spp.protocol.view.LiveViewSubscription.serializer=spp.protocol.ProtocolMarshaller#serializeLiveViewSubscription -spp.protocol.view.LiveViewSubscription.deserializer=spp.protocol.ProtocolMarshaller#deserializeLiveViewSubscription -spp.protocol.platform.developer.SelfInfo.serializer=spp.protocol.ProtocolMarshaller#serializeSelfInfo -spp.protocol.platform.developer.SelfInfo.deserializer=spp.protocol.ProtocolMarshaller#deserializeSelfInfo -spp.protocol.platform.general.Service.serializer=spp.protocol.ProtocolMarshaller#serializeService -spp.protocol.platform.general.Service.deserializer=spp.protocol.ProtocolMarshaller#deserializeService -spp.protocol.platform.status.ActiveInstance.serializer=spp.protocol.ProtocolMarshaller#serializeActiveInstance -spp.protocol.platform.status.ActiveInstance.deserializer=spp.protocol.ProtocolMarshaller#deserializeActiveInstance \ No newline at end of file +spp.protocol.artifact.ArtifactQualifiedName.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeArtifactQualifiedName +spp.protocol.artifact.ArtifactQualifiedName.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeArtifactQualifiedName +spp.protocol.artifact.trace.TraceResult.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeTraceResult +spp.protocol.artifact.trace.TraceResult.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeTraceResult +kotlinx.datetime.Instant.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeInstant +kotlinx.datetime.Instant.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeInstant +spp.protocol.artifact.log.LogCountSummary.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLogCountSummary +spp.protocol.artifact.log.LogCountSummary.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLogCountSummary +spp.protocol.instrument.LiveInstrument.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveInstrument +spp.protocol.instrument.LiveInstrument.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveInstrument +spp.protocol.instrument.LiveSourceLocation.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveSourceLocation +spp.protocol.instrument.LiveSourceLocation.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveSourceLocation +spp.protocol.instrument.LiveBreakpoint.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveBreakpoint +spp.protocol.instrument.LiveBreakpoint.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveBreakpoint +spp.protocol.instrument.LiveLog.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveLog +spp.protocol.instrument.LiveLog.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveLog +spp.protocol.instrument.LiveMeter.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveMeter +spp.protocol.instrument.LiveMeter.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveMeter +spp.protocol.instrument.LiveSpan.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveSpan +spp.protocol.instrument.LiveSpan.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveSpan +spp.protocol.view.LiveViewSubscription.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveViewSubscription +spp.protocol.view.LiveViewSubscription.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveViewSubscription +spp.protocol.platform.developer.SelfInfo.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeSelfInfo +spp.protocol.platform.developer.SelfInfo.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeSelfInfo +spp.protocol.platform.general.Service.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeService +spp.protocol.platform.general.Service.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeService +spp.protocol.platform.status.ActiveInstance.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeActiveInstance +spp.protocol.platform.status.ActiveInstance.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeActiveInstance \ No newline at end of file diff --git a/src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt b/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt similarity index 99% rename from src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt rename to src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt index c36722ab..0427d9bc 100644 --- a/src/jvmTest/kotlin/spp/protocol/ProtocolMarshallerTest.kt +++ b/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt @@ -1,4 +1,4 @@ -package spp.protocol +package spp.protocol.marshall import kotlinx.datetime.Clock import org.junit.Assert.assertEquals From d2dcde93def4236bddbca490877664f7aeacb287 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 27 Feb 2022 00:03:26 +0100 Subject: [PATCH 03/26] only plugin uses --- .../kotlin/spp/protocol/marshall/ProtocolMarshaller.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index 099c1e71..0c835ea4 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -19,10 +19,6 @@ package spp.protocol.marshall import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.SerializationFeature -import com.fasterxml.jackson.datatype.guava.GuavaModule -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule -import com.fasterxml.jackson.module.kotlin.KotlinModule import io.vertx.core.Vertx import io.vertx.core.buffer.Buffer import io.vertx.core.eventbus.MessageCodec @@ -54,10 +50,6 @@ import java.util.* object ProtocolMarshaller { init { try { - DatabindCodec.mapper().registerModule(GuavaModule()) - DatabindCodec.mapper().registerModule(Jdk8Module()) - DatabindCodec.mapper().registerModule(JavaTimeModule()) - DatabindCodec.mapper().registerModule(KotlinModule()) DatabindCodec.mapper().enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) DatabindCodec.mapper().enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING) DatabindCodec.mapper().enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL) From c7dab19dc1390e0465306a590b8df385a61be957 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 27 Feb 2022 12:01:19 +0100 Subject: [PATCH 04/26] use protocol marshaller --- .../protocol/marshall/ProtocolMarshaller.kt | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index 0c835ea4..541f9546 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -19,15 +19,13 @@ package spp.protocol.marshall import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.SerializationFeature -import io.vertx.core.Vertx -import io.vertx.core.buffer.Buffer -import io.vertx.core.eventbus.MessageCodec import io.vertx.core.json.Json import io.vertx.core.json.JsonObject import io.vertx.core.json.jackson.DatabindCodec import kotlinx.datetime.Instant import spp.protocol.artifact.ArtifactQualifiedName import spp.protocol.artifact.exception.LiveStackTrace +import spp.protocol.artifact.exception.LiveStackTraceElement import spp.protocol.artifact.log.LogCountSummary import spp.protocol.artifact.trace.TraceResult import spp.protocol.instrument.* @@ -35,11 +33,11 @@ import spp.protocol.instrument.command.CommandType import spp.protocol.instrument.command.LiveInstrumentCommand import spp.protocol.instrument.event.LiveBreakpointHit import spp.protocol.instrument.event.LiveInstrumentRemoved +import spp.protocol.instrument.variable.LiveVariable import spp.protocol.platform.developer.SelfInfo import spp.protocol.platform.general.Service import spp.protocol.platform.status.ActiveInstance import spp.protocol.view.LiveViewSubscription -import java.util.* /** * Used for marshalling and unmarshalling protocol messages. @@ -257,30 +255,58 @@ object ProtocolMarshaller { } @JvmStatic - fun setupCodecs(vertx: Vertx) { - vertx.eventBus().registerDefaultCodec(LiveBreakpointHit::class.java, ProtocolMessageCodec()) + fun serializeLiveVariable(value: LiveVariable): JsonObject { + return JsonObject(Json.encode(value)) } - class ProtocolMessageCodec : MessageCodec { - override fun encodeToWire(buffer: Buffer?, s: T?) { - val value = Json.encode(s).toByteArray() - buffer?.appendInt(value.size) - buffer?.appendBytes(value) - } + @JvmStatic + fun deserializeLiveVariable(value: JsonObject): LiveVariable { + return value.mapTo(LiveVariable::class.java) + } - override fun decodeFromWire(pos: Int, buffer: Buffer?): T? { - val len = buffer?.getInt(pos) ?: return null - val bytes = buffer.getBytes(pos + 4, pos + 4 + len) - return cast(Json.decodeValue(String(bytes))) - } + @JvmStatic + fun serializeLiveStackTraceElement(value: LiveStackTraceElement): JsonObject { + return JsonObject(Json.encode(value)) + } - @Suppress("UNCHECKED_CAST") - private fun cast(obj: Any?): T? { - return obj as? T - } + @JvmStatic + fun deserializeLiveStackTraceElement(value: JsonObject): LiveStackTraceElement { + return value.mapTo(LiveStackTraceElement::class.java) + } + + @JvmStatic + fun serializeLiveStackTrace(value: LiveStackTrace): JsonObject { + return JsonObject(Json.encode(value)) + } + + @JvmStatic + fun deserializeLiveStackTrace(value: JsonObject): LiveStackTrace { + return value.mapTo(LiveStackTrace::class.java) + } + + @JvmStatic + fun serializeLiveBreakpointHit(value: LiveBreakpointHit): JsonObject { + return JsonObject(Json.encode(value)) + } - override fun transform(o: T): T = o - override fun name(): String = UUID.randomUUID().toString() - override fun systemCodecID(): Byte = -1 + @JvmStatic + fun deserializeLiveBreakpointHit(value: JsonObject): LiveBreakpointHit { + return LiveBreakpointHit( + value.getString("breakpointId"), + value.getString("traceId"), + value.let { + if (it.getValue("occurredAt") is Number) { + Instant.fromEpochMilliseconds(value.getLong("occurredAt")) + } else { + Instant.fromEpochSeconds( + value.getJsonObject("occurredAt").getLong("epochSeconds"), + value.getJsonObject("occurredAt").getInteger("nanosecondsOfSecond") + ) + } + }, + value.getString("serviceInstance"), + value.getString("service"), + deserializeLiveStackTrace(value.getJsonObject("stackTrace")) + ) } } From 473051b4e5cabf6226a04c1224dcec94d376af7d Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 27 Feb 2022 12:02:06 +0100 Subject: [PATCH 05/26] use protocol marshaller --- .../resources/META-INF/vertx/json-mappers.properties | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jvmMain/resources/META-INF/vertx/json-mappers.properties b/src/jvmMain/resources/META-INF/vertx/json-mappers.properties index 1773468b..99f7b50c 100644 --- a/src/jvmMain/resources/META-INF/vertx/json-mappers.properties +++ b/src/jvmMain/resources/META-INF/vertx/json-mappers.properties @@ -25,4 +25,8 @@ spp.protocol.platform.developer.SelfInfo.deserializer=spp.protocol.marshall.Prot spp.protocol.platform.general.Service.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeService spp.protocol.platform.general.Service.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeService spp.protocol.platform.status.ActiveInstance.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeActiveInstance -spp.protocol.platform.status.ActiveInstance.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeActiveInstance \ No newline at end of file +spp.protocol.platform.status.ActiveInstance.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeActiveInstance +spp.protocol.instrument.event.LiveInstrumentRemoved.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveInstrumentRemoved +spp.protocol.instrument.event.LiveInstrumentRemoved.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveInstrumentRemoved +spp.protocol.instrument.event.LiveBreakpointHit.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveBreakpointHit +spp.protocol.instrument.event.LiveBreakpointHit.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveBreakpointHit \ No newline at end of file From 8f19b74aec5c27f3185148b3620f93756cf92de8 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 27 Feb 2022 13:39:04 +0100 Subject: [PATCH 06/26] test --- .../marshall/ProtocolMarshallerTest.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt b/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt index 0427d9bc..ad4458a7 100644 --- a/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt +++ b/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt @@ -6,18 +6,22 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import spp.protocol.artifact.exception.LiveStackTrace +import spp.protocol.artifact.exception.LiveStackTraceElement import spp.protocol.instrument.LiveBreakpoint import spp.protocol.instrument.LiveLog import spp.protocol.instrument.LiveMeter import spp.protocol.instrument.LiveSourceLocation import spp.protocol.instrument.command.CommandType import spp.protocol.instrument.command.LiveInstrumentCommand +import spp.protocol.instrument.event.LiveBreakpointHit import spp.protocol.instrument.event.LiveInstrumentRemoved import spp.protocol.instrument.meter.MeterType import spp.protocol.instrument.meter.MetricValue import spp.protocol.instrument.meter.MetricValueType import spp.protocol.instrument.throttle.InstrumentThrottle import spp.protocol.instrument.throttle.ThrottleStep +import spp.protocol.instrument.variable.LiveVariable +import spp.protocol.instrument.variable.LiveVariableScope @RunWith(JUnit4::class) class ProtocolMarshallerTest { @@ -98,4 +102,63 @@ class ProtocolMarshallerTest { val deserialized = ProtocolMarshaller.deserializeLiveInstrumentRemoved(serialized) assertEquals(liveInstrumentRemoved, deserialized) } + + @Test + fun testLiveBreakpointHit() { + val liveBreakpointHit = LiveBreakpointHit( + "breakpointId", + "traceId", + Clock.System.now(), + "serviceInstance", + "service", + LiveStackTrace( + "exception", + "message", + mutableListOf( + LiveStackTraceElement( + "method", + "source", + mutableListOf( + LiveVariable( + "name", + "value", + 1, + LiveVariableScope.GLOBAL_VARIABLE, + "liveClazz", + "liveIdentity", + "presentation" + ) + ), + "sourceCode" + ) + ), + LiveStackTrace( + "exception", + "message", + mutableListOf( + LiveStackTraceElement( + "method", + "source", + mutableListOf( + LiveVariable( + "name", + "value", + 1, + LiveVariableScope.GLOBAL_VARIABLE, + "liveClazz", + "liveIdentity", + "presentation" + ) + ), + "sourceCode" + ) + ) + ) + ) + ) + + val serialized = ProtocolMarshaller.serializeLiveBreakpointHit(liveBreakpointHit) + val deserialized = ProtocolMarshaller.deserializeLiveBreakpointHit(serialized) + assertEquals(liveBreakpointHit, deserialized) + } } \ No newline at end of file From 2bd4bea9ad6b2197f21717c1a74b21be96e82443 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 27 Feb 2022 21:33:20 +0100 Subject: [PATCH 07/26] remove Serializable with --- .../kotlin/spp.protocol/Serializers.kt | 67 ------------------- .../artifact/ArtifactQualifiedName.kt | 2 - .../kotlin/spp.protocol/artifact/log/Log.kt | 2 - .../artifact/log/LogCountSummary.kt | 2 - .../spp.protocol/artifact/log/LogResult.kt | 2 - .../artifact/metrics/ArtifactMetricResult.kt | 3 - .../spp.protocol/artifact/trace/Trace.kt | 2 - .../artifact/trace/TraceResult.kt | 3 - .../spp.protocol/artifact/trace/TraceSpan.kt | 3 - .../artifact/trace/TraceSpanLogEntry.kt | 2 - .../instrument/event/LiveBreakpointHit.kt | 2 - .../instrument/event/LiveInstrumentRemoved.kt | 2 - .../instrument/event/LiveLogHit.kt | 2 - .../protocol/artifact/trace/TraceStackTest.kt | 38 ----------- 14 files changed, 132 deletions(-) delete mode 100644 src/commonMain/kotlin/spp.protocol/Serializers.kt diff --git a/src/commonMain/kotlin/spp.protocol/Serializers.kt b/src/commonMain/kotlin/spp.protocol/Serializers.kt deleted file mode 100644 index 391ec114..00000000 --- a/src/commonMain/kotlin/spp.protocol/Serializers.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Source++, the open-source live coding platform. - * Copyright (C) 2022 CodeBrig, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package spp.protocol - -import kotlinx.datetime.Instant -import kotlinx.serialization.KSerializer -import kotlinx.serialization.descriptors.PrimitiveKind -import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import spp.protocol.artifact.ArtifactType - -/** - * Used to serialize/deserialize protocol messages. - * - * @since 0.1.0 - * @author [Brandon Fergerson](mailto:bfergerson@apache.org) - */ -class Serializers { - - /** - * Used to serialize/deserialize [Instant] classes. - * - * @since 0.1.0 - */ - class InstantKSerializer : KSerializer { - - override val descriptor = PrimitiveSerialDescriptor( - "spp.protocol.InstantKSerializer", - PrimitiveKind.LONG - ) - - override fun deserialize(decoder: Decoder) = Instant.fromEpochMilliseconds(decoder.decodeLong()) - override fun serialize(encoder: Encoder, value: Instant) = encoder.encodeLong(value.toEpochMilliseconds()) - } - - /** - * Used to serialize/deserialize [ArtifactType] classes. - * - * @since 0.1.0 - */ - class ArtifactTypeSerializer : KSerializer { - - override val descriptor = PrimitiveSerialDescriptor( - "spp.protocol.ArtifactTypeSerializer", - PrimitiveKind.STRING - ) - - override fun deserialize(decoder: Decoder) = ArtifactType.valueOf(decoder.decodeString()) - override fun serialize(encoder: Encoder, value: ArtifactType) = encoder.encodeString(value.name) - } -} diff --git a/src/commonMain/kotlin/spp.protocol/artifact/ArtifactQualifiedName.kt b/src/commonMain/kotlin/spp.protocol/artifact/ArtifactQualifiedName.kt index f535186e..0a1eaade 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/ArtifactQualifiedName.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/ArtifactQualifiedName.kt @@ -18,7 +18,6 @@ package spp.protocol.artifact import kotlinx.serialization.Serializable -import spp.protocol.Serializers.ArtifactTypeSerializer /** * todo: description. @@ -30,7 +29,6 @@ import spp.protocol.Serializers.ArtifactTypeSerializer data class ArtifactQualifiedName( val identifier: String, val commitId: String? = null, - @Serializable(with = ArtifactTypeSerializer::class) val type: ArtifactType, val lineNumber: Int? = null, val operationName: String? = null //todo: only method artifacts need diff --git a/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt b/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt index 9002f0bd..7b214f37 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.log import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.exception.LiveStackTrace /** @@ -30,7 +29,6 @@ import spp.protocol.artifact.exception.LiveStackTrace */ @Serializable data class Log( - @Serializable(with = Serializers.InstantKSerializer::class) val timestamp: Instant, val content: String, val level: String, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt b/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt index cf8c7ed4..37d0bdb7 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.log import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers /** * todo: description. @@ -29,7 +28,6 @@ import spp.protocol.Serializers */ @Serializable data class LogCountSummary( - @Serializable(with = Serializers.InstantKSerializer::class) val timestamp: Instant, val logCounts: Map ) diff --git a/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt b/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt index 421d98e6..5e2259ea 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.log import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.ArtifactQualifiedName /** @@ -32,7 +31,6 @@ import spp.protocol.artifact.ArtifactQualifiedName data class LogResult( val artifactQualifiedName: ArtifactQualifiedName? = null, val orderType: LogOrderType, - @Serializable(with = Serializers.InstantKSerializer::class) val timestamp: Instant, val logs: List = emptyList(), val total: Int = 0 diff --git a/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt b/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt index 1abb4acb..87510436 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.metrics import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.ArtifactQualifiedName import spp.protocol.artifact.QueryTimeFrame @@ -34,9 +33,7 @@ data class ArtifactMetricResult( val artifactQualifiedName: ArtifactQualifiedName, val timeFrame: QueryTimeFrame, val focus: MetricType, - @Serializable(with = Serializers.InstantKSerializer::class) val start: Instant, - @Serializable(with = Serializers.InstantKSerializer::class) val stop: Instant, val step: String, val artifactMetrics: List, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt index 8fa04262..72e3f78f 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers /** * todo: description. @@ -32,7 +31,6 @@ data class Trace( val key: String? = null, val operationNames: List, val duration: Int, - @Serializable(with = Serializers.InstantKSerializer::class) val start: Instant, val error: Boolean? = null, val traceIds: List, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt index 311232fd..ccc0db7e 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.ArtifactQualifiedName /** @@ -33,9 +32,7 @@ data class TraceResult( val artifactQualifiedName: ArtifactQualifiedName, val artifactSimpleName: String? = null, val orderType: TraceOrderType, - @Serializable(with = Serializers.InstantKSerializer::class) val start: Instant, - @Serializable(with = Serializers.InstantKSerializer::class) val stop: Instant, val step: String, val traces: List, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt index 778914c1..b3e2aea6 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.ArtifactQualifiedName /** @@ -37,9 +36,7 @@ data class TraceSpan( val refs: List = emptyList(), val serviceCode: String, val serviceInstanceName: String? = null, - @Serializable(with = Serializers.InstantKSerializer::class) val startTime: Instant, - @Serializable(with = Serializers.InstantKSerializer::class) val endTime: Instant, val endpointName: String? = null, val artifactQualifiedName: ArtifactQualifiedName? = null, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt index 9520043a..cdeef1df 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt @@ -19,7 +19,6 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers /** * todo: description. @@ -29,7 +28,6 @@ import spp.protocol.Serializers */ @Serializable data class TraceSpanLogEntry( - @Serializable(with = Serializers.InstantKSerializer::class) val time: Instant, val data: String ) diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt index ad8e705f..ef827101 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt @@ -19,7 +19,6 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.exception.LiveStackTrace /** @@ -32,7 +31,6 @@ import spp.protocol.artifact.exception.LiveStackTrace data class LiveBreakpointHit( val breakpointId: String, val traceId: String, - @Serializable(with = Serializers.InstantKSerializer::class) override val occurredAt: Instant, val serviceInstance: String, val service: String, diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt index 767f48e8..4676ede4 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt @@ -19,7 +19,6 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.exception.LiveStackTrace import spp.protocol.instrument.LiveInstrument @@ -32,7 +31,6 @@ import spp.protocol.instrument.LiveInstrument @Serializable data class LiveInstrumentRemoved( val liveInstrument: LiveInstrument, - @Serializable(with = Serializers.InstantKSerializer::class) override val occurredAt: Instant, val cause: LiveStackTrace? = null ) : TrackedLiveEvent diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt index c66703f4..fd782b9b 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt @@ -19,7 +19,6 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant import kotlinx.serialization.Serializable -import spp.protocol.Serializers import spp.protocol.artifact.log.LogResult /** @@ -31,7 +30,6 @@ import spp.protocol.artifact.log.LogResult @Serializable data class LiveLogHit( val logId: String, - @Serializable(with = Serializers.InstantKSerializer::class) override val occurredAt: Instant, val serviceInstance: String, val service: String, diff --git a/src/jvmTest/kotlin/spp/protocol/artifact/trace/TraceStackTest.kt b/src/jvmTest/kotlin/spp/protocol/artifact/trace/TraceStackTest.kt index a9b01e30..16af7464 100644 --- a/src/jvmTest/kotlin/spp/protocol/artifact/trace/TraceStackTest.kt +++ b/src/jvmTest/kotlin/spp/protocol/artifact/trace/TraceStackTest.kt @@ -17,22 +17,11 @@ */ package spp.protocol.artifact.trace -import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.* -import com.fasterxml.jackson.databind.module.SimpleModule -import com.fasterxml.jackson.datatype.guava.GuavaModule -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule -import com.fasterxml.jackson.module.kotlin.KotlinModule import com.google.common.io.Resources import io.vertx.core.json.Json import io.vertx.core.json.JsonArray -import io.vertx.core.json.jackson.DatabindCodec -import kotlinx.datetime.Instant import org.junit.Assert.assertEquals import org.junit.Assert.assertNull -import org.junit.Before import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith @@ -42,21 +31,6 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class TraceStackTest { - @Before - fun setUp() { - val module = SimpleModule() - module.addSerializer(Instant::class.java, KSerializers.KotlinInstantSerializer()) - module.addDeserializer(Instant::class.java, KSerializers.KotlinInstantDeserializer()) - DatabindCodec.mapper().registerModule(module) - - DatabindCodec.mapper().registerModule(GuavaModule()) - DatabindCodec.mapper().registerModule(Jdk8Module()) - DatabindCodec.mapper().registerModule(JavaTimeModule()) - DatabindCodec.mapper().registerModule(KotlinModule()) - DatabindCodec.mapper().enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) - DatabindCodec.mapper().enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING) - } - @Test fun `dual segment trace stack`() { val jsonTraceStack = JsonArray( @@ -89,16 +63,4 @@ class TraceStackTest { assertEquals(1, entrySegment.getParent(3)!!.spanId) assertEquals(1, entrySegment.getParent(4)!!.spanId) } - - private class KSerializers { - class KotlinInstantSerializer : JsonSerializer() { - override fun serialize(value: Instant, jgen: JsonGenerator, provider: SerializerProvider) = - jgen.writeNumber(value.toEpochMilliseconds()) - } - - class KotlinInstantDeserializer : JsonDeserializer() { - override fun deserialize(p: JsonParser, p1: DeserializationContext): Instant = - Instant.fromEpochMilliseconds((p.codec.readTree(p) as JsonNode).longValue()) - } - } } From ab838b16418037fc8a530e2a433c24bd220d55a1 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Mon, 7 Mar 2022 14:20:23 +0100 Subject: [PATCH 08/26] remove unused --- .../kotlin/spp/protocol/SourceServices.kt | 3 -- .../service/LogCountIndicatorService.kt | 44 ------------------- 2 files changed, 47 deletions(-) delete mode 100644 src/jvmMain/kotlin/spp/protocol/service/LogCountIndicatorService.kt diff --git a/src/jvmMain/kotlin/spp/protocol/SourceServices.kt b/src/jvmMain/kotlin/spp/protocol/SourceServices.kt index 4c44defe..79667717 100644 --- a/src/jvmMain/kotlin/spp/protocol/SourceServices.kt +++ b/src/jvmMain/kotlin/spp/protocol/SourceServices.kt @@ -22,7 +22,6 @@ import spp.protocol.SourceServices.Utilize.LIVE_VIEW import spp.protocol.service.LiveInstrumentService import spp.protocol.service.LiveService import spp.protocol.service.LiveViewService -import spp.protocol.service.LogCountIndicatorService /** * todo: description. @@ -36,14 +35,12 @@ object SourceServices { var liveService: LiveService? = null var liveInstrument: LiveInstrumentService? = null var liveView: LiveViewService? = null - var logCountIndicator: LogCountIndicatorService? = null } object Utilize { const val LIVE_SERVICE = "spp.service.live-service" const val LIVE_INSTRUMENT = "spp.service.live-instrument" const val LIVE_VIEW = "spp.service.live-view" - const val LOG_COUNT_INDICATOR = "spp.service.log-count-indicator" } object Provide { diff --git a/src/jvmMain/kotlin/spp/protocol/service/LogCountIndicatorService.kt b/src/jvmMain/kotlin/spp/protocol/service/LogCountIndicatorService.kt deleted file mode 100644 index 458a4bfa..00000000 --- a/src/jvmMain/kotlin/spp/protocol/service/LogCountIndicatorService.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Source++, the open-source live coding platform. - * Copyright (C) 2022 CodeBrig, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package spp.protocol.service - -import io.vertx.codegen.annotations.ProxyGen -import io.vertx.codegen.annotations.VertxGen -import io.vertx.core.Future -import io.vertx.core.json.JsonObject -import kotlinx.datetime.Instant -import spp.protocol.instrument.DurationStep - -/** - * todo: description. - * - * @since 0.2.1 - * @author [Brandon Fergerson](mailto:bfergerson@apache.org) - */ -@ProxyGen -@VertxGen -interface LogCountIndicatorService { - - fun getPatternOccurrences( - logPatterns: List, - serviceName: String?, - start: Instant, - stop: Instant, - step: DurationStep - ): Future -} From 208648e967da1befd30029960e48137d6ce1fb28 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Mon, 7 Mar 2022 16:08:34 +0100 Subject: [PATCH 09/26] required service --- src/jvmMain/kotlin/spp/protocol/SourceServices.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jvmMain/kotlin/spp/protocol/SourceServices.kt b/src/jvmMain/kotlin/spp/protocol/SourceServices.kt index 79667717..0db32392 100644 --- a/src/jvmMain/kotlin/spp/protocol/SourceServices.kt +++ b/src/jvmMain/kotlin/spp/protocol/SourceServices.kt @@ -32,7 +32,7 @@ import spp.protocol.service.LiveViewService object SourceServices { object Instance { - var liveService: LiveService? = null + lateinit var liveService: LiveService var liveInstrument: LiveInstrumentService? = null var liveView: LiveViewService? = null } From 22d08b05c539a047278112ca1b50d3d08bf1a373 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 14:06:37 +0100 Subject: [PATCH 10/26] ability to clear --- src/jvmMain/kotlin/spp/protocol/SourceServices.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jvmMain/kotlin/spp/protocol/SourceServices.kt b/src/jvmMain/kotlin/spp/protocol/SourceServices.kt index 0db32392..dabc74bd 100644 --- a/src/jvmMain/kotlin/spp/protocol/SourceServices.kt +++ b/src/jvmMain/kotlin/spp/protocol/SourceServices.kt @@ -32,9 +32,15 @@ import spp.protocol.service.LiveViewService object SourceServices { object Instance { - lateinit var liveService: LiveService + var liveService: LiveService? = null var liveInstrument: LiveInstrumentService? = null var liveView: LiveViewService? = null + + fun clearServices() { + liveService = null + liveInstrument = null + liveView = null + } } object Utilize { From eacd2a58a0a63abfd89fee796583e1abd2f86901 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 18:51:29 +0100 Subject: [PATCH 11/26] add sub id --- src/commonMain/kotlin/spp.protocol/view/LiveViewEvent.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commonMain/kotlin/spp.protocol/view/LiveViewEvent.kt b/src/commonMain/kotlin/spp.protocol/view/LiveViewEvent.kt index 1c86574d..77720e6e 100644 --- a/src/commonMain/kotlin/spp.protocol/view/LiveViewEvent.kt +++ b/src/commonMain/kotlin/spp.protocol/view/LiveViewEvent.kt @@ -28,6 +28,7 @@ import spp.protocol.artifact.ArtifactQualifiedName */ @Serializable data class LiveViewEvent( + val subscriptionId: String, val entityId: String, val artifactQualifiedName: ArtifactQualifiedName, val timeBucket: String, From e642103a471c6c1d83d37b8cb6ae7451d5cc2a4d Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 20:41:32 +0100 Subject: [PATCH 12/26] impl more --- .../protocol/marshall/ProtocolMarshaller.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index 541f9546..3ff3a45c 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -26,6 +26,7 @@ import kotlinx.datetime.Instant import spp.protocol.artifact.ArtifactQualifiedName import spp.protocol.artifact.exception.LiveStackTrace import spp.protocol.artifact.exception.LiveStackTraceElement +import spp.protocol.artifact.log.Log import spp.protocol.artifact.log.LogCountSummary import spp.protocol.artifact.trace.TraceResult import spp.protocol.instrument.* @@ -33,6 +34,7 @@ import spp.protocol.instrument.command.CommandType import spp.protocol.instrument.command.LiveInstrumentCommand import spp.protocol.instrument.event.LiveBreakpointHit import spp.protocol.instrument.event.LiveInstrumentRemoved +import spp.protocol.instrument.event.LiveLogHit import spp.protocol.instrument.variable.LiveVariable import spp.protocol.platform.developer.SelfInfo import spp.protocol.platform.general.Service @@ -309,4 +311,41 @@ object ProtocolMarshaller { deserializeLiveStackTrace(value.getJsonObject("stackTrace")) ) } + + @JvmStatic + fun serializeLiveLogHit(value: LiveLogHit): JsonObject { + return JsonObject(Json.encode(value)) + } + + @JvmStatic + fun deserializeLiveLogHit(value: JsonObject): LiveLogHit { + return value.mapTo(LiveLogHit::class.java) + } + + @JvmStatic + fun serializeLog(value: Log): JsonObject { + return JsonObject(Json.encode(value)) + } + + @JvmStatic + fun deserializeLog(value: JsonObject): Log { + return Log( + value.let { + if (it.getValue("timestamp") is Number) { + Instant.fromEpochMilliseconds(value.getLong("timestamp")) + } else { + Instant.fromEpochSeconds( + value.getJsonObject("timestamp").getLong("epochSeconds"), + value.getJsonObject("timestamp").getInteger("nanosecondsOfSecond") + ) + } + }, + value.getString("content"), + value.getString("level"), + value.getString("logger"), + value.getString("thread"), + deserializeLiveStackTrace(value.getJsonObject("exception")), + value.getJsonArray("arguments").list.map { it.toString() } + ) + } } From 6e7e89a5ca7865aa21bec7f91a60fd01b3aed757 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 20:48:40 +0100 Subject: [PATCH 13/26] refactor --- .../kotlin/spp/protocol/marshall/ProtocolMarshaller.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index 3ff3a45c..b93ea1a5 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -252,7 +252,7 @@ object ProtocolMarshaller { ) } }, - value.getJsonObject("cause")?.let { Json.decodeValue(it.toString(), LiveStackTrace::class.java) } + value.getJsonObject("cause")?.let { deserializeLiveStackTrace(it) } ) } @@ -344,7 +344,7 @@ object ProtocolMarshaller { value.getString("level"), value.getString("logger"), value.getString("thread"), - deserializeLiveStackTrace(value.getJsonObject("exception")), + value.getJsonObject("exception")?.let { deserializeLiveStackTrace(it) }, value.getJsonArray("arguments").list.map { it.toString() } ) } From 91bf9d72ab6447e228126727bebc8e6fddb7bf5a Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 21:07:09 +0100 Subject: [PATCH 14/26] impl --- .../protocol/marshall/ProtocolMarshaller.kt | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index b93ea1a5..f8e39566 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -28,6 +28,8 @@ import spp.protocol.artifact.exception.LiveStackTrace import spp.protocol.artifact.exception.LiveStackTraceElement import spp.protocol.artifact.log.Log import spp.protocol.artifact.log.LogCountSummary +import spp.protocol.artifact.log.LogOrderType +import spp.protocol.artifact.log.LogResult import spp.protocol.artifact.trace.TraceResult import spp.protocol.instrument.* import spp.protocol.instrument.command.CommandType @@ -312,6 +314,37 @@ object ProtocolMarshaller { ) } + @JvmStatic + fun serializeLogResult(value: LogResult): JsonObject { + return JsonObject(Json.encode(value)) + } + + @JvmStatic + fun deserializeLogResult(value: JsonObject): LogResult { + return LogResult( + deserializeArtifactQualifiedName(value.getJsonObject("artifactQualifiedName")), + LogOrderType.valueOf(value.getString("orderType")), + value.let { + if (it.getValue("timestamp") is Number) { + Instant.fromEpochMilliseconds(value.getLong("occurredAt")) + } else { + Instant.fromEpochSeconds( + value.getJsonObject("timestamp").getLong("epochSeconds"), + value.getJsonObject("timestamp").getInteger("nanosecondsOfSecond") + ) + } + }, + value.getJsonArray("logs").list.map { + if (it is JsonObject) { + deserializeLog(it) + } else { + deserializeLog(JsonObject.mapFrom(it)) + } + }, + value.getInteger("total") + ) + } + @JvmStatic fun serializeLiveLogHit(value: LiveLogHit): JsonObject { return JsonObject(Json.encode(value)) @@ -319,7 +352,22 @@ object ProtocolMarshaller { @JvmStatic fun deserializeLiveLogHit(value: JsonObject): LiveLogHit { - return value.mapTo(LiveLogHit::class.java) + return LiveLogHit( + value.getString("logId"), + value.let { + if (it.getValue("occurredAt") is Number) { + Instant.fromEpochMilliseconds(value.getLong("occurredAt")) + } else { + Instant.fromEpochSeconds( + value.getJsonObject("occurredAt").getLong("epochSeconds"), + value.getJsonObject("occurredAt").getInteger("nanosecondsOfSecond") + ) + } + }, + value.getString("serviceInstance"), + value.getString("service"), + deserializeLogResult(value.getJsonObject("logResult")) + ) } @JvmStatic From 164731a1d3e5567fac63aeeaab6dfd87495d401d Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 21:22:21 +0100 Subject: [PATCH 15/26] impl --- src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index f8e39566..f1389577 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -45,6 +45,7 @@ import spp.protocol.view.LiveViewSubscription /** * Used for marshalling and unmarshalling protocol messages. + * Avoids using annotations and Jackson modules to keep probe-jvm dependencies simple. * * @since 0.2.1 * @author [Brandon Fergerson](mailto:bfergerson@apache.org) @@ -322,7 +323,7 @@ object ProtocolMarshaller { @JvmStatic fun deserializeLogResult(value: JsonObject): LogResult { return LogResult( - deserializeArtifactQualifiedName(value.getJsonObject("artifactQualifiedName")), + value.getJsonObject("artifactQualifiedName")?.let { deserializeArtifactQualifiedName(it) }, LogOrderType.valueOf(value.getString("orderType")), value.let { if (it.getValue("timestamp") is Number) { From e540bbcccbfa6a57bc356ae62c4404d818900257 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 8 Mar 2022 21:29:02 +0100 Subject: [PATCH 16/26] impl --- src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index f1389577..ffffe0e5 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -327,7 +327,7 @@ object ProtocolMarshaller { LogOrderType.valueOf(value.getString("orderType")), value.let { if (it.getValue("timestamp") is Number) { - Instant.fromEpochMilliseconds(value.getLong("occurredAt")) + Instant.fromEpochMilliseconds(value.getLong("timestamp")) } else { Instant.fromEpochSeconds( value.getJsonObject("timestamp").getLong("epochSeconds"), From 74f9963365f43888dd05b5c176748bc3cb72ad58 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Wed, 9 Mar 2022 17:05:35 +0100 Subject: [PATCH 17/26] default serializer --- src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt | 2 ++ .../kotlin/spp.protocol/artifact/log/LogCountSummary.kt | 2 ++ src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt | 2 ++ .../spp.protocol/artifact/metrics/ArtifactMetricResult.kt | 3 +++ src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt | 2 ++ .../kotlin/spp.protocol/artifact/trace/TraceResult.kt | 3 +++ src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt | 3 +++ .../kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt | 2 ++ .../kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt | 2 ++ .../spp.protocol/instrument/event/LiveInstrumentRemoved.kt | 2 ++ .../kotlin/spp.protocol/instrument/event/LiveLogHit.kt | 2 ++ .../kotlin/spp.protocol/instrument/event/TrackedLiveEvent.kt | 3 +++ 12 files changed, 28 insertions(+) diff --git a/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt b/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt index 7b214f37..a6dabee6 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/log/Log.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.log import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.exception.LiveStackTrace @@ -29,6 +30,7 @@ import spp.protocol.artifact.exception.LiveStackTrace */ @Serializable data class Log( + @Serializable(with = InstantIso8601Serializer::class) val timestamp: Instant, val content: String, val level: String, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt b/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt index 37d0bdb7..abbab8cb 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/log/LogCountSummary.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.log import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable /** @@ -28,6 +29,7 @@ import kotlinx.serialization.Serializable */ @Serializable data class LogCountSummary( + @Serializable(with = InstantIso8601Serializer::class) val timestamp: Instant, val logCounts: Map ) diff --git a/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt b/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt index 5e2259ea..86ed39f2 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/log/LogResult.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.log import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.ArtifactQualifiedName @@ -31,6 +32,7 @@ import spp.protocol.artifact.ArtifactQualifiedName data class LogResult( val artifactQualifiedName: ArtifactQualifiedName? = null, val orderType: LogOrderType, + @Serializable(with = InstantIso8601Serializer::class) val timestamp: Instant, val logs: List = emptyList(), val total: Int = 0 diff --git a/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt b/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt index 87510436..89823e1a 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/metrics/ArtifactMetricResult.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.metrics import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.ArtifactQualifiedName import spp.protocol.artifact.QueryTimeFrame @@ -33,7 +34,9 @@ data class ArtifactMetricResult( val artifactQualifiedName: ArtifactQualifiedName, val timeFrame: QueryTimeFrame, val focus: MetricType, + @Serializable(with = InstantIso8601Serializer::class) val start: Instant, + @Serializable(with = InstantIso8601Serializer::class) val stop: Instant, val step: String, val artifactMetrics: List, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt index 72e3f78f..c81a3a8d 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable /** @@ -31,6 +32,7 @@ data class Trace( val key: String? = null, val operationNames: List, val duration: Int, + @Serializable(with = InstantIso8601Serializer::class) val start: Instant, val error: Boolean? = null, val traceIds: List, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt index ccc0db7e..3012f172 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceResult.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.ArtifactQualifiedName @@ -32,7 +33,9 @@ data class TraceResult( val artifactQualifiedName: ArtifactQualifiedName, val artifactSimpleName: String? = null, val orderType: TraceOrderType, + @Serializable(with = InstantIso8601Serializer::class) val start: Instant, + @Serializable(with = InstantIso8601Serializer::class) val stop: Instant, val step: String, val traces: List, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt index b3e2aea6..91fd34c5 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.ArtifactQualifiedName @@ -36,7 +37,9 @@ data class TraceSpan( val refs: List = emptyList(), val serviceCode: String, val serviceInstanceName: String? = null, + @Serializable(with = InstantIso8601Serializer::class) val startTime: Instant, + @Serializable(with = InstantIso8601Serializer::class) val endTime: Instant, val endpointName: String? = null, val artifactQualifiedName: ArtifactQualifiedName? = null, diff --git a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt index cdeef1df..a8c9d8ed 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpanLogEntry.kt @@ -18,6 +18,7 @@ package spp.protocol.artifact.trace import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable /** @@ -28,6 +29,7 @@ import kotlinx.serialization.Serializable */ @Serializable data class TraceSpanLogEntry( + @Serializable(with = InstantIso8601Serializer::class) val time: Instant, val data: String ) diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt index ef827101..88861373 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveBreakpointHit.kt @@ -18,6 +18,7 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.exception.LiveStackTrace @@ -31,6 +32,7 @@ import spp.protocol.artifact.exception.LiveStackTrace data class LiveBreakpointHit( val breakpointId: String, val traceId: String, + @Serializable(with = InstantIso8601Serializer::class) override val occurredAt: Instant, val serviceInstance: String, val service: String, diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt index 4676ede4..c61ce376 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveInstrumentRemoved.kt @@ -18,6 +18,7 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.exception.LiveStackTrace import spp.protocol.instrument.LiveInstrument @@ -31,6 +32,7 @@ import spp.protocol.instrument.LiveInstrument @Serializable data class LiveInstrumentRemoved( val liveInstrument: LiveInstrument, + @Serializable(with = InstantIso8601Serializer::class) override val occurredAt: Instant, val cause: LiveStackTrace? = null ) : TrackedLiveEvent diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt index fd782b9b..b2733186 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/LiveLogHit.kt @@ -18,6 +18,7 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer import kotlinx.serialization.Serializable import spp.protocol.artifact.log.LogResult @@ -30,6 +31,7 @@ import spp.protocol.artifact.log.LogResult @Serializable data class LiveLogHit( val logId: String, + @Serializable(with = InstantIso8601Serializer::class) override val occurredAt: Instant, val serviceInstance: String, val service: String, diff --git a/src/commonMain/kotlin/spp.protocol/instrument/event/TrackedLiveEvent.kt b/src/commonMain/kotlin/spp.protocol/instrument/event/TrackedLiveEvent.kt index 61399eb7..1bc3edda 100644 --- a/src/commonMain/kotlin/spp.protocol/instrument/event/TrackedLiveEvent.kt +++ b/src/commonMain/kotlin/spp.protocol/instrument/event/TrackedLiveEvent.kt @@ -18,6 +18,8 @@ package spp.protocol.instrument.event import kotlinx.datetime.Instant +import kotlinx.datetime.serializers.InstantIso8601Serializer +import kotlinx.serialization.Serializable /** * todo: description. @@ -26,5 +28,6 @@ import kotlinx.datetime.Instant * @author [Brandon Fergerson](mailto:bfergerson@apache.org) */ interface TrackedLiveEvent { + @Serializable(with = InstantIso8601Serializer::class) val occurredAt: Instant } From e1728ae87c32c40173f231d7adfef362b27400b2 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Wed, 9 Mar 2022 17:40:06 +0100 Subject: [PATCH 18/26] default to str instant --- .../spp/protocol/marshall/KSerializers.kt | 4 ++-- .../protocol/marshall/ProtocolMarshaller.kt | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt b/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt index a509446b..59e3957a 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt @@ -30,11 +30,11 @@ import kotlinx.datetime.Instant object KSerializers { class KotlinInstantSerializer : JsonSerializer() { override fun serialize(value: Instant, jgen: JsonGenerator, provider: SerializerProvider) = - jgen.writeNumber(value.toEpochMilliseconds()) + jgen.writeString(value.toEpochMilliseconds().toString()) } class KotlinInstantDeserializer : JsonDeserializer() { override fun deserialize(p: JsonParser, p1: DeserializationContext): Instant = - Instant.fromEpochMilliseconds((p.codec.readTree(p) as JsonNode).longValue()) + Instant.fromEpochMilliseconds((p.codec.readTree(p) as JsonNode).asText().toLong()) } } diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index ffffe0e5..d3ee92be 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -246,7 +246,9 @@ object ProtocolMarshaller { return LiveInstrumentRemoved( deserializeLiveInstrument(value.getJsonObject("liveInstrument")), value.let { - if (it.getValue("occurredAt") is Number) { + if (it.getValue("occurredAt") is String) { + Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + } else if (it.getValue("occurredAt") is Number) { Instant.fromEpochMilliseconds(value.getLong("occurredAt")) } else { Instant.fromEpochSeconds( @@ -300,7 +302,9 @@ object ProtocolMarshaller { value.getString("breakpointId"), value.getString("traceId"), value.let { - if (it.getValue("occurredAt") is Number) { + if (it.getValue("occurredAt") is String) { + Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + } else if (it.getValue("occurredAt") is Number) { Instant.fromEpochMilliseconds(value.getLong("occurredAt")) } else { Instant.fromEpochSeconds( @@ -326,7 +330,9 @@ object ProtocolMarshaller { value.getJsonObject("artifactQualifiedName")?.let { deserializeArtifactQualifiedName(it) }, LogOrderType.valueOf(value.getString("orderType")), value.let { - if (it.getValue("timestamp") is Number) { + if (it.getValue("timestamp") is String) { + Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + } else if (it.getValue("timestamp") is Number) { Instant.fromEpochMilliseconds(value.getLong("timestamp")) } else { Instant.fromEpochSeconds( @@ -356,7 +362,9 @@ object ProtocolMarshaller { return LiveLogHit( value.getString("logId"), value.let { - if (it.getValue("occurredAt") is Number) { + if (it.getValue("occurredAt") is String) { + Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + } else if (it.getValue("occurredAt") is Number) { Instant.fromEpochMilliseconds(value.getLong("occurredAt")) } else { Instant.fromEpochSeconds( @@ -380,7 +388,9 @@ object ProtocolMarshaller { fun deserializeLog(value: JsonObject): Log { return Log( value.let { - if (it.getValue("timestamp") is Number) { + if (it.getValue("timestamp") is String) { + Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + } else if (it.getValue("timestamp") is Number) { Instant.fromEpochMilliseconds(value.getLong("timestamp")) } else { Instant.fromEpochSeconds( From 78ea42edb321c97ad1bd6cec93cb446db592a1f0 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Wed, 9 Mar 2022 17:54:08 +0100 Subject: [PATCH 19/26] use iso8601 --- .../kotlin/spp/protocol/marshall/KSerializers.kt | 4 ++-- .../kotlin/spp/protocol/marshall/ProtocolMarshaller.kt | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt b/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt index 59e3957a..a9b7dd9e 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt @@ -30,11 +30,11 @@ import kotlinx.datetime.Instant object KSerializers { class KotlinInstantSerializer : JsonSerializer() { override fun serialize(value: Instant, jgen: JsonGenerator, provider: SerializerProvider) = - jgen.writeString(value.toEpochMilliseconds().toString()) + jgen.writeString(value.toString()) } class KotlinInstantDeserializer : JsonDeserializer() { override fun deserialize(p: JsonParser, p1: DeserializationContext): Instant = - Instant.fromEpochMilliseconds((p.codec.readTree(p) as JsonNode).asText().toLong()) + Instant.parse((p.codec.readTree(p) as JsonNode).asText()) } } diff --git a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt index d3ee92be..8177072a 100644 --- a/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt +++ b/src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt @@ -247,7 +247,7 @@ object ProtocolMarshaller { deserializeLiveInstrument(value.getJsonObject("liveInstrument")), value.let { if (it.getValue("occurredAt") is String) { - Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + Instant.parse(value.getString("occurredAt")) } else if (it.getValue("occurredAt") is Number) { Instant.fromEpochMilliseconds(value.getLong("occurredAt")) } else { @@ -303,7 +303,7 @@ object ProtocolMarshaller { value.getString("traceId"), value.let { if (it.getValue("occurredAt") is String) { - Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + Instant.parse(value.getString("occurredAt")) } else if (it.getValue("occurredAt") is Number) { Instant.fromEpochMilliseconds(value.getLong("occurredAt")) } else { @@ -331,7 +331,7 @@ object ProtocolMarshaller { LogOrderType.valueOf(value.getString("orderType")), value.let { if (it.getValue("timestamp") is String) { - Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + Instant.parse(value.getString("timestamp")) } else if (it.getValue("timestamp") is Number) { Instant.fromEpochMilliseconds(value.getLong("timestamp")) } else { @@ -363,7 +363,7 @@ object ProtocolMarshaller { value.getString("logId"), value.let { if (it.getValue("occurredAt") is String) { - Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + Instant.parse(value.getString("occurredAt")) } else if (it.getValue("occurredAt") is Number) { Instant.fromEpochMilliseconds(value.getLong("occurredAt")) } else { @@ -389,7 +389,7 @@ object ProtocolMarshaller { return Log( value.let { if (it.getValue("timestamp") is String) { - Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong()) + Instant.parse(value.getString("timestamp")) } else if (it.getValue("timestamp") is Number) { Instant.fromEpochMilliseconds(value.getLong("timestamp")) } else { From cd683997652e5f91de5c4df7bb7c656398db4cdb Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Thu, 10 Mar 2022 10:38:40 +0100 Subject: [PATCH 20/26] portal config --- .../portal/PortalConfiguration.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt diff --git a/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt b/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt new file mode 100644 index 00000000..8b310c5a --- /dev/null +++ b/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt @@ -0,0 +1,34 @@ +/* + * Source++, the open-source live coding platform. + * Copyright (C) 2022 CodeBrig, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package spp.protocol.portal + +import kotlinx.serialization.Contextual +import kotlinx.serialization.Serializable +import spp.protocol.artifact.ArtifactQualifiedName + +@Serializable +data class PortalConfiguration( + var artifactQualifiedName: ArtifactQualifiedName, + var darkMode: Boolean = false, + var external: Boolean = false, + var config: MutableMap = mutableMapOf() +) { + fun fromConfig(key: String, default: T): T { + return config[key] as T ?: default + } +} From a2cd759830c98fbb6f8a6721c98a46208dc9c570 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Thu, 10 Mar 2022 12:35:01 +0100 Subject: [PATCH 21/26] rename --- .../kotlin/spp.protocol/portal/PortalConfiguration.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt b/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt index 8b310c5a..6989a7dc 100644 --- a/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt +++ b/src/commonMain/kotlin/spp.protocol/portal/PortalConfiguration.kt @@ -28,7 +28,11 @@ data class PortalConfiguration( var external: Boolean = false, var config: MutableMap = mutableMapOf() ) { - fun fromConfig(key: String, default: T): T { + fun get(key: String): T { + return config[key] as T + } + + fun get(key: String, default: T): T { return config[key] as T ?: default } } From 852903d261e8c218721a35ab5730a52915ea94d5 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 12 Mar 2022 15:43:11 +0100 Subject: [PATCH 22/26] simple name --- .../spp.protocol/artifact/metrics/MetricType.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/commonMain/kotlin/spp.protocol/artifact/metrics/MetricType.kt b/src/commonMain/kotlin/spp.protocol/artifact/metrics/MetricType.kt index 1a3ae28f..6007c4ff 100644 --- a/src/commonMain/kotlin/spp.protocol/artifact/metrics/MetricType.kt +++ b/src/commonMain/kotlin/spp.protocol/artifact/metrics/MetricType.kt @@ -43,6 +43,18 @@ enum class MetricType { || this == ResponseTime_75Percentile || this == ResponseTime_50Percentile + val simpleName: String + get() = when (this) { + Throughput_Average -> "Throughput" + ResponseTime_Average -> "Response" + ServiceLevelAgreement_Average -> "SLA" + ResponseTime_99Percentile -> "Resp(99%)" + ResponseTime_95Percentile -> "Resp(95%)" + ResponseTime_90Percentile -> "Resp(90%)" + ResponseTime_75Percentile -> "Resp(75%)" + ResponseTime_50Percentile -> "Resp(50%)" + } + companion object { //todo: remove fun realValueOf(name: String): MetricType { From 5ab12b5c51b65f039177f178968e1d33d9f25081 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 12 Mar 2022 15:43:22 +0100 Subject: [PATCH 23/26] comment --- .../protocol/marshall/ProtocolMarshallerTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt b/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt index ad4458a7..b82c609b 100644 --- a/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt +++ b/src/jvmTest/kotlin/spp/protocol/marshall/ProtocolMarshallerTest.kt @@ -1,3 +1,20 @@ +/* + * Source++, the open-source live coding platform. + * Copyright (C) 2022 CodeBrig, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ package spp.protocol.marshall import kotlinx.datetime.Clock From 3da1dbb572d391090358c9358fd752a81b3a6e84 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 13 Mar 2022 16:06:46 +0100 Subject: [PATCH 24/26] default --- src/commonMain/kotlin/spp.protocol/view/LiveViewConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/spp.protocol/view/LiveViewConfig.kt b/src/commonMain/kotlin/spp.protocol/view/LiveViewConfig.kt index 9d931baa..91d7847c 100644 --- a/src/commonMain/kotlin/spp.protocol/view/LiveViewConfig.kt +++ b/src/commonMain/kotlin/spp.protocol/view/LiveViewConfig.kt @@ -29,5 +29,5 @@ import kotlinx.serialization.Serializable data class LiveViewConfig( val viewName: String, val viewMetrics: List, - val refreshRateLimit: Int = 1000 //limit of once per X milliseconds + val refreshRateLimit: Int = -1 //limit of once per X milliseconds ) From af337ba2479d6befe2872133246ad41073890270 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 13 Mar 2022 16:07:14 +0100 Subject: [PATCH 25/26] publish messages without reply addresses --- .../kotlin/spp/protocol/extend/TCPServiceFrameParser.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jvmMain/kotlin/spp/protocol/extend/TCPServiceFrameParser.kt b/src/jvmMain/kotlin/spp/protocol/extend/TCPServiceFrameParser.kt index 9967ccd4..9c4d9b1c 100644 --- a/src/jvmMain/kotlin/spp/protocol/extend/TCPServiceFrameParser.kt +++ b/src/jvmMain/kotlin/spp/protocol/extend/TCPServiceFrameParser.kt @@ -83,7 +83,7 @@ class TCPServiceFrameParser(val vertx: Vertx, val socket: NetSocket) : Handler TODO() } - vertx.eventBus().send(frame.getString("address"), error) + vertx.eventBus().publish(frame.getString("address"), error) } else { throw UnsupportedOperationException(frame.toString()) } From 44620ec4ae9f9a916e113267473c4a77fd164ced Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sun, 13 Mar 2022 16:54:48 +0100 Subject: [PATCH 26/26] bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index cfe477f7..40290dc4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ kotlin.code.style=official -projectVersion=0.4.1 +projectVersion=0.4.2 kotlinVersion=1.6.10 vertxVersion=4.2.4