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
30 changes: 24 additions & 6 deletions .github/workflows/kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,38 @@ on:

env:
test_api_key: ${{ secrets.KONG_SERVER_SDK_KEY }}
test_client_key: ${{ secrets. KONG_CLIENT_SDK_KEY }}
repo_pat: ${{ secrets.KONG_FINE_GRAINED_REPO_PAT }}
test_client_key: ${{ secrets.KONG_CLIENT_SDK_KEY }}
OAI_GITHUB_APP_ID: ${{ secrets.OAI_GITHUB_APP_ID }}
OAI_GITHUB_APP_PRIVATE_KEY: ${{ secrets.OAI_GITHUB_APP_PRIVATE_KEY }}
FORCE_COLOR: true

jobs:
KONG:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3
id: app-token
with:
client-id: ${{ secrets.OAI_GITHUB_APP_ID }}
private-key: ${{ secrets.OAI_GITHUB_APP_PRIVATE_KEY }}
owner: openai
repositories: statsig-priv-kong
- name: Get KONG
run: git clone https://oauth2:$repo_pat@github.com/statsig-io/kong.git .
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ steps.app-token.outputs.token }}
repository: openai/statsig-priv-kong
ref: main
path: kong
persist-credentials: false

- uses: actions/setup-java@v4
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: "17"
distribution: "temurin"

- uses: actions/cache@v3
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
~/.gradle/caches
Expand All @@ -37,16 +51,20 @@ jobs:
${{ runner.os }}-android-gradle-

- name: Install Deps
working-directory: kong
run: npm install

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5

- name: Setup Android SDK
working-directory: kong
run: npm run kong -- setup android -v

- name: Precompile Android Bridge
working-directory: kong
run: (cd bridges/android-bridge ; ./gradlew assemble)

- name: Run Tests
working-directory: kong
run: npm run kong -- test android -v -r
6 changes: 3 additions & 3 deletions .github/workflows/publish-to-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: 'temurin'
java-version: '17'

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v5
uses: gradle/actions/wrapper-validation@0723195856401067f7a2779048b490ace7a47d7c # v5

