Skip to content

Commit

Permalink
NOISSUE - Add Tracing To Bootstrap Service (absmach#1849)
Browse files Browse the repository at this point in the history
* Initial Commit: Remove JaegerURL from grpc Client Config

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Initial Commit: Add Tracing To Bootstrap Service

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

---------

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
  • Loading branch information
rodneyosodo authored and WashingtonKK committed Jul 12, 2023
1 parent f3a2eb3 commit d88876f
Show file tree
Hide file tree
Showing 33 changed files with 381 additions and 196 deletions.
29 changes: 15 additions & 14 deletions bootstrap/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package bootstrap

import (
"context"
"time"

"github.com/mainflux/mainflux/pkg/clients"
Expand Down Expand Up @@ -62,54 +63,54 @@ type ConfigsPage struct {
type ConfigRepository interface {
// Save persists the Config. Successful operation is indicated by non-nil
// error response.
Save(cfg Config, chsConnIDs []string) (string, error)
Save(ctx context.Context, cfg Config, chsConnIDs []string) (string, error)

// RetrieveByID retrieves the Config having the provided identifier, that is owned
// by the specified user.
RetrieveByID(owner, id string) (Config, error)
RetrieveByID(ctx context.Context, owner, id string) (Config, error)

// RetrieveAll retrieves a subset of Configs that are owned
// by the specific user, with given filter parameters.
RetrieveAll(owner string, filter Filter, offset, limit uint64) ConfigsPage
RetrieveAll(ctx context.Context, owner string, filter Filter, offset, limit uint64) ConfigsPage

// RetrieveByExternalID returns Config for given external ID.
RetrieveByExternalID(externalID string) (Config, error)
RetrieveByExternalID(ctx context.Context, externalID string) (Config, error)

// Update updates an existing Config. A non-nil error is returned
// to indicate operation failure.
Update(cfg Config) error
Update(ctx context.Context, cfg Config) error

// UpdateCerts updates an existing Config certificate and owner.
// A non-nil error is returned to indicate operation failure.
UpdateCert(owner, thingID, clientCert, clientKey, caCert string) error
UpdateCert(ctx context.Context, owner, thingID, clientCert, clientKey, caCert string) error

// UpdateConnections updates a list of Channels the Config is connected to
// adding new Channels if needed.
UpdateConnections(owner, id string, channels []Channel, connections []string) error
UpdateConnections(ctx context.Context, owner, id string, channels []Channel, connections []string) error

// Remove removes the Config having the provided identifier, that is owned
// by the specified user.
Remove(owner, id string) error
Remove(ctx context.Context, owner, id string) error

// ChangeState changes of the Config, that is owned by the specific user.
ChangeState(owner, id string, state State) error
ChangeState(ctx context.Context, owner, id string, state State) error

// ListExisting retrieves those channels from the given list that exist in DB.
ListExisting(owner string, ids []string) ([]Channel, error)
ListExisting(ctx context.Context, owner string, ids []string) ([]Channel, error)

// Methods RemoveThing, UpdateChannel, and RemoveChannel are related to
// event sourcing. That's why these methods surpass ownership check.

// RemoveThing removes Config of the Thing with the given ID.
RemoveThing(id string) error
RemoveThing(ctx context.Context, id string) error

// UpdateChannel updates channel with the given ID.
UpdateChannel(c Channel) error
UpdateChannel(ctx context.Context, c Channel) error

// RemoveChannel removes channel with the given ID.
RemoveChannel(id string) error
RemoveChannel(ctx context.Context, id string) error

// DisconnectHandler changes state of the Config when the corresponding Thing is
// disconnected from the Channel.
DisconnectThing(channelID, thingID string) error
DisconnectThing(ctx context.Context, channelID, thingID string) error
}
29 changes: 15 additions & 14 deletions bootstrap/mocks/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package mocks

import (
"context"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -32,7 +33,7 @@ func NewConfigsRepository() bootstrap.ConfigRepository {
}
}

func (crm *configRepositoryMock) Save(config bootstrap.Config, connections []string) (string, error) {
func (crm *configRepositoryMock) Save(_ context.Context, config bootstrap.Config, connections []string) (string, error) {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand Down Expand Up @@ -61,7 +62,7 @@ func (crm *configRepositoryMock) Save(config bootstrap.Config, connections []str
return config.MFThing, nil
}

func (crm *configRepositoryMock) RetrieveByID(token, id string) (bootstrap.Config, error) {
func (crm *configRepositoryMock) RetrieveByID(_ context.Context, token, id string) (bootstrap.Config, error) {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -77,7 +78,7 @@ func (crm *configRepositoryMock) RetrieveByID(token, id string) (bootstrap.Confi

}

func (crm *configRepositoryMock) RetrieveAll(token string, filter bootstrap.Filter, offset, limit uint64) bootstrap.ConfigsPage {
func (crm *configRepositoryMock) RetrieveAll(_ context.Context, token string, filter bootstrap.Filter, offset, limit uint64) bootstrap.ConfigsPage {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand Down Expand Up @@ -121,7 +122,7 @@ func (crm *configRepositoryMock) RetrieveAll(token string, filter bootstrap.Filt
}
}

func (crm *configRepositoryMock) RetrieveByExternalID(externalID string) (bootstrap.Config, error) {
func (crm *configRepositoryMock) RetrieveByExternalID(_ context.Context, externalID string) (bootstrap.Config, error) {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -134,7 +135,7 @@ func (crm *configRepositoryMock) RetrieveByExternalID(externalID string) (bootst
return bootstrap.Config{}, errors.ErrNotFound
}

func (crm *configRepositoryMock) Update(config bootstrap.Config) error {
func (crm *configRepositoryMock) Update(_ context.Context, config bootstrap.Config) error {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -150,7 +151,7 @@ func (crm *configRepositoryMock) Update(config bootstrap.Config) error {
return nil
}

func (crm *configRepositoryMock) UpdateCert(owner, thingID, clientCert, clientKey, caCert string) error {
func (crm *configRepositoryMock) UpdateCert(_ context.Context, owner, thingID, clientCert, clientKey, caCert string) error {
crm.mu.Lock()
defer crm.mu.Unlock()
var forUpdate bootstrap.Config
Expand All @@ -171,7 +172,7 @@ func (crm *configRepositoryMock) UpdateCert(owner, thingID, clientCert, clientKe
return nil
}

func (crm *configRepositoryMock) UpdateConnections(token, id string, channels []bootstrap.Channel, connections []string) error {
func (crm *configRepositoryMock) UpdateConnections(_ context.Context, token, id string, channels []bootstrap.Channel, connections []string) error {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -197,7 +198,7 @@ func (crm *configRepositoryMock) UpdateConnections(token, id string, channels []
return nil
}

func (crm *configRepositoryMock) Remove(token, id string) error {
func (crm *configRepositoryMock) Remove(_ context.Context, token, id string) error {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -211,7 +212,7 @@ func (crm *configRepositoryMock) Remove(token, id string) error {
return nil
}

func (crm *configRepositoryMock) ChangeState(token, id string, state bootstrap.State) error {
func (crm *configRepositoryMock) ChangeState(_ context.Context, token, id string, state bootstrap.State) error {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -228,7 +229,7 @@ func (crm *configRepositoryMock) ChangeState(token, id string, state bootstrap.S
return nil
}

func (crm *configRepositoryMock) ListExisting(token string, connections []string) ([]bootstrap.Channel, error) {
func (crm *configRepositoryMock) ListExisting(_ context.Context, token string, connections []string) ([]bootstrap.Channel, error) {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -246,15 +247,15 @@ func (crm *configRepositoryMock) ListExisting(token string, connections []string
return ret, nil
}

func (crm *configRepositoryMock) RemoveThing(id string) error {
func (crm *configRepositoryMock) RemoveThing(_ context.Context, id string) error {
crm.mu.Lock()
defer crm.mu.Unlock()

delete(crm.configs, id)
return nil
}

func (crm *configRepositoryMock) UpdateChannel(ch bootstrap.Channel) error {
func (crm *configRepositoryMock) UpdateChannel(_ context.Context, ch bootstrap.Channel) error {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand All @@ -269,15 +270,15 @@ func (crm *configRepositoryMock) UpdateChannel(ch bootstrap.Channel) error {
return nil
}

func (crm *configRepositoryMock) RemoveChannel(id string) error {
func (crm *configRepositoryMock) RemoveChannel(_ context.Context, id string) error {
crm.mu.Lock()
defer crm.mu.Unlock()

delete(crm.channels, id)
return nil
}

func (crm *configRepositoryMock) DisconnectThing(channelID, thingID string) error {
func (crm *configRepositoryMock) DisconnectThing(_ context.Context, channelID, thingID string) error {
crm.mu.Lock()
defer crm.mu.Unlock()

Expand Down
Loading

0 comments on commit d88876f

Please sign in to comment.