Skip to content
Open
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GeneralCacheSpec : ShouldSpec({
val postResponse = prebidCacheApi.postCache(requestObject)

// when: GET cache endpoint is called
val getCacheResponse = BaseSpec.getPrebidCacheApi().getCache(postResponse.responses[0].uuid)
val getCacheResponse = prebidCacheApi.getCache(postResponse.responses[0].uuid)

// then: response content type is the same as request object type
getCacheResponse.contentType()?.contentType shouldBe "application"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import org.prebid.cache.functional.BaseSpec.Companion.prebidCacheConfig
import org.prebid.cache.functional.model.request.PayloadTransfer
import org.prebid.cache.functional.service.ApiException
import org.prebid.cache.functional.service.PrebidCacheApi
import org.prebid.cache.functional.util.getRandomLong
import org.prebid.cache.functional.util.getRandomString
import org.springframework.http.HttpStatus.BAD_REQUEST
import org.springframework.http.HttpStatus.NOT_FOUND
import org.springframework.http.HttpStatus.UNAUTHORIZED
import org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR

class StorageSpec : ShouldSpec({
class RedisModuleStorageSpec : ShouldSpec({

lateinit var apiKey: String
lateinit var applicationName: String
Expand All @@ -27,7 +28,7 @@ class StorageSpec : ShouldSpec({
beforeSpec {
apiKey = getRandomString()
applicationName = getRandomString().lowercase(Locale.getDefault())
val config = prebidCacheConfig.getBaseModuleStorageConfig(applicationName, apiKey)
val config = prebidCacheConfig.getRedisModuleStorageConfig(applicationName, apiKey)
cacheApi = BaseSpec.getPrebidCacheApi(config)
}

Expand Down Expand Up @@ -78,7 +79,7 @@ class StorageSpec : ShouldSpec({
val payloadTransfer = PayloadTransfer.getDefaultJsonPayloadTransfer().apply {
key = payloadKey
application = applicationName
ttlseconds = 300L
ttlseconds = getRandomLong(300, 1000)
}

// when: POST module-storage endpoint is called
Expand All @@ -104,7 +105,8 @@ class StorageSpec : ShouldSpec({

// when: POST module-storage endpoint is called
val exception = shouldThrowExactly<ApiException> {
cacheApi.postStorageCache(payloadTransfer, apiKey) }
cacheApi.postStorageCache(payloadTransfer, apiKey)
}

// then: Not found exception is thrown
assertSoftly {
Expand Down Expand Up @@ -291,7 +293,8 @@ class StorageSpec : ShouldSpec({

// when: POST module-storage endpoint is called
val exception = shouldThrowExactly<ApiException> {
cacheApi.postStorageCache(payloadTransfer, apiKey) }
cacheApi.postStorageCache(payloadTransfer, apiKey)
}

// then: Expire time exception is thrown
assertSoftly {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.prebid.cache.functional.model.request

data class AvailableTag(
val tag: String,
val values: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.prebid.cache.functional.model.request

data class Measurement(
val statistic: String,
val value: Number
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.prebid.cache.functional.model.request

data class MetricDetail(
val name: String,
val description: String? = null,
val baseUnit: String? = null,
val measurements: List<Measurement>,
val availableTags: List<AvailableTag>
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.ktor.http.ContentType.Application.Json
import io.ktor.http.HttpHeaders.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.serialization.jackson.jackson
import org.prebid.cache.functional.model.request.MetricDetail
import org.prebid.cache.functional.model.request.PayloadTransfer
import org.prebid.cache.functional.model.request.RequestObject
import org.prebid.cache.functional.model.response.ResponseObject
Expand Down Expand Up @@ -113,6 +114,19 @@ class PrebidCacheApi(
}
}

suspend fun getMetrics(): Map<String, Number> {
val response: Map<String, List<String>> = get(endpoint = METRICS_ENDPOINT).body()
val metricNames = response["names"] ?: emptyList()
val results: List<Pair<String, Number>> = metricNames.map { name ->
val detail: MetricDetail = get(endpoint = "$METRICS_ENDPOINT/$name").body()
val countValue = detail.measurements
.firstOrNull { it.statistic == "COUNT" }
?.value?.toInt() ?: 0
name to countValue
}
return results.toMap()
}

companion object {
private const val CACHE_ENDPOINT = "/cache"
private const val UUID_QUERY_PARAMETER = "uuid"
Expand All @@ -123,5 +137,7 @@ class PrebidCacheApi(
private const val API_KEY_PARAMETER = "x-pbc-api-key"
private const val KEY_PARAMETER = "k"
private const val APPLICATION_PARAMETER = "a"

private const val METRICS_ENDPOINT = "/metrics"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ class PrebidCacheContainerConfig(
): Map<String, String> =
getBaseConfig(allowExternalUuid, cacheWriteSecured) + getApacheIgniteConfig(ingineCacheName)

fun getBaseModuleStorageConfig(applicationName: String, apiKey: String): Map<String, String> =
fun getRedisModuleStorageConfig(applicationName: String, apiKey: String): Map<String, String> =
getBaseConfig(allowExternalUuid = true, apiKey = apiKey) +
getModuleStorageRedisConfig(applicationName) + getRedisConfig()

fun getAerospikeModuleStorageConfig(
applicationName: String,
apiKey: String,
aerospikeNamespace: String = NAMESPACE
): Map<String, String> = getBaseConfig(allowExternalUuid = true, apiKey = apiKey) +
getModuleStorageAerospikeConfig(applicationName) +
getAerospikeConfig(aerospikeNamespace)

fun getCacheExpiryConfig(minExpiry: String = "15", maxExpiry: String = "28800"): Map<String, String> =
mapOf(
"cache.min.expiry" to minExpiry,
Expand Down Expand Up @@ -92,12 +100,29 @@ class PrebidCacheContainerConfig(

private fun getModuleStorageRedisConfig(
applicationName: String,
timeoutMs: Long = 9999L,
): Map<String, String> =
mapOf(
"storage.redis.${applicationName}.port" to RedisContainer.PORT.toString(),
"storage.redis.${applicationName}.host" to redisHost,
"storage.redis.${applicationName}.timeout" to timeoutMs.toString(),
"storage.redis.${applicationName}.timeout" to "9999",
"storage.default-ttl-seconds" to 1000L.toString()
)

private fun getModuleStorageAerospikeConfig(
applicationName: String,
preventUuidDuplication: Boolean = false,
): Map<String, String> =
mapOf(
"storage.aerospike.${applicationName}.port" to AerospikeContainer.PORT.toString(),
"storage.aerospike.${applicationName}.host" to aerospikeHost,
"storage.aerospike.${applicationName}.cores" to "4",
"storage.aerospike.${applicationName}.timeout" to "9999",
"storage.aerospike.${applicationName}.password" to "",
"storage.aerospike.${applicationName}.first_backoff" to "300",
"storage.aerospike.${applicationName}.max_backoff" to "1000",
"storage.aerospike.${applicationName}.max_retry" to "3",
"storage.aerospike.${applicationName}.namespace" to NAMESPACE,
"storage.aerospike.${applicationName}.prevent-u-u-i-d-duplication" to preventUuidDuplication.toString(),
"storage.default-ttl-seconds" to 1000L.toString()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically the base config + getAerospikePreventUuidDuplicationConfig, so why not use them?

Copy link
Collaborator Author

@marki1an marki1an Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAerospikePreventUuidDuplicationConfig and storage.aerospike.${applicationName}.prevent-u-u-i-d-duplication different property

)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.cache.functional.util

import java.util.*
import java.util.UUID
import java.util.Random

fun getRandomUuid(): String = UUID.randomUUID().toString()

Expand All @@ -9,4 +10,4 @@ fun getRandomString(length: Int = 16): String {
return List(length) { allowedChars.random() }.joinToString("")
}

fun getRandomLong(length: Int = 16): Long = Random().nextInt(length).toLong()
fun getRandomLong(start: Int = 0, end: Int = 16): Long = Random().nextInt(start, end).toLong()