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

Add events of the OpenFeature into the provider #45

Merged
merged 5 commits into from
Jul 27, 2023

Conversation

vahidlazio
Copy link
Contributor

  • Add events of the OpenFeature into the provider
  • Update non suspending provider

Copy link
Member

@fabriziodemaria fabriziodemaria left a comment

Choose a reason for hiding this comment

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

.

Copy link
Member

@fabriziodemaria fabriziodemaria left a comment

Choose a reason for hiding this comment

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

Mostly questions and side-observations. Looks good

coroutineScope.cancel()
}

override fun onContextSet(
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should emit "ProviderStale" if newContext != oldContext, and until the flags for the newContext are fetched. But this is something we can think about in a future PR.

@@ -163,7 +183,7 @@ class ConfidenceFeatureProvider private constructor(
private class ConfidenceMetadata(override var name: String? = "confidence") : ProviderMetadata

@Suppress("LongParameterList")
suspend fun create(
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to have a "create" method not suspend 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the problem with this however is that the cache is reading from file in the caller thread now. we should probably make the read from file in the cache explicit. we can discuss this offline.

Comment on lines +51 to +52
// network failed, provider is ready but with default/cache values
eventsPublisher.publish(OpenFeatureEvents.ProviderReady)
Copy link
Member

@fabriziodemaria fabriziodemaria Jul 27, 2023

Choose a reason for hiding this comment

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

I believe in some cases we will want to emit ProviderError here. I think we can merge this as it is for now, but we should perhaps take another look the overall OpenFeature design of Events and make sure they are useful for users to really understand what is happening in the Provider at any time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this depends on the strategy of the provider. maybe we are fine with the network to fail. if user doesn't have internet they should still be able to use a working provider with flags from the cache. and provider is ready.

@@ -43,10 +41,10 @@ class StorageFileCache private constructor(context: Context) : InMemoryCache() {
}

companion object {
suspend fun create(context: Context): StorageFileCache = suspendCoroutine {
Copy link
Member

Choose a reason for hiding this comment

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

Curious about removing suspend here: reading file could be a slow operation, do we really want to make create blocking on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

explained in another comment. we can and i believe we should explicitly call read from file in the provider initialization on a background thread instead of doing it in the init of the cache.

mapOf(
"country" to Value.String("SE")
)
EventHandler.eventsPublisher().publish(OpenFeatureEvents.ProviderShutDown)
Copy link
Member

Choose a reason for hiding this comment

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

What's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests are running on the same machine, if they run together and one after another, the next one will fail because provider was already ready in the previous test. we need to clean up the events for the new test case.

@@ -10,7 +10,10 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import dev.openfeature.contrib.providers.ConfidenceFeatureProvider
import dev.openfeature.sdk.*
import dev.openfeature.sdk.async.awaitProviderReady
Copy link
Member

Choose a reason for hiding this comment

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

I am sill concerned about exposing this non-spec-standard API from the base SDK: we should use the Events API directly or try add this API in the OpenFeature Sepc. But this comment is not related to this PR under review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this makes the life of provider devs much easier. but we can always remove it.

@vahidlazio vahidlazio merged commit c62ae6e into main Jul 27, 2023
1 check passed
@vahidlazio vahidlazio deleted the update-openfeature-events branch July 27, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants