From a811ad9c4c2ed73a08d7ce280a90f7ceedec7b0b Mon Sep 17 00:00:00 2001 From: Miranda Wilson Date: Thu, 30 May 2024 17:31:40 +0100 Subject: [PATCH] Set serverAnonymisation more quickly (close #689) * Make OkHttpNetworkConnection serverAnon property public * Remove outdated docstring * Fix assignment * Update java version and runner in build action --- .github/workflows/build.yml | 15 ++++++++------- .../snowplowdemocompose/data/Tracking.kt | 2 +- .../snowplowanalytics/core/emitter/Emitter.kt | 19 +++---------------- .../network/OkHttpNetworkConnection.kt | 2 +- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2e95b48ae..505ffcd9e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: [push] jobs: test: - runs-on: macos-latest + runs-on: ubuntu-latest strategy: fail-fast: false @@ -17,11 +17,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '11' + + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 @@ -30,7 +31,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: "temurin" - java-version: "11" + java-version: "17" - name: Run Tests uses: reactivecircus/android-emulator-runner@v2 diff --git a/snowplow-demo-compose/src/main/java/com/snowplowanalytics/snowplowdemocompose/data/Tracking.kt b/snowplow-demo-compose/src/main/java/com/snowplowanalytics/snowplowdemocompose/data/Tracking.kt index da8dd4b1e..5826dc451 100644 --- a/snowplow-demo-compose/src/main/java/com/snowplowanalytics/snowplowdemocompose/data/Tracking.kt +++ b/snowplow-demo-compose/src/main/java/com/snowplowanalytics/snowplowdemocompose/data/Tracking.kt @@ -20,7 +20,7 @@ object Tracking { @Composable fun setup(namespace: String) : TrackerController { // Replace this collector endpoint with your own - val networkConfig = NetworkConfiguration("https://23a6-82-26-43-253.ngrok.io", HttpMethod.POST) + val networkConfig = NetworkConfiguration("http://192.168.0.20:9090", HttpMethod.POST) val trackerConfig = TrackerConfiguration("appID") .logLevel(LogLevel.DEBUG) .screenViewAutotracking(false) diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/emitter/Emitter.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/emitter/Emitter.kt index 220acef7a..985a637a8 100755 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/emitter/Emitter.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/emitter/Emitter.kt @@ -197,9 +197,7 @@ class Emitter( var bufferOption: BufferOption = EmitterDefaults.bufferOption /** * Whether the buffer should send events instantly or after the buffer has reached - * its limit. By default, this is set to BufferOption Default. - * - * @param option Set the BufferOption enum to Instant to send events upon creation. + * its limit. */ set(option) { if (!isRunning.get()) { @@ -303,19 +301,8 @@ class Emitter( */ set(serverAnonymisation) { field = serverAnonymisation - if (!isCustomNetworkConnection && builderFinished) { - networkConnection = emitTimeout?.let { - OkHttpNetworkConnectionBuilder(uri, context) - .method(httpMethod) - .tls(tlsVersions) - .emitTimeout(it) - .customPostPath(customPostPath) - .client(client) - .cookieJar(cookieJar) - .serverAnonymisation(serverAnonymisation) - .requestHeaders(requestHeaders) - .build() - } + if (!isCustomNetworkConnection && builderFinished && networkConnection is OkHttpNetworkConnection) { + (networkConnection as OkHttpNetworkConnection).serverAnonymisation = serverAnonymisation } } diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/network/OkHttpNetworkConnection.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/network/OkHttpNetworkConnection.kt index 4b5631300..4092cc254 100644 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/network/OkHttpNetworkConnection.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/network/OkHttpNetworkConnection.kt @@ -48,7 +48,7 @@ class OkHttpNetworkConnection private constructor(builder: OkHttpNetworkConnecti override val httpMethod: HttpMethod private val emitTimeout: Int private val customPostPath: String? - private val serverAnonymisation: Boolean + var serverAnonymisation: Boolean private val requestHeaders: Map? private var client: OkHttpClient? = null private val uriBuilder: Uri.Builder