Skip to content

Commit 8614b7f

Browse files
committed
chore: save meter rules
1 parent afb4425 commit 8614b7f

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

boot/src/test/kotlin/integration/meter/MeterGaugeTest.kt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import spp.protocol.service.SourceServices.Subscribe.toLiveViewSubscriberAddress
3434
import spp.protocol.view.LiveView
3535
import spp.protocol.view.LiveViewConfig
3636
import spp.protocol.view.LiveViewEvent
37+
import spp.protocol.view.rule.LiveViewRule
3738
import java.io.ByteArrayOutputStream
3839
import java.io.ObjectOutputStream
3940
import java.io.Serializable
@@ -63,13 +64,26 @@ class MeterGaugeTest : ProbeIntegrationTest() {
6364
MetricValue(MetricValueType.NUMBER_SUPPLIER, encodedSupplier),
6465
location = LiveSourceLocation(
6566
MeterGaugeTest::class.qualifiedName!!,
66-
47,
67+
48,
6768
"spp-test-probe"
6869
),
6970
id = meterId,
7071
applyImmediately = true
7172
)
7273

74+
viewService.saveRuleIfAbsent(
75+
LiveViewRule(
76+
name = liveMeter.toMetricIdWithoutPrefix(),
77+
exp = buildString {
78+
append("(")
79+
append(liveMeter.toMetricIdWithoutPrefix())
80+
append(".downsampling(LATEST)")
81+
append(")")
82+
append(".instance(['service'], ['instance'], Layer.GENERAL)")
83+
}
84+
)
85+
).await()
86+
7387
val subscriptionId = viewService.addLiveView(
7488
LiveView(
7589
entityIds = mutableSetOf(liveMeter.toMetricId()),
@@ -79,7 +93,7 @@ class MeterGaugeTest : ProbeIntegrationTest() {
7993
),
8094
artifactLocation = LiveSourceLocation(
8195
MeterGaugeTest::class.qualifiedName!!,
82-
47
96+
48
8397
),
8498
viewConfig = LiveViewConfig(
8599
"test",
@@ -128,13 +142,26 @@ class MeterGaugeTest : ProbeIntegrationTest() {
128142
MetricValue(MetricValueType.NUMBER_EXPRESSION, "localVariables[i]"),
129143
location = LiveSourceLocation(
130144
MeterGaugeTest::class.qualifiedName!!,
131-
47,
145+
48,
132146
"spp-test-probe"
133147
),
134148
id = meterId,
135149
applyImmediately = true
136150
)
137151

152+
viewService.saveRuleIfAbsent(
153+
LiveViewRule(
154+
name = liveMeter.toMetricIdWithoutPrefix(),
155+
exp = buildString {
156+
append("(")
157+
append(liveMeter.toMetricIdWithoutPrefix())
158+
append(".downsampling(LATEST)")
159+
append(")")
160+
append(".instance(['service'], ['instance'], Layer.GENERAL)")
161+
}
162+
)
163+
).await()
164+
138165
val subscriptionId = viewService.addLiveView(
139166
LiveView(
140167
entityIds = mutableSetOf(liveMeter.toMetricId()),
@@ -144,7 +171,7 @@ class MeterGaugeTest : ProbeIntegrationTest() {
144171
),
145172
artifactLocation = LiveSourceLocation(
146173
MeterGaugeTest::class.qualifiedName!!,
147-
47
174+
48
148175
),
149176
viewConfig = LiveViewConfig(
150177
"test",

boot/src/test/kotlin/integration/meter/MeterReturnValueTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import spp.protocol.service.SourceServices
3535
import spp.protocol.view.LiveView
3636
import spp.protocol.view.LiveViewConfig
3737
import spp.protocol.view.LiveViewEvent
38+
import spp.protocol.view.rule.LiveViewRule
3839

3940
class MeterReturnValueTest : ProbeIntegrationTest() {
4041

@@ -59,6 +60,20 @@ class MeterReturnValueTest : ProbeIntegrationTest() {
5960
hitLimit = 1
6061
)
6162

63+
viewService.saveRuleIfAbsent(
64+
LiveViewRule(
65+
name = liveMeter.toMetricIdWithoutPrefix(),
66+
exp = buildString {
67+
append("(")
68+
append(liveMeter.toMetricIdWithoutPrefix())
69+
append(".sum(['service', 'instance'])")
70+
append(".downsampling(SUM)")
71+
append(")")
72+
append(".instance(['service'], ['instance'], Layer.GENERAL)")
73+
}
74+
)
75+
).await()
76+
6277
val subscriptionId = viewService.addLiveView(
6378
LiveView(
6479
entityIds = mutableSetOf(liveMeter.toMetricId()),

0 commit comments

Comments
 (0)