Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config service hardening #1641

Merged
merged 56 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
23c481d
refactor: remove config listeners
fractalwrench Nov 6, 2024
42193e6
refactor: avoid shared prefs for config
fractalwrench Nov 6, 2024
5b36683
refactor: extract config loading
fractalwrench Nov 6, 2024
0717c5e
refactor: create interface for instrumented config
fractalwrench Nov 7, 2024
d50e433
Merge pull request #1635 from embrace-io/remove-config-listeners
fractalwrench Nov 7, 2024
925a2aa
Merge pull request #1636 from embrace-io/avoid-config-prefs
fractalwrench Nov 7, 2024
5ce509f
Merge pull request #1637 from embrace-io/extract-config-load
fractalwrench Nov 7, 2024
089454f
Merge pull request #1638 from embrace-io/config-swazzling
fractalwrench Nov 7, 2024
fc50030
test: alter integration tests to use config service
fractalwrench Nov 7, 2024
57d0027
Merge pull request #1640 from embrace-io/config-integration-tests
fractalwrench Nov 7, 2024
5b409a1
refactor: move remote config tests
fractalwrench Nov 7, 2024
1331638
Merge pull request #1642 from embrace-io/move-remote-config-tests
fractalwrench Nov 8, 2024
2adedb1
test: add assertions for checking config request made
fractalwrench Nov 8, 2024
5b172a7
disable inline
fractalwrench Nov 8, 2024
dc9ea74
Merge pull request #1647 from embrace-io/config-tests
fractalwrench Nov 8, 2024
18bae2c
Merge pull request #1650 from embrace-io/disable-inline
fractalwrench Nov 8, 2024
7b05876
wip: okhttp implementation
fractalwrench Nov 8, 2024
8a9f3f6
refactor: reorganise initial bootstrapping
fractalwrench Nov 11, 2024
aebe158
refactor: extract url construction
fractalwrench Nov 11, 2024
20c02c9
fix okhttp implementation
fractalwrench Nov 12, 2024
2e639ef
refactor: implement store for remote config
fractalwrench Nov 12, 2024
544b0c6
refactor: create combined source of remote config
fractalwrench Nov 12, 2024
64b193d
refactor: add etag support to okhttp
fractalwrench Nov 12, 2024
dddb137
refactor: alter config implementation to use okhttp
fractalwrench Nov 12, 2024
0aaaa0c
poc: disable sdk earlier in lifecycle
fractalwrench Nov 12, 2024
82a73da
wip: okhttp implementation
fractalwrench Nov 8, 2024
50a5f42
Merge pull request #1651 from embrace-io/okhttp-implementation
fractalwrench Nov 13, 2024
3e90b67
Merge branch 'main' into integration/config-hardening
fractalwrench Nov 13, 2024
bc28460
refactor: reorganise initial bootstrapping
fractalwrench Nov 11, 2024
f546bb6
Merge pull request #1655 from embrace-io/alter-bootstrapping
fractalwrench Nov 13, 2024
c737405
refactor: extract url construction
fractalwrench Nov 11, 2024
4e4263f
Merge pull request #1656 from embrace-io/refactor-url-construction
fractalwrench Nov 13, 2024
14192c7
Merge pull request #1666 from embrace-io/config-disable-sdk
fractalwrench Nov 13, 2024
660dde9
Merge pull request #1663 from embrace-io/okhttp-etag-support
fractalwrench Nov 13, 2024
4ff3995
Merge pull request #1665 from embrace-io/use-okhttp-for-config
fractalwrench Nov 13, 2024
016bcd4
Merge branch 'integration/config-hardening' into fix-okhttp-implement…
fractalwrench Nov 13, 2024
e2923bd
Merge pull request #1660 from embrace-io/fix-okhttp-implementation
fractalwrench Nov 13, 2024
da1c1ab
Merge pull request #1661 from embrace-io/cache-implementation
fractalwrench Nov 13, 2024
2c53e38
Merge pull request #1662 from embrace-io/combined-source
fractalwrench Nov 13, 2024
d5f637a
fix build
fractalwrench Nov 13, 2024
50e5a39
test: add integration tests for config disabling sdk
fractalwrench Nov 13, 2024
a81794f
refactor: store payload uncompressed
fractalwrench Nov 13, 2024
4bb7b8a
perf: systrace improvements
fractalwrench Nov 13, 2024
e37af7b
Merge pull request #1669 from embrace-io/config-disable-tests
fractalwrench Nov 14, 2024
4282882
Merge pull request #1670 from embrace-io/payload-uncompressed
fractalwrench Nov 14, 2024
3cc9f0b
Merge pull request #1672 from embrace-io/systrace-improvement
fractalwrench Nov 14, 2024
0cf009e
Merge branch 'main' into integration/config-hardening
fractalwrench Nov 14, 2024
4bac7e0
refactor: purge config
fractalwrench Nov 13, 2024
35e8b52
simplify config behavior implementation
fractalwrench Nov 14, 2024
5cc2407
perf: load okhttp async
fractalwrench Nov 14, 2024
bff72ec
fix endpoint used for sdk
fractalwrench Nov 14, 2024
6f2ad41
Merge pull request #1678 from embrace-io/fix-endpoint
fractalwrench Nov 14, 2024
1311fea
Merge pull request #1677 from embrace-io/config-perf-optimization
fractalwrench Nov 14, 2024
ae90a8a
Merge pull request #1676 from embrace-io/simplify-behavior-remote-cfg
fractalwrench Nov 14, 2024
677a7ea
Merge pull request #1671 from embrace-io/config-purge
fractalwrench Nov 14, 2024
59ccf25
Merge branch 'main' into integration/config-hardening
fractalwrench Nov 18, 2024
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
1 change: 1 addition & 0 deletions embrace-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
compileOnly(libs.opentelemetry.semconv.incubating)
implementation(libs.lifecycle.runtime)
implementation(libs.lifecycle.process)
implementation(libs.okhttp)

testImplementation(platform(libs.opentelemetry.bom))
testImplementation(libs.opentelemetry.api)
Expand Down
2 changes: 1 addition & 1 deletion embrace-android-core/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>LongParameterList:DeliveryModuleSupplier.kt$( configModule: ConfigModule, initModule: InitModule, otelModule: OpenTelemetryModule, workerThreadModule: WorkerThreadModule, coreModule: CoreModule, storageModule: StorageModule, essentialServiceModule: EssentialServiceModule, payloadStorageServiceProvider: Provider&lt;PayloadStorageService?&gt;, cacheStorageServiceProvider: Provider&lt;PayloadStorageService?&gt;, requestExecutionServiceProvider: Provider&lt;RequestExecutionService?&gt;, deliveryServiceProvider: Provider&lt;DeliveryService?&gt;, )</ID>
<ID>LongParameterList:DeliveryModuleSupplier.kt$( configModule: ConfigModule, initModule: InitModule, otelModule: OpenTelemetryModule, workerThreadModule: WorkerThreadModule, coreModule: CoreModule, storageModule: StorageModule, essentialServiceModule: EssentialServiceModule, androidServicesModule: AndroidServicesModule, payloadStorageServiceProvider: Provider&lt;PayloadStorageService&gt;?, cacheStorageServiceProvider: Provider&lt;PayloadStorageService&gt;?, requestExecutionServiceProvider: Provider&lt;RequestExecutionService&gt;?, deliveryServiceProvider: Provider&lt;DeliveryService&gt;?, )</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.embrace.android.embracesdk.internal.arch

import io.embrace.android.embracesdk.internal.arch.datasource.DataSourceState
import io.embrace.android.embracesdk.internal.config.ConfigService
import io.embrace.android.embracesdk.internal.logging.EmbLogger
import io.embrace.android.embracesdk.internal.logging.InternalErrorType
import io.embrace.android.embracesdk.internal.worker.BackgroundWorker
Expand All @@ -12,17 +11,10 @@ import java.util.concurrent.CopyOnWriteArrayList
* place to coordinate everything in one place.
*/
class DataCaptureOrchestrator(
configService: ConfigService,
private val worker: BackgroundWorker,
private val logger: EmbLogger,
) : EmbraceFeatureRegistry {

init {
configService.addListener {
onConfigChange()
}
}

private val dataSourceStates = CopyOnWriteArrayList<DataSourceState<*>>()

var currentSessionType: SessionType? = null
Expand All @@ -38,18 +30,6 @@ class DataCaptureOrchestrator(
}
}

private fun onConfigChange() {
dataSourceStates.forEach { state ->
try {
state.dispatchStateChange {
state.onConfigChange()
}
} catch (exc: Throwable) {
logger.trackInternalError(InternalErrorType.CFG_CHANGE_DATA_CAPTURE_FAIL, exc)
}
}
}

/**
* Callback that is invoked when the session type changes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ class DataSourceState<T : DataSource<*>>(
}
}

/**
* Callback that is invoked when the config layer experiences a change.
*/
fun onConfigChange() {
updateDataSource()
}