- name: Grant Execute Permission for Gradlew
run: chmod +x gradlew
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
if: startsWith(github.head_ref, 'releases/') || github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: statsig-io/statsig-publish-sdk-action@main
- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3
id: app-token
with:
client-id: ${{ secrets.OAI_GITHUB_APP_ID }}
private-key: ${{ secrets.OAI_GITHUB_APP_PRIVATE_KEY }}
owner: openai
repositories: statsig-publish-sdk-action
- uses: openai/statsig-publish-sdk-action@main
with:
token: ${{ steps.app-token.outputs.token }}
kong-private-key: ${{ secrets.KONG_GH_APP_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Trigger Scheduled Test Runs
if: github.event.repository.private
uses: actions/github-script@v6
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const args = {
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ on:
jobs:
gradle:
timeout-minutes: 12
runs-on: ubuntu-latest-16core
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

- uses: actions/setup-java@v5
- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: 17
distribution: "adopt"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5

- name: Lint
run: ./gradlew ktLintCheck
Expand All @@ -30,7 +30,7 @@ jobs:

- name: Upload test report on failure
if: failure()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: test-report
path: build/reports/tests/testDebugUnitTest/
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
android.useAndroidX=true
libraryVersion=5.0.0
libraryVersion=5.1.0
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.problems=warn
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/statsig/androidsdk/StatsigClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class StatsigClient : LifecycleEventListener {

@VisibleForTesting
internal lateinit var options: StatsigOptions
private lateinit var runtimeMutableOptions: StatsigRuntimeMutableOptions

private lateinit var connectivityListener: StatsigNetworkConnectivityListener

Expand Down Expand Up @@ -675,7 +676,13 @@ class StatsigClient : LifecycleEventListener {
enforceInitialized(functionName)
errorBoundary.capture(
{
this.runtimeMutableOptions =
StatsigRuntimeMutableOptions(
loggingEnabled = runtimeMutableOptions.loggingEnabled,
eventLoggingAPI = runtimeMutableOptions.eventLoggingAPI
)
this.logger.setLoggingEnabled(runtimeMutableOptions.loggingEnabled)
this.logger.setApi(runtimeMutableOptions.eventLoggingAPI)
Log.v(TAG, "Runtime options successfully updated")
},
tag = functionName
Expand Down Expand Up @@ -1188,7 +1195,7 @@ class StatsigClient : LifecycleEventListener {
retryScope.launch(dispatcherProvider.io) {
try {
this@StatsigClient.statsigNetwork.apiRetryFailedLogs(
this@StatsigClient.options.eventLoggingAPI,
this@StatsigClient.runtimeMutableOptions.eventLoggingAPI,
this@StatsigClient.options.logEventFallbackUrls,
statsigClientMetadata
)
Expand Down Expand Up @@ -1267,6 +1274,11 @@ class StatsigClient : LifecycleEventListener {
this.keyValueStorage = storage
this.sdkKey = sdkKey
this.options = options
this.runtimeMutableOptions =
StatsigRuntimeMutableOptions(
loggingEnabled = options.loggingEnabled,
eventLoggingAPI = options.eventLoggingAPI
)
val normalizedUser = normalizeUser(user)
val initializeValues = options.initializeValues
this.user = normalizedUser
Expand Down Expand Up @@ -1313,14 +1325,14 @@ class StatsigClient : LifecycleEventListener {
StatsigLogger(
statsigScope,
sdkKey,
options.eventLoggingAPI,
runtimeMutableOptions.eventLoggingAPI,
statsigClientMetadata,
statsigNetwork,
normalizedUser,
{ store.getBootstrapMetadata() },
diagnostics,
options.logEventFallbackUrls,
options.loggingEnabled,
runtimeMutableOptions.loggingEnabled,
gson
)
populateStatsigMetadata()
Expand Down Expand Up @@ -1648,7 +1660,7 @@ class StatsigClient : LifecycleEventListener {
}
retryScope.launch(dispatcherProvider.io) {
statsigNetwork.apiRetryFailedLogs(
this@StatsigClient.options.eventLoggingAPI,
this@StatsigClient.runtimeMutableOptions.eventLoggingAPI,
this@StatsigClient.options.logEventFallbackUrls,
statsigClientMetadata
)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/statsig/androidsdk/StatsigLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal data class LogEventData(
internal class StatsigLogger(
private val coroutineScope: CoroutineScope,
private val sdkKey: String,
private val api: String,
private var api: String,
private val statsigMetadata: StatsigMetadata,
private val statsigNetwork: StatsigNetwork,
private val statsigUser: StatsigUser,
Expand Down Expand Up @@ -259,6 +259,10 @@ internal class StatsigLogger(
this.loggingEnabled = loggingEnabled
}

fun setApi(api: String) {
this.api = api
}

private fun addManualFlag(
metadata: MutableMap<String, Any?>,
isManual: Boolean
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/statsig/androidsdk/StatsigOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ class StatsigOptions(
@SerializedName("api") var api: String = DEFAULT_INIT_API,

/**
* The endpoint to use for logging events. Default is "https://api.statsig.com/v1".
* The SDK will hit different endpoints for initialize
* The endpoint to use for logging events. The SDK will hit different endpoints for initialize
* to evaluate gates and for logEvent to log event data. The api option controls the evaluation
* endpoint, and eventLoggingApi controls the event logging endpoint.
*/
@SerializedName("eventLoggingAPI") var eventLoggingAPI: String = DEFAULT_EVENT_API,
eventLoggingAPI: String = DEFAULT_EVENT_API,

/**
* The endpoint to use for logging sdk-internal exceptions for Statsig diagnostics.
Expand Down Expand Up @@ -166,7 +165,7 @@ class StatsigOptions(
var logNetworkMetadata: Boolean = false,

loggingEnabled: Boolean = DEFAULT_LOGGING_ENABLED
) : StatsigRuntimeMutableOptions(loggingEnabled) {
) : StatsigRuntimeMutableOptions(loggingEnabled, eventLoggingAPI) {

@SerializedName("autoValueUpdateIntervalMinutes")
var autoValueUpdateIntervalMinutes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ open class StatsigRuntimeMutableOptions(
* [loggingEnabled] defaults to true if a value is not provided.
*/
@SerializedName("loggingEnabled")
var loggingEnabled: Boolean = DEFAULT_LOGGING_ENABLED
var loggingEnabled: Boolean = DEFAULT_LOGGING_ENABLED,

/**
* The endpoint to use for logging events. This can be updated at runtime to support gradual
* cutovers between log ingestion endpoints.
*/
@SerializedName("eventLoggingAPI")
var eventLoggingAPI: String = DEFAULT_EVENT_API
)
27 changes: 27 additions & 0 deletions src/test/java/com/statsig/androidsdk/LogEventTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,33 @@ class LogEventTest {
}
}

@Test
fun testRuntimeMutableSettingsEventLoggingApi() = runBlocking {
val initialLogEventApi = "https://initial.fake.statsig.com/v1"
val updatedLogEventApi = "https://updated.fake.statsig.com/v1"
val options = StatsigOptions(eventLoggingAPI = initialLogEventApi)

setup(options)

Statsig.logEvent("event_before_api_update")
Statsig.flush()

Statsig.updateRuntimeOptions(
StatsigRuntimeMutableOptions(eventLoggingAPI = updatedLogEventApi)
)

Statsig.logEvent("event_after_api_update")
Statsig.flush()

coVerify(exactly = 1) {
network.apiPostLogs(initialLogEventApi, any(), any(), any(), any())
}
coVerify(exactly = 1) {
network.apiPostLogs(updatedLogEventApi, any(), any(), any(), any())
}
assertThat(options.eventLoggingAPI).isEqualTo(initialLogEventApi)
}

@Test
fun testOverrideLoggingApi() = runBlocking {
val apiPermutations = arrayOf(
Expand Down
Loading