Skip to content

Commit

Permalink
feat: new cohort api
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Aug 2, 2024
1 parent 5266906 commit b123d93
Show file tree
Hide file tree
Showing 44 changed files with 2,657 additions and 616 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lint:
./gradlew ktlintFormat

run: build
PROXY_CONFIG_FILE_PATH=`pwd`/config.yaml ./gradlew run --console=plain
AMPLITUDE_LOG_LEVEL=DEBUG PROXY_CONFIG_FILE_PATH=`pwd`/config.yaml PROXY_PROJECTS_FILE_PATH=`pwd`/projects.yaml ./gradlew run --console=plain

docker-build: build
docker build -t evaluation-proxy:local .
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "1.9.10"
kotlin("jvm") version "2.0.0"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

Expand Down
14 changes: 9 additions & 5 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.9.10"
kotlin("plugin.serialization") version "1.9.0"
kotlin("jvm") version "2.0.0"
kotlin("plugin.serialization") version "2.0.0"
`maven-publish`
signing
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
id("org.jlleitschuh.gradle.ktlint") version "12.1.1"
}

java {
Expand All @@ -20,23 +20,27 @@ tasks {
// Defined in gradle.properties
val kotlinVersion: String by project
val ktorVersion: String by project
val coroutinesVersion: String by project
val serializationVersion: String by project
val experimentEvaluationVersion: String by project
val amplitudeAnalytics: String by project
val amplitudeAnalyticsJson: String by project
val lettuce: String by project
val apacheCommons: String by project
val kaml: String by project
val mockk: String by project

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("com.amplitude:evaluation-core:$experimentEvaluationVersion")
implementation("com.amplitude:java-sdk:$amplitudeAnalytics")
implementation("org.json:json:$amplitudeAnalyticsJson")
implementation("io.lettuce:lettuce-core:$lettuce")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktorVersion")
implementation("com.charleskorn.kaml:kaml:$kaml")
implementation("org.apache.commons:commons-csv:$apacheCommons")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
testImplementation("io.mockk:mockk:$mockk")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
}

// Publishing
Expand Down
60 changes: 54 additions & 6 deletions core/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ data class ProjectConfiguration(
@Serializable
data class Configuration(
val port: Int = Default.PORT,
val serverUrl: String = Default.SERVER_URL,
val cohortServerUrl: String = Default.COHORT_SERVER_URL,
val serverZone: String = Default.SERVER_ZONE,
val serverUrl: String = getServerUrl(serverZone),
val cohortServerUrl: String = getCohortServerUrl(serverZone),
val managementServerUrl: String = getManagementServerUrl(serverZone),
val analyticsServerUrl: String = getAnalyticsServerUrl(serverZone),
val deploymentSyncIntervalMillis: Long = Default.DEPLOYMENT_SYNC_INTERVAL_MILLIS,
val flagSyncIntervalMillis: Long = Default.FLAG_SYNC_INTERVAL_MILLIS,
val cohortSyncIntervalMillis: Long = Default.COHORT_SYNC_INTERVAL_MILLIS,
Expand All @@ -88,8 +91,11 @@ data class Configuration(
companion object {
fun fromEnv() = Configuration(
port = intEnv(EnvKey.PORT, Default.PORT)!!,
serverUrl = stringEnv(EnvKey.SERVER_URL, Default.SERVER_URL)!!,
cohortServerUrl = stringEnv(EnvKey.COHORT_SERVER_URL, Default.COHORT_SERVER_URL)!!,
serverZone = stringEnv(EnvKey.SERVER_ZONE, Default.SERVER_ZONE)!!,
serverUrl = stringEnv(EnvKey.SERVER_URL, Default.US_SERVER_URL)!!,
cohortServerUrl = stringEnv(EnvKey.COHORT_SERVER_URL, Default.US_COHORT_SERVER_URL)!!,
managementServerUrl = stringEnv(EnvKey.MANAGEMENT_SERVER_URL, Default.US_MANAGEMENT_SERVER_URL)!!,
analyticsServerUrl = stringEnv(EnvKey.ANALYTICS_SERVER_URL, Default.US_ANALYTICS_SERVER_URL)!!,
deploymentSyncIntervalMillis = longEnv(
EnvKey.DEPLOYMENT_SYNC_INTERVAL_MILLIS,
Default.DEPLOYMENT_SYNC_INTERVAL_MILLIS
Expand Down Expand Up @@ -164,8 +170,11 @@ data class RedisConfiguration(

object EnvKey {
const val PORT = "AMPLITUDE_PORT"
const val SERVER_ZONE = "AMPLITUDE_SERVER_ZONE"
const val SERVER_URL = "AMPLITUDE_SERVER_URL"
const val COHORT_SERVER_URL = "AMPLITUDE_COHORT_SERVER_URL"
const val MANAGEMENT_SERVER_URL = "AMPLITUDE_MANAGEMENT_SERVER_URL"
const val ANALYTICS_SERVER_URL = "AMPLITUDE_ANALYTICS_SERVER_URL"

const val API_KEY = "AMPLITUDE_API_KEY"
const val SECRET_KEY = "AMPLITUDE_SECRET_KEY"
Expand All @@ -188,8 +197,15 @@ object EnvKey {

object Default {
const val PORT = 3546
const val SERVER_URL = "https://flag.lab.amplitude.com"
const val COHORT_SERVER_URL = "https://cohort.lab.amplitude.com"
const val SERVER_ZONE = "US"
const val US_SERVER_URL = "https://flag.lab.amplitude.com"
const val US_COHORT_SERVER_URL = "https://cohort-v2.lab.amplitude.com"
const val US_MANAGEMENT_SERVER_URL = "https://experiment.amplitude.com"
const val US_ANALYTICS_SERVER_URL = "https://api2.amplitude.com/2/httpapi"
const val EU_SERVER_URL = "https://flag.lab.eu.amplitude.com"
const val EU_COHORT_SERVER_URL = "https://cohort-v2.lab.eu.amplitude.com"
const val EU_MANAGEMENT_SERVER_URL = "https://experiment.eu.amplitude.com"
const val EU_ANALYTICS_SERVER_URL = "https://api.eu.amplitude.com/2/httpapi"
const val DEPLOYMENT_SYNC_INTERVAL_MILLIS = 60 * 1000L
const val FLAG_SYNC_INTERVAL_MILLIS = 10 * 1000L
const val COHORT_SYNC_INTERVAL_MILLIS = 60 * 1000L
Expand All @@ -204,3 +220,35 @@ object Default {
val REDIS_READ_ONLY_URI: String? = null
const val REDIS_PREFIX = "amplitude"
}

private fun getServerUrl(zone: String): String {
return if (zone == "EU") {
Default.EU_SERVER_URL
} else {
Default.US_SERVER_URL
}
}

private fun getCohortServerUrl(zone: String): String {
return if (zone == "EU") {
Default.EU_COHORT_SERVER_URL
} else {
Default.US_COHORT_SERVER_URL
}
}

private fun getManagementServerUrl(zone: String): String {
return if (zone == "EU") {
Default.EU_MANAGEMENT_SERVER_URL
} else {
Default.US_MANAGEMENT_SERVER_URL
}
}

private fun getAnalyticsServerUrl(zone: String): String {
return if (zone == "EU") {
Default.EU_ANALYTICS_SERVER_URL
} else {
Default.US_ANALYTICS_SERVER_URL
}
}
Loading

0 comments on commit b123d93

Please sign in to comment.