private fun updateDataSource() {
val enabled =
currentSessionType != null && currentSessionType != disabledSessionType && configGate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,49 @@

import android.content.res.Resources
import io.embrace.android.embracesdk.internal.AndroidResourcesService
import io.embrace.android.embracesdk.internal.config.instrumented.ProjectConfig
import io.embrace.android.embracesdk.internal.config.instrumented.schema.InstrumentedConfig

internal class BuildInfoServiceImpl(
resources: AndroidResourcesService,
packageName: String,
private val instrumentedConfig: InstrumentedConfig,
private val resources: AndroidResourcesService,
private val packageName: String,
) : BuildInfoService {

companion object {
private const val BUILD_INFO_RN_BUNDLE_ID: String = "emb_rn_bundle_id"
private const val RES_TYPE_STRING = "string"
}

private val info by lazy {
fromResources(resources, packageName)
BuildInfo(
instrumentedConfig.project.getBuildId(),
instrumentedConfig.project.getBuildType(),
instrumentedConfig.project.getBuildFlavor(),
getBuildResource(resources, packageName, BUILD_INFO_RN_BUNDLE_ID),
)
}

override fun getBuildInfo(): BuildInfo = info

companion object {
private const val BUILD_INFO_RN_BUNDLE_ID: String = "emb_rn_bundle_id"
private const val RES_TYPE_STRING = "string"

/**
* Loads the build information from resources provided by the config file packaged within the application by Gradle at
* build-time.
*
* @return the build information
*/
@JvmStatic
fun fromResources(resources: AndroidResourcesService, packageName: String): BuildInfo {
val buildInfo = BuildInfo(
ProjectConfig.getBuildId(),
ProjectConfig.getBuildType(),
ProjectConfig.getBuildFlavor(),
getBuildResource(resources, packageName, BUILD_INFO_RN_BUNDLE_ID),
/**
* Given a build property name and a build property type, retrieves the embrace build resource value.
*/
fun getBuildResource(
resources: AndroidResourcesService,
packageName: String,
buildProperty: String,
): String? {
return try {
val resourceId =
resources.getIdentifier(buildProperty, RES_TYPE_STRING, packageName)
resources.getString(resourceId)
} catch (ex: NullPointerException) {
throw IllegalArgumentException(
"No resource found for $buildProperty property. Failed to create build info.",
ex

Check warning on line 44 in embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/buildinfo/BuildInfoServiceImpl.kt

View check run for this annotation

Codecov / codecov/patch

embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/buildinfo/BuildInfoServiceImpl.kt#L42-L44

Added lines #L42 - L44 were not covered by tests
)
return buildInfo
}

/**
* Given a build property name and a build property type, retrieves the embrace build resource value.
*/
fun getBuildResource(
resources: AndroidResourcesService,
packageName: String,
buildProperty: String,
): String? {
return try {
val resourceId =
resources.getIdentifier(buildProperty, RES_TYPE_STRING, packageName)
resources.getString(resourceId)
} catch (ex: NullPointerException) {
throw IllegalArgumentException(
"No resource found for $buildProperty property. Failed to create build info.",
ex
)
} catch (ex: Resources.NotFoundException) {
null
}
} catch (ex: Resources.NotFoundException) {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class ApiRequestMapper(
) {

private val apiUrlBuilders = Endpoint.values().associateWith {
urlBuilder.getEmbraceUrlWithSuffix(it.version, it.path)
urlBuilder.resolveUrl(it)
}

private fun Endpoint.asEmbraceUrl(): String = checkNotNull(apiUrlBuilders[this])
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.embrace.android.embracesdk.internal.comms.api

import io.embrace.android.embracesdk.internal.capture.connectivity.NetworkConnectivityListener
import io.embrace.android.embracesdk.internal.config.RemoteConfigSource
import io.embrace.android.embracesdk.internal.injection.SerializationAction
import io.embrace.android.embracesdk.internal.payload.Envelope
import io.embrace.android.embracesdk.internal.payload.LogPayload
import java.util.concurrent.Future

interface ApiService : RemoteConfigSource, NetworkConnectivityListener {
interface ApiService : NetworkConnectivityListener {

/**
* Sends a list of OTel Logs to the API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ package io.embrace.android.embracesdk.internal.comms.api
interface ApiUrlBuilder {

/**
* Returns the url used to fetch the config.
* The App ID that will be used in API requests.
*/
fun getConfigUrl(): String
val appId: String

/**
* The Device ID that will be used in API requests.
*/
val deviceId: String

/**
* Base URL for the data endpoint
*/
val baseDataUrl: String

/**
* Returns the url used to send data to Embrace.
*/
fun getEmbraceUrlWithSuffix(apiVersion: String, suffix: String): String
fun resolveUrl(endpoint: Endpoint): String
}
Loading