Skip to content
Snippets Groups Projects
Commit 85b1e975 authored by Sören Henning's avatar Sören Henning
Browse files

Allow taking more metrics than just the first one

parent 5297a676
No related branches found
No related tags found
No related merge requests found
Pipeline #14546 passed
...@@ -26,7 +26,7 @@ class AnalysisExecutor( ...@@ -26,7 +26,7 @@ class AnalysisExecutor(
/** /**
* Analyses an experiment via prometheus data. * Analyses an experiment via prometheus data.
* First fetches data from prometheus, then documents them and afterwards evaluate it via a [slo]. * First fetches data from prometheus, then documents them and afterward evaluate it via a [slo].
* @param load of the experiment. * @param load of the experiment.
* @param resource of the experiment. * @param resource of the experiment.
* @param executionIntervals list of start and end points of experiments * @param executionIntervals list of start and end points of experiments
...@@ -41,6 +41,7 @@ class AnalysisExecutor( ...@@ -41,6 +41,7 @@ class AnalysisExecutor(
val fileURL = "${resultsFolder}exp${executionId}_${load}_${resource}_${slo.sloType.toSlug()}" val fileURL = "${resultsFolder}exp${executionId}_${load}_${resource}_${slo.sloType.toSlug()}"
val stepSize = slo.properties["promQLStepSeconds"]?.toLong()?.let { Duration.ofSeconds(it) } ?: DEFAULT_STEP_SIZE val stepSize = slo.properties["promQLStepSeconds"]?.toLong()?.let { Duration.ofSeconds(it) } ?: DEFAULT_STEP_SIZE
val onlyFirstMetric = slo.properties["takeOnlyFirstMetric"]?.toBoolean() ?: true
val prometheusData = executionIntervals val prometheusData = executionIntervals
.map { interval -> .map { interval ->
...@@ -55,7 +56,7 @@ class AnalysisExecutor( ...@@ -55,7 +56,7 @@ class AnalysisExecutor(
prometheusData.forEach{ data -> prometheusData.forEach{ data ->
ioHandler.writeToCSVFile( ioHandler.writeToCSVFile(
fileURL = "${fileURL}_${slo.name}_${repetitionCounter++}", fileURL = "${fileURL}_${slo.name}_${repetitionCounter++}",
data = data.getResultAsList(), data = data.getResultAsList(onlyFirst = onlyFirstMetric),
columns = listOf("labels", "timestamp", "value") columns = listOf("labels", "timestamp", "value")
) )
} }
......
...@@ -24,20 +24,24 @@ data class PrometheusResponse( ...@@ -24,20 +24,24 @@ data class PrometheusResponse(
* The format of the returned list is: `[[ group, timestamp, value ], [ group, timestamp, value ], ... ]` * The format of the returned list is: `[[ group, timestamp, value ], [ group, timestamp, value ], ... ]`
*/ */
@JsonIgnore @JsonIgnore
fun getResultAsList(): List<List<String>> { fun getResultAsList(onlyFirst: Boolean = true): List<List<String>> {
val group = data?.result?.get(0)?.metric?.toString()!! val resultsList = mutableListOf<List<String>>()
val values = data?.result?.get(0)?.values
val result = mutableListOf<List<String>>()
if (values != null) { val results = data?.result ?: throw IllegalStateException("No 'results' available in the Prometheus response.")
for (value in values) { for (result in results.subList(0, if (onlyFirst && results.isNotEmpty()) 1 else results.size)) {
val valueList = value as List<*> val group = result.metric.toString()
val timestamp = (valueList[0] as Double).toLong().toString() val values = result.values
val resultValue = valueList[1].toString()
result.add(listOf(group, timestamp, resultValue)) if (values != null) {
for (value in values) {
val valueList = value as List<*>
val timestamp = (valueList[0] as Number).toLong().toString()
val resultValue = valueList[1].toString()
resultsList.add(listOf(group, timestamp, resultValue))
}
} }
} }
return Collections.unmodifiableList(result) return resultsList.toList()
} }
} }
......
package rocks.theodolite.kubernetes.slo
import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*
class PrometheusResponseTest {
private val objectMapper = ObjectMapper()
@Test
fun testSingleTimeseriesListConvert() {
val prometheusResponse = readSingleTimeseriesResponse()
val resultsList = prometheusResponse.getResultAsList()
assertEquals(126, resultsList.size)
}
@Test
fun testSingleTimeseriesWithNoMillisListConvert() {
val prometheusResponse = readSingleTimeseriesNoMillisResponse()
val resultsList = prometheusResponse.getResultAsList()
assertEquals(11, resultsList.size)
}
@Test
fun testNoTimeseriesListConvert() {
val prometheusResponse = readNoTimeseriesResponse()
val resultsList = prometheusResponse.getResultAsList()
assertEquals(0, resultsList.size)
}
@Test
fun testMultiTimeseriesListConvertWithOnlyFirst() {
val prometheusResponse = readMultiTimeseriesResponse()
val resultsList = prometheusResponse.getResultAsList()
assertEquals(17, resultsList.size)
}
@Test
fun testMultiTimeseriesListConvertWithoutOnlyFirst() {
val prometheusResponse = readMultiTimeseriesResponse()
val resultsList = prometheusResponse.getResultAsList(onlyFirst = false)
assertEquals(1700, resultsList.size)
}
private fun readMultiTimeseriesResponse(): PrometheusResponse {
return objectMapper.readValue(
javaClass.getResourceAsStream("/prometheus-response/multi-timeseries.json"),
PrometheusResponse::class.java
)
}
private fun readSingleTimeseriesResponse(): PrometheusResponse {
return objectMapper.readValue(
javaClass.getResourceAsStream("/prometheus-response/single-timeseries.json"),
PrometheusResponse::class.java
)
}
private fun readSingleTimeseriesNoMillisResponse(): PrometheusResponse {
return objectMapper.readValue(
javaClass.getResourceAsStream("/prometheus-response/single-timeseries-nomillis.json"),
PrometheusResponse::class.java
)
}
private fun readNoTimeseriesResponse(): PrometheusResponse {
return objectMapper.readValue(
javaClass.getResourceAsStream("/prometheus-response/empty-timeseries.json"),
PrometheusResponse::class.java
)
}
}
\ No newline at end of file
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
]
}
}
\ No newline at end of file
This diff is collapsed.
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"consumergroup": "shufflebench-kstreams",
"topic": "input"
},
"values": [
[
1702453465,
"345824"
],
[
1702453466,
"306612"
],
[
1702453467,
"337641"
],
[
1702453468,
"320957"
],
[
1702453469,
"334418"
],
[
1702453470,
"327339"
],
[
1702453471,
"311165"
],
[
1702453472,
"342963"
],
[
1702453473,
"328380"
],
[
1702453474,
"314322"
],
[
1702453475,
"326701"
]
]
}
]
}
}
\ No newline at end of file
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"consumergroup": "shufflebench-kstreams",
"topic": "input"
},
"values": [
[
1702453425.792,
"45827.099200000026"
],
[
1702453426.792,
"52723.40266666667"
],
[
1702453427.792,
"60765.52030769229"
],
[
1702453428.792,
"67724.00274285715"
],
[
1702453429.792,
"77071.35011555557"
],
[
1702453430.792,
"77806.98444444445"
],
[
1702453431.792,
"90319.11422188251"
],
[
1702453432.792,
"95559.55282962965"
],
[
1702453433.792,
"102681.91541052636"
],
[
1702453434.792,
"110680.77280000002"
],
[
1702453435.792,
"118175.76382222223"
],
[
1702453436.792,
"125235.98559999997"
],
[
1702453437.792,
"133313.9763130435"
],
[
1702453438.792,
"141982.56413333333"
],
[
1702453439.792,
"150182.53309866664"
],
[
1702453440.792,
"157938.50800000003"
],
[
1702453441.792,
"165152.25259259256"
],
[
1702453442.792,
"173734.9929142857"
],
[
1702453443.792,
"181751.8033655173"
],
[
1702453444.792,
"189359.48100229882"
],
[
1702453445.792,
"195329.68965517235"
],
[
1702453446.792,
"201464.6896551724"
],
[
1702453447.792,
"206828.79310344832"
],
[
1702453448.792,
"212666.41379310348"
],
[
1702453449.792,
"219041.89655172417"
],
[
1702453450.792,
"225580.8620689655"
],
[
1702453451.792,
"233049.82758620693"
],
[
1702453452.792,
"241729.99999999997"
],
[
1702453453.792,
"248566.5172413793"
],
[
1702453454.792,
"256626.17241379313"
],
[
1702453455.792,
"263996.7586206896"
],
[
1702453456.792,
"267141.20689655177"
],
[
1702453457.792,
"273647.34482758614"
],
[
1702453458.792,
"276918.17241379316"
],
[
1702453459.792,
"275514.8739531925"
],
[
1702453460.792,
"289042.39246662747"
],
[
1702453461.792,
"295689.0344827587"
],
[
1702453462.792,
"299088.44827586215"
],
[
1702453463.792,
"302463.9655172414"
],
[
1702453464.792,
"306671.20689655177"
],
[
1702453465.792,
"309965.79310344823"
],
[
1702453466.792,
"313291.17241379304"
],
[
1702453467.792,
"315435.8965517242"
],
[
1702453468.792,
"318519.3103448276"
],
[
1702453469.792,
"321809.172413793"
],
[
1702453470.792,
"325093.1379310345"
],
[
1702453471.792,
"328073.79310344823"
],
[
1702453472.792,
"331127.7586206897"
],
[
1702453473.792,
"333080.99999999994"
],
[
1702453474.792,
"334463.68965517235"
],
[
1702453475.792,
"337053.1034482758"
],
[
1702453476.792,
"338064.41379310336"
],
[
1702453477.792,
"339256.79310344806"
],
[
1702453478.792,
"340640.13793103455"
],
[
1702453479.792,
"340302.8965517242"
],
[
1702453480.792,
"340739.03448275855"
],
[
1702453481.792,
"338241.13793103455"
],
[
1702453482.792,
"336843.68965517235"
],
[
1702453483.792,
"333786.24137931026"
],
[
1702453484.792,
"330203.724137931"
],
[
1702453485.792,
"329070.2068965517"
],
[
1702453486.792,
"325565.6206896553"
],
[
1702453487.792,
"323903.31034482754"
],
[
1702453488.792,
"320569.2413793104"
],
[
1702453489.792,
"319020.51724137936"
],
[
1702453490.792,
"318235.3448275862"
],
[
1702453491.792,
"317969.0689655172"
],
[
1702453492.792,
"317677.3103448276"
],
[
1702453493.792,
"316547.03123922495"
],
[
1702453494.792,
"316003.4137931034"
],
[
1702453495.792,
"315336.27586206887"
],
[
1702453496.792,
"315274.13793103455"
],
[
1702453497.792,
"312991.3448275861"
],
[
1702453498.792,
"312337.65517241374"
],
[
1702453499.792,
"312506.96551724133"
],
[
1702453500.792,
"311033.4482758621"
],
[
1702453501.792,
"309570.68965517246"
],
[
1702453502.792,
"309230.41379310354"
],
[
1702453503.792,
"308299.14146812406"
],
[
1702453504.792,
"306043.6206896553"
],
[
1702453505.792,
"306161.7241379311"
],
[
1702453506.792,
"306388.79310344823"
],
[
1702453507.792,
"305580.1379310345"
],
[
1702453508.792,
"305641.44827586215"
],
[
1702453509.792,
"305662.3103448276"
],
[
1702453510.792,
"304721.55172413803"
],
[
1702453511.792,
"304220.5978691861"
],
[
1702453512.792,
"303531.6896551724"
],
[
1702453513.792,
"303937.5862068966"
],
[
1702453514.792,
"304194.4482758622"
],
[
1702453515.792,
"303117.2413793105"
],
[
1702453516.792,
"303564.275862069"
],
[
1702453517.792,
"303871.82758620684"
],
[
1702453518.792,
"303023.9310344827"
],
[
1702453519.792,
"302069.0000000001"
],
[
1702453520.792,
"301651.6896551723"
],
[
1702453521.792,
"301092.2758620691"
],
[
1702453522.792,
"300639.56134905847"
],
[
1702453523.792,
"300419.51724137925"
],
[
1702453524.792,
"300222.10344827577"
],
[
1702453525.792,
"299006.0689655174"
],
[
1702453526.792,
"300240.5517241379"
],
[
1702453527.792,
"300220.48275862064"
],
[
1702453528.792,
"299525.1379310345"
],
[
1702453529.792,
"299322.99999999994"
],
[
1702453530.792,
"300305.9999999998"
],
[
1702453531.792,
"299742.79310344846"
],
[
1702453532.792,
"291230.3614539058"
],
[
1702453533.792,
"281468.3237925926"
],
[
1702453534.792,
"271455.4275794871"
],
[
1702453535.792,
"261288.143408"
],
[
1702453536.792,
"251146.61436111113"
],
[
1702453537.792,
"241390.022452174"
],
[
1702453538.792,
"230399.12869090916"
],
[
1702453539.792,
"221125.3156"
],
[
1702453540.792,
"211518.3795306796"
],
[
1702453541.792,
"201742.17143157902"
],
[
1702453542.792,
"190820.63507407412"
],
[
1702453543.792,
"180676.1147686275"
],
[
1702453544.792,
"172003.79995000002"
],
[
1702453545.792,
"160685.19543999998"
],
[
1702453546.792,
"150690.0318"
],
[
1702453547.792,
"141092.0908615384"
],
[
1702453548.792,
"131065.18059999999"
],
[
1702453549.792,
"121379.87103030298"
],
[
1702453550.792,
"110942.14616000002"
]
]
}
]
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment