Repository: open-feature/go-sdk
Pull request #248 (2024-01-30 23:16:50)

chore: improve eventing
## This PR

Contains minor improvements on the eventing of the SDK

- Expose the provider name from `EventDetails`
- Add buffer to internal channel handler to improve concurrency: Buffer should theoretically allow us to handle events in order of they are received 

github-actions[bot]: Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.

Details:

```
Unknown release type "Chore" found in pull request title "Chore: improve eventing". 

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit
```
<!-- Sticky Pull Request Commentpr-title-lint-error -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/open-feature/go-sdk/pull/248?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`95f592a`)](https://app.codecov.io/gh/open-feature/go-sdk/commit/95f592a50ff669b32a071625029b0566c750c534?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature) 81.61% compared to head [(`677ce4a`)](https://app.codecov.io/gh/open-feature/go-sdk/pull/248?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature) 81.61%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #248   +/-   ##
=======================================
  Coverage   81.61%   81.61%           
=======================================
  Files          10       10           
  Lines        1142     1142           
=======================================
  Hits          932      932           
  Misses        192      192           
  Partials       18       18           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/open-feature/go-sdk/pull/248?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-feature).


Patch:
diff --git a/openfeature/event_executor.go b/openfeature/event_executor.go
index c91f407..8644e43 100644
--- a/openfeature/event_executor.go
+++ b/openfeature/event_executor.go
@@ -35,7 +35,7 @@ func newEventExecutor(logger logr.Logger) *eventExecutor {
 		apiRegistry:            map[EventType][]EventCallback{},
 		scopedRegistry:         map[string]scopedCallback{},
 		logger:                 logger,
-		eventChan:              make(chan eventPayload, 1),
+		eventChan:              make(chan eventPayload, 5),
 	}
 
 	executor.startEventListener()
@@ -189,7 +189,7 @@ func (e *eventExecutor) emitOnRegistration(
 
 	if message != "" {
 		(*callback)(EventDetails{
-			providerName: providerReference.featureProvider.Metadata().Name,
+			ProviderName: providerReference.featureProvider.Metadata().Name,
 			ProviderEventDetails: ProviderEventDetails{
 				Message: message,
 			},
@@ -355,7 +355,7 @@ func (e *eventExecutor) executeHandler(f func(details EventDetails), event Event
 		}()
 
 		f(EventDetails{
-			providerName: event.ProviderName,
+			ProviderName: event.ProviderName,
 			ProviderEventDetails: ProviderEventDetails{
 				Message:       event.Message,
 				FlagChanges:   event.FlagChanges,
diff --git a/openfeature/provider.go b/openfeature/provider.go
index 135ba85..634b23b 100644
--- a/openfeature/provider.go
+++ b/openfeature/provider.go
@@ -109,7 +109,7 @@ type Event struct {
 }
 
 type EventDetails struct {
-	providerName string
+	ProviderName string
 	ProviderEventDetails
 }
 


Test patch:
diff --git a/openfeature/event_executor_test.go b/openfeature/event_executor_test.go
index d787e4d..ed41e3a 100644
--- a/openfeature/event_executor_test.go
+++ b/openfeature/event_executor_test.go
@@ -177,8 +177,8 @@ func TestEventHandler_Eventing(t *testing.T) {
 			t.Fatalf("timeout - event did not trigger")
 		}
 
-		if result.providerName != eventingProvider.Metadata().Name {
-			t.Errorf("expected %s, but got %s", eventingProvider.Metadata().Name, result.providerName)
+		if result.ProviderName != eventingProvider.Metadata().Name {
+			t.Errorf("expected %s, but got %s", eventingProvider.Metadata().Name, result.ProviderName)
 		}
 
 		if result.Message != "ReadyMessage" {
@@ -1120,29 +1120,29 @@ func TestEventHandler_multiSubs(t *testing.T) {
 	globalEvents := make(chan string, 10)
 	go func() {
 		for rsp := range rspGlobal {
-			globalEvents <- rsp.providerName
+			globalEvents <- rsp.ProviderName
 		}
 	}()
 
 	clientAEvents := make(chan string, 10)
 	go func() {
 		for rsp := range rspClientA {
-			if rsp.providerName != "providerOther" {
-				t.Errorf("incorrect event provider association, expected %s, got %s", "providerOther", rsp.providerName)
+			if rsp.ProviderName != "providerOther" {
+				t.Errorf("incorrect event provider association, expected %s, got %s", "providerOther", rsp.ProviderName)
 			}
 
-			clientAEvents <- rsp.providerName
+			clientAEvents <- rsp.ProviderName
 		}
 	}()
 
 	clientBEvents := make(chan string, 10)
 	go func() {
 		for rsp := range rspClientB {
-			if rsp.providerName != "providerOther" {
-				t.Errorf("incorrect event provider association, expected %s, got %s", "providerOther", rsp.providerName)
+			if rsp.ProviderName != "providerOther" {
+				t.Errorf("incorrect event provider association, expected %s, got %s", "providerOther", rsp.ProviderName)
 			}
 
-			clientBEvents <- rsp.providerName
+			clientBEvents <- rsp.ProviderName
 		}
 	}()