Skip to content

Commit

Permalink
chore: use correct term "domain" instead of name/clientName in code (#…
Browse files Browse the repository at this point in the history
…305)

Signed-off-by: Bernd Warmuth <bernd.warmuth@dynatrace.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
  • Loading branch information
warber and toddbaert authored Nov 26, 2024
1 parent 96d86ba commit 73c0e85
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 43 deletions.
26 changes: 13 additions & 13 deletions openfeature/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ import (

// ClientMetadata provides a client's metadata
type ClientMetadata struct {
name string
domain string
}

// NewClientMetadata constructs ClientMetadata
// Allows for simplified hook test cases while maintaining immutability
func NewClientMetadata(name string) ClientMetadata {
func NewClientMetadata(domain string) ClientMetadata {
return ClientMetadata{
name: name,
domain: domain,
}
}

// Name returns the client's name
// Name returns the client's domain name
// Deprecated: Name() exists for historical compatibility, use Domain() instead.
func (cm ClientMetadata) Name() string {
return cm.name
return cm.domain
}

// Domain returns the client's domain
func (cm ClientMetadata) Domain() string {
return cm.name
return cm.domain
}

// Client implements the behaviour required of an openfeature client
Expand All @@ -51,16 +51,16 @@ var _ IClient = (*Client)(nil)

// NewClient returns a new Client. Name is a unique identifier for this client
// This helper exists for historical reasons. It is recommended to interact with IEvaluation to derive IClient instances.
func NewClient(name string) *Client {
return newClient(name, api, eventing)
func NewClient(domain string) *Client {
return newClient(domain, api, eventing)
}

func newClient(name string, apiRef evaluationImpl, eventRef clientEvent) *Client {
func newClient(domain string, apiRef evaluationImpl, eventRef clientEvent) *Client {
return &Client{
domain: name,
domain: domain,
api: apiRef,
clientEventing: eventRef,
metadata: ClientMetadata{name: name},
metadata: ClientMetadata{domain: domain},
hooks: []Hook{},
evaluationContext: EvaluationContext{},
}
Expand Down Expand Up @@ -668,7 +668,7 @@ func (c *Client) Track(ctx context.Context, trackingEventName string, evalCtx Ev
// - client
// - invocation (highest precedence)
func (c *Client) forTracking(ctx context.Context, evalCtx EvaluationContext) (Tracker, EvaluationContext) {
provider, _, apiCtx := c.api.ForEvaluation(c.metadata.name)
provider, _, apiCtx := c.api.ForEvaluation(c.metadata.domain)
evalCtx = mergeContexts(evalCtx, c.evaluationContext, TransactionContext(ctx), apiCtx)
trackingProvider, ok := provider.(Tracker)
if !ok {
Expand All @@ -693,7 +693,7 @@ func (c *Client) evaluate(
}

// ensure that the same provider & hooks are used across this transaction to avoid unexpected behaviour
provider, globalHooks, globalCtx := c.api.ForEvaluation(c.metadata.name)
provider, globalHooks, globalCtx := c.api.ForEvaluation(c.metadata.domain)

evalCtx = mergeContexts(evalCtx, c.evaluationContext, TransactionContext(ctx), globalCtx) // API (global) -> transaction -> client -> invocation
apiClientInvocationProviderHooks := append(append(append(globalHooks, c.hooks...), options.hooks...), provider.Hooks()...) // API, Client, Invocation, Provider
Expand Down
34 changes: 17 additions & 17 deletions openfeature/event_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,44 +126,44 @@ func (e *eventExecutor) RemoveHandler(t EventType, c EventCallback) {
}

// AddClientHandler registers a client level handler
func (e *eventExecutor) AddClientHandler(clientDomain string, t EventType, c EventCallback) {
func (e *eventExecutor) AddClientHandler(domain string, t EventType, c EventCallback) {
e.mu.Lock()
defer e.mu.Unlock()

_, ok := e.scopedRegistry[clientDomain]
_, ok := e.scopedRegistry[domain]
if !ok {
e.scopedRegistry[clientDomain] = newScopedCallback(clientDomain)
e.scopedRegistry[domain] = newScopedCallback(domain)
}

registry := e.scopedRegistry[clientDomain]
registry := e.scopedRegistry[domain]

if registry.callbacks[t] == nil {
registry.callbacks[t] = []EventCallback{c}
} else {
registry.callbacks[t] = append(registry.callbacks[t], c)
}

reference, ok := e.namedProviderReference[clientDomain]
reference, ok := e.namedProviderReference[domain]
if !ok {
// fallback to default
reference = e.defaultProviderReference
}

e.emitOnRegistration(clientDomain, reference, t, c)
e.emitOnRegistration(domain, reference, t, c)
}

// RemoveClientHandler removes a client level handler
func (e *eventExecutor) RemoveClientHandler(name string, t EventType, c EventCallback) {
func (e *eventExecutor) RemoveClientHandler(domain string, t EventType, c EventCallback) {
e.mu.Lock()
defer e.mu.Unlock()

_, ok := e.scopedRegistry[name]
_, ok := e.scopedRegistry[domain]
if !ok {
// nothing to remove
return
}

entrySlice := e.scopedRegistry[name].callbacks[t]
entrySlice := e.scopedRegistry[domain].callbacks[t]
if entrySlice == nil {
// nothing to remove
return
Expand All @@ -175,7 +175,7 @@ func (e *eventExecutor) RemoveClientHandler(name string, t EventType, c EventCal
}
}

e.scopedRegistry[name].callbacks[t] = entrySlice
e.scopedRegistry[domain].callbacks[t] = entrySlice
}

func (e *eventExecutor) GetAPIRegistry() map[EventType][]EventCallback {
Expand All @@ -188,8 +188,8 @@ func (e *eventExecutor) GetClientRegistry(client string) scopedCallback {

// emitOnRegistration fulfils the spec requirement to fire events if the
// event type and the state of the associated provider are compatible.
func (e *eventExecutor) emitOnRegistration(clientDomain string, providerReference providerReference, eventType EventType, callback EventCallback) {
state, ok := e.states.Load(clientDomain)
func (e *eventExecutor) emitOnRegistration(domain string, providerReference providerReference, eventType EventType, callback EventCallback) {
state, ok := e.states.Load(domain)
if !ok {
return
}
Expand Down Expand Up @@ -340,14 +340,14 @@ func (e *eventExecutor) triggerEvent(event Event, handler FeatureProvider) {
}

// then run client handlers
for name, reference := range e.namedProviderReference {
for domain, reference := range e.namedProviderReference {
if !reflect.DeepEqual(reference.featureProvider, handler) {
// unassociated client, continue to next
continue
}

e.states.Store(name, stateFromEvent(event))
for _, c := range e.scopedRegistry[name].callbacks[event.EventType] {
e.states.Store(domain, stateFromEvent(event))
for _, c := range e.scopedRegistry[domain].callbacks[event.EventType] {
e.executeHandler(*c, event)
}
}
Expand All @@ -359,8 +359,8 @@ func (e *eventExecutor) triggerEvent(event Event, handler FeatureProvider) {
// handling the default provider
e.states.Store(defaultClient, stateFromEvent(event))
// invoke default provider bound (no provider associated) handlers by filtering
for clientName, registry := range e.scopedRegistry {
if _, ok := e.namedProviderReference[clientName]; ok {
for domain, registry := range e.scopedRegistry {
if _, ok := e.namedProviderReference[domain]; ok {
// association exist, skip and check next
continue
}
Expand Down
8 changes: 4 additions & 4 deletions openfeature/openfeature.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func ProviderMetadata() Metadata {

// SetNamedProvider sets a provider mapped to the given Client domain. Provider initialization is asynchronous and
// status can be checked from provider status
func SetNamedProvider(clientDomain string, provider FeatureProvider) error {
return api.SetNamedProvider(clientDomain, provider, true)
func SetNamedProvider(domain string, provider FeatureProvider) error {
return api.SetNamedProvider(domain, provider, true)
}

// SetNamedProviderAndWait sets a provider mapped to the given Client domain and waits for its initialization.
// Returns an error if initialization cause error
func SetNamedProviderAndWait(clientDomain string, provider FeatureProvider) error {
return api.SetNamedProvider(clientDomain, provider, false)
func SetNamedProviderAndWait(domain string, provider FeatureProvider) error {
return api.SetNamedProvider(domain, provider, false)
}

// NamedProviderMetadata returns the named provider's Metadata
Expand Down
4 changes: 2 additions & 2 deletions openfeature/openfeature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,14 @@ func TestRequirement_1_1_6(t *testing.T) {
}
})

t.Run("client from api level - no name", func(t *testing.T) {
t.Run("client from api level - no domain", func(t *testing.T) {
client := api.GetClient()
if client == nil {
t.Errorf("expected an IClient instance, but got invalid")
}
})

t.Run("client from api level - with name", func(t *testing.T) {
t.Run("client from api level - with domain", func(t *testing.T) {
client := api.GetNamedClient("test-client")
if client == nil {
t.Errorf("expected an IClient instance, but got invalid")
Expand Down
10 changes: 5 additions & 5 deletions pkg/openfeature/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ type ClientMetadata = openfeature.ClientMetadata
//
// Deprecated: use
// github.com/open-feature/go-sdk/openfeature.NewClientMetadata, instead.
func NewClientMetadata(name string) ClientMetadata {
return openfeature.NewClientMetadata(name)
func NewClientMetadata(domain string) ClientMetadata {
return openfeature.NewClientMetadata(domain)
}

// Client implements the behaviour required of an openfeature client
//
// Deprecated: use github.com/open-feature/go-sdk/openfeature.Client, instead.
type Client = openfeature.Client

// NewClient returns a new Client. Name is a unique identifier for this client
// NewClient returns a new Client. Domain is a unique identifier for this client
//
// Deprecated: use github.com/open-feature/go-sdk/openfeature.NewClient,
// instead.
func NewClient(name string) *Client {
return openfeature.NewClient(name)
func NewClient(domain string) *Client {
return openfeature.NewClient(domain)
}

// Type represents the type of a flag
Expand Down
4 changes: 2 additions & 2 deletions pkg/openfeature/openfeature.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func SetProvider(provider FeatureProvider) error {
//
// Deprecated: use github.com/open-feature/go-sdk/openfeature.SetNamedProvider,
// instead.
func SetNamedProvider(clientName string, provider FeatureProvider) error {
return openfeature.SetNamedProvider(clientName, provider)
func SetNamedProvider(domain string, provider FeatureProvider) error {
return openfeature.SetNamedProvider(domain, provider)
}

// SetEvaluationContext sets the global evaluation context.
Expand Down

0 comments on commit 73c0e85

Please sign in to comment.