Skip to content

Commit

Permalink
Make Prometheus step resolution configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
SoerenHenning committed Nov 20, 2023
1 parent 9bf2e09 commit d8fc284
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package rocks.theodolite.kubernetes.slo

import rocks.theodolite.core.strategies.Metric
import rocks.theodolite.core.IOHandler
import rocks.theodolite.kubernetes.model.KubernetesBenchmark.Slo
import java.text.Normalizer
Expand All @@ -9,6 +8,8 @@ import java.time.Instant
import java.util.*
import java.util.regex.Pattern

private val DEFAULT_STEP_SIZE = Duration.ofSeconds(5)

/**
* Contains the analysis. Fetches a metric from Prometheus, documents it, and evaluates it.
* @param slo Slo that is used for the analysis.
Expand Down Expand Up @@ -39,11 +40,14 @@ class AnalysisExecutor(
val resultsFolder = ioHandler.getResultFolderURL()
val fileURL = "${resultsFolder}exp${executionId}_${load}_${resource}_${slo.sloType.toSlug()}"

val stepSize = slo.properties["promQLStepSeconds"]?.toLong()?.let { Duration.ofSeconds(it) } ?: DEFAULT_STEP_SIZE

val prometheusData = executionIntervals
.map { interval ->
fetcher.fetchMetric(
start = interval.first,
end = interval.second,
stepSize = stepSize,
query = SloConfigHandler.getQueryString(slo = slo)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MetricFetcher(private val prometheusURL: String, private val offset: Durat
* @param query query for the prometheus server.
* @throws ConnectException - if the prometheus server timed out/was not reached.
*/
fun fetchMetric(start: Instant, end: Instant, query: String): PrometheusResponse {
fun fetchMetric(start: Instant, end: Instant, stepSize: Duration, query: String): PrometheusResponse {

val offsetStart = start.minus(offset)
val offsetEnd = end.minus(offset)
Expand All @@ -46,7 +46,7 @@ class MetricFetcher(private val prometheusURL: String, private val offset: Durat
val encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8)
val request = HttpRequest.newBuilder()
.uri(URI.create(
"$prometheusURL/api/v1/query_range?query=$encodedQuery&start=$offsetStart&end=$offsetEnd&step=5s"))
"$prometheusURL/api/v1/query_range?query=$encodedQuery&start=$offsetStart&end=$offsetEnd&step={${stepSize.toSeconds()}}s"))
.GET()
.version(HttpClient.Version.HTTP_1_1)
.timeout(TIMEOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ internal class MetricFetcherTest {
val response = metricFetcher.fetchMetric(
exampleDateTime.minus(Duration.ofMinutes(10)),
exampleDateTime,
Duration.ofSeconds(5),
"sum by(consumergroup) (kafka_consumergroup_lag >= 0)")

assertEquals(emptyPrometheusResponse, response)
Expand Down

0 comments on commit d8fc284

Please sign in to comment.