Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/kotlin/com/cosmotech/api/loki/LokiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.readValue
import java.time.Instant
import kotlin.math.min
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days
import org.json.JSONArray
import org.json.JSONObject
import org.springframework.http.HttpHeaders
Expand Down Expand Up @@ -60,9 +62,10 @@ class LokiService(private val csmPlatformProperties: CsmPlatformProperties) {
val lokiConfig = getLokiConfig()
val maxQueryLengthNano =
Duration.parse(lokiConfig.limitsConfig.maxQueryLength).inWholeNanoseconds
val queryLengthNano = min(maxQueryLengthNano, 1.days.inWholeNanoseconds)

val startTimeNano = startTime.toEpochMilli() * MILLI_TO_NANO
val endTimeNano = startTimeNano + maxQueryLengthNano
val endTimeNano = startTimeNano + queryLengthNano

val params = LinkedMultiValueMap<String, String>()
params.add("query", "{namespace=\"$namespace\",pod=\"$podName\",container=\"main\"}")
Expand Down Expand Up @@ -98,7 +101,7 @@ class LokiService(private val csmPlatformProperties: CsmPlatformProperties) {
logEntries.lastOrNull()?.let {
val newStartTime = it.getLong(0) + 1
params.set("start", newStartTime.toString())
params.set("end", (newStartTime + maxQueryLengthNano).toString())
params.set("end", (newStartTime + queryLengthNano).toString())
}
} while (logEntries.size >= lokiConfig.limitsConfig.maxEntriesLimitPerQuery)

Expand Down