Skip to content

Commit bd567ee

Browse files
committed
fix: support full live meter config
1 parent ff63237 commit bd567ee

File tree

6 files changed

+292
-13
lines changed

6 files changed

+292
-13
lines changed

src/main/kotlin/spp/protocol/instrument/LiveBreakpoint.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package spp.protocol.instrument
1818

1919
import io.vertx.codegen.annotations.DataObject
2020
import io.vertx.core.Vertx
21+
import io.vertx.core.json.JsonArray
2122
import io.vertx.core.json.JsonObject
2223
import spp.protocol.instrument.event.LiveBreakpointHit
2324
import spp.protocol.instrument.event.LiveInstrumentEvent
@@ -60,7 +61,13 @@ data class LiveBreakpoint(
6061
applied = json.getBoolean("applied") ?: false,
6162
pending = json.getBoolean("pending") ?: false,
6263
throttle = json.getJsonObject("throttle")?.let { InstrumentThrottle(it) } ?: InstrumentThrottle.DEFAULT,
63-
meta = json.getJsonObject("meta")?.associate { it.key to it.value } ?: emptyMap()
64+
meta = json.getValue("meta")?.let {
65+
if (it is JsonObject) {
66+
it.associate { it.key to it.value }
67+
} else {
68+
toJsonMap(it as JsonArray)
69+
}
70+
} ?: emptyMap()
6471
)
6572

6673
override fun toJson(): JsonObject {

src/main/kotlin/spp/protocol/instrument/LiveInstrument.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package spp.protocol.instrument
1818

1919
import io.vertx.core.Vertx
20+
import io.vertx.core.json.JsonArray
2021
import io.vertx.core.json.JsonObject
2122
import spp.protocol.instrument.event.LiveInstrumentEvent
2223
import spp.protocol.instrument.location.LiveSourceLocation
@@ -39,7 +40,7 @@ sealed class LiveInstrument {
3940
abstract val applyImmediately: Boolean
4041
abstract val applied: Boolean
4142
abstract val pending: Boolean
42-
abstract val throttle: InstrumentThrottle?
43+
abstract val throttle: InstrumentThrottle
4344
abstract val meta: Map<String, Any>
4445

4546
override fun equals(other: Any?): Boolean {
@@ -88,5 +89,15 @@ sealed class LiveInstrument {
8889
LiveInstrumentType.METER -> LiveMeter(json)
8990
}
9091
}
92+
93+
internal fun toJsonMap(metaArray: JsonArray?): Map<String, Any> {
94+
val meta = mutableMapOf<String, String>()
95+
val metaOb = metaArray ?: JsonArray()
96+
for (i in 0 until metaOb.size()) {
97+
val metaInfoOb = metaOb.getJsonObject(i)
98+
meta[metaInfoOb.getString("name")] = metaInfoOb.getString("value")
99+
}
100+
return meta
101+
}
91102
}
92103
}

src/main/kotlin/spp/protocol/instrument/LiveLog.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ data class LiveLog(
5757
applied = json.getBoolean("applied") ?: false,
5858
pending = json.getBoolean("pending") ?: false,
5959
throttle = json.getJsonObject("throttle")?.let { InstrumentThrottle(it) } ?: InstrumentThrottle.DEFAULT,
60-
meta = json.getJsonObject("meta")?.associate { it.key to it.value } ?: emptyMap()
60+
meta = json.getValue("meta")?.let {
61+
if (it is JsonObject) {
62+
it.associate { it.key to it.value }
63+
} else {
64+
toJsonMap(it as JsonArray)
65+
}
66+
} ?: emptyMap()
6167
)
6268

6369
override fun toJson(): JsonObject {

src/main/kotlin/spp/protocol/instrument/LiveMeter.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import spp.protocol.instrument.throttle.InstrumentThrottle
3535
data class LiveMeter(
3636
val meterType: MeterType,
3737
val metricValue: MetricValue? = null,
38-
val meterTags: List<MeterTag> = emptyList(),
39-
val meterPartitions: List<MeterPartition> = emptyList(),
38+
val meterTags: List<MeterTag> = emptyList(), //todo: rename to tags
39+
val meterPartitions: List<MeterPartition> = emptyList(), //todo: rename to partitions
4040
override val location: LiveSourceLocation,
4141
override val condition: String? = null,
4242
override val expiresAt: Long? = null,
@@ -45,7 +45,7 @@ data class LiveMeter(
4545
override val applyImmediately: Boolean = false,
4646
override val applied: Boolean = false,
4747
override val pending: Boolean = false,
48-
override val throttle: InstrumentThrottle? = null,
48+
override val throttle: InstrumentThrottle = InstrumentThrottle.NONE,
4949
override val meta: Map<String, Any> = emptyMap()
5050
) : LiveInstrument() {
5151
override val type: LiveInstrumentType = LiveInstrumentType.METER
@@ -77,8 +77,14 @@ data class LiveMeter(
7777
applyImmediately = json.getBoolean("applyImmediately") ?: false,
7878
applied = json.getBoolean("applied") ?: false,
7979
pending = json.getBoolean("pending") ?: false,
80-
throttle = json.getJsonObject("throttle")?.let { InstrumentThrottle(it) },
81-
meta = json.getJsonObject("meta")?.associate { it.key to it.value } ?: emptyMap()
80+
throttle = json.getJsonObject("throttle")?.let { InstrumentThrottle(it) } ?: InstrumentThrottle.NONE,
81+
meta = json.getValue("meta")?.let {
82+
if (it is JsonObject) {
83+
it.associate { it.key to it.value }
84+
} else {
85+
toJsonMap(it as JsonArray)
86+
}
87+
} ?: emptyMap()
8288
)
8389

8490
override fun toJson(): JsonObject {
@@ -96,7 +102,7 @@ data class LiveMeter(
96102
json.put("applyImmediately", applyImmediately)
97103
json.put("applied", applied)
98104
json.put("pending", pending)
99-
json.put("throttle", throttle?.toJson())
105+
json.put("throttle", throttle.toJson())
100106
json.put("meta", JsonObject(meta))
101107
return json
102108
}

src/main/kotlin/spp/protocol/instrument/LiveSpan.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package spp.protocol.instrument
1818

1919
import io.vertx.codegen.annotations.DataObject
20+
import io.vertx.core.json.JsonArray
2021
import io.vertx.core.json.JsonObject
2122
import spp.protocol.instrument.location.LiveSourceLocation
2223
import spp.protocol.instrument.throttle.InstrumentThrottle
@@ -37,7 +38,7 @@ data class LiveSpan(
3738
override val applyImmediately: Boolean = false,
3839
override val applied: Boolean = false,
3940
override val pending: Boolean = false,
40-
override val throttle: InstrumentThrottle? = null,
41+
override val throttle: InstrumentThrottle = InstrumentThrottle.DEFAULT,
4142
override val meta: Map<String, Any> = emptyMap()
4243
) : LiveInstrument() {
4344
override val type: LiveInstrumentType = LiveInstrumentType.SPAN
@@ -52,8 +53,14 @@ data class LiveSpan(
5253
applyImmediately = json.getBoolean("applyImmediately") ?: false,
5354
applied = json.getBoolean("applied") ?: false,
5455
pending = json.getBoolean("pending") ?: false,
55-
throttle = json.getJsonObject("throttle")?.let { InstrumentThrottle(it) },
56-
meta = json.getJsonObject("meta")?.associate { it.key to it.value } ?: emptyMap()
56+
throttle = json.getJsonObject("throttle")?.let { InstrumentThrottle(it) } ?: InstrumentThrottle.DEFAULT,
57+
meta = json.getValue("meta")?.let {
58+
if (it is JsonObject) {
59+
it.associate { it.key to it.value }
60+
} else {
61+
toJsonMap(it as JsonArray)
62+
}
63+
} ?: emptyMap()
5764
)
5865

5966
override fun toJson(): JsonObject {
@@ -68,7 +75,7 @@ data class LiveSpan(
6875
json.put("applyImmediately", applyImmediately)
6976
json.put("applied", applied)
7077
json.put("pending", pending)
71-
json.put("throttle", throttle?.toJson())
78+
json.put("throttle", throttle.toJson())
7279
json.put("meta", JsonObject(meta))
7380
return json
7481
}

0 commit comments

Comments
 (0)