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

MF-399 - Add open tracing support #782

Merged
merged 14 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ MF_UI_PORT=3000
## Grafana
MF_GRAFANA_PORT=3000

## Jaeger
MF_JAEGER_PORT=6831
MF_JAEGER_FRONTEND=16686
MF_JAEGER_COLLECTOR=14268
MF_JAEGER_CONFIGS=5778
MF_JAEGER_URL=jaeger:6831

## Core Services
### Users
MF_USERS_LOG_LEVEL=debug
Expand Down
58 changes: 56 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
name = "github.com/gofrs/uuid"
version = "~v3.2.0"

[[constraint]]
name = "github.com/opentracing/opentracing-go"
version = "~v1.1.0"

[prune]
go-tests = true
unused-packages = true
6 changes: 5 additions & 1 deletion bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ The service is configured using the environment variables presented in the follo
| MF_BOOTSTRAP_ES_PASS | Bootstrap service event source password | |
| MF_BOOTSTRAP_ES_DB | Bootstrap service event source database | 0 |
| MF_BOOTSTRAP_INSTANCE_NAME | Bootstrap service instance name | bootstrap |
| MF_JAEGER_URL | Jaeger server URL | localhost:6831 |
| MF_BOOTSTRAP_THINGS_TIMEOUT | Things gRPC request timeout in seconds | 1 |

## Deployment

Expand Down Expand Up @@ -105,6 +107,8 @@ version: "2"
MF_BOOTSTRAP_ES_PASS: [Bootstrap service event source password]
MF_BOOTSTRAP_ES_DB: [Bootstrap service event source database]
MF_BOOTSTRAP_INSTANCE_NAME: [Bootstrap service instance name]
MF_JAEGER_URL: [Jaeger server URL]
MF_BOOTSTRAP_THINGS_TIMEOUT: [Things gRPC request timeout in seconds]
```

To start the service outside of the container, execute the following shell script:
Expand All @@ -122,7 +126,7 @@ make bootstrap
make install

# set the environment variables and run the service
MF_BOOTSTRAP_LOG_LEVEL=[Bootstrap log level] MF_BOOTSTRAP_DB_HOST=[Database host address] MF_BOOTSTRAP_DB_PORT=[Database host port] MF_BOOTSTRAP_DB_USER=[Database user] MF_BOOTSTRAP_DB_PASS=[Database password] MF_BOOTSTRAP_DB=[Name of the database used by the service] MF_BOOTSTRAP_DB_SSL_MODE=[SSL mode to connect to the database with] MF_BOOTSTRAP_DB_SSL_CERT=[Path to the PEM encoded certificate file] MF_BOOTSTRAP_DB_SSL_KEY=[Path to the PEM encoded key file] MF_BOOTSTRAP_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file] MF_BOOTSTRAP_CLIENT_TLS=[Boolean value to enable/disable client TLS] MF_BOOTSTRAP_CA_CERTS=[Path to trusted CAs in PEM format] MF_BOOTSTRAP_PORT=[Service HTTP port] MF_BOOTSTRAP_SERVER_CERT=[Path to server certificate] MF_BOOTSTRAP_SERVER_KEY=[Path to server key] MF_SDK_BASE_URL=[Base SDK URL for the Mainflux services] MF_SDK_THINGS_PREFIX=[SDK prefix for Things service] MF_USERS_URL=[Users service URL] $GOBIN/mainflux-bootstrap
MF_BOOTSTRAP_LOG_LEVEL=[Bootstrap log level] MF_BOOTSTRAP_DB_HOST=[Database host address] MF_BOOTSTRAP_DB_PORT=[Database host port] MF_BOOTSTRAP_DB_USER=[Database user] MF_BOOTSTRAP_DB_PASS=[Database password] MF_BOOTSTRAP_DB=[Name of the database used by the service] MF_BOOTSTRAP_DB_SSL_MODE=[SSL mode to connect to the database with] MF_BOOTSTRAP_DB_SSL_CERT=[Path to the PEM encoded certificate file] MF_BOOTSTRAP_DB_SSL_KEY=[Path to the PEM encoded key file] MF_BOOTSTRAP_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file] MF_BOOTSTRAP_CLIENT_TLS=[Boolean value to enable/disable client TLS] MF_BOOTSTRAP_CA_CERTS=[Path to trusted CAs in PEM format] MF_BOOTSTRAP_PORT=[Service HTTP port] MF_BOOTSTRAP_SERVER_CERT=[Path to server certificate] MF_BOOTSTRAP_SERVER_KEY=[Path to server key] MF_SDK_BASE_URL=[Base SDK URL for the Mainflux services] MF_SDK_THINGS_PREFIX=[SDK prefix for Things service] MF_USERS_URL=[Users service URL] MF_JAEGER_URL=[Jaeger server URL] MF_BOOTSTRAP_THINGS_TIMEOUT=[Things gRPC request timeout in seconds] $GOBIN/mainflux-bootstrap
```

Setting `MF_BOOTSTRAP_CA_CERTS` expects a file in PEM format of trusted CAs. This will enable TLS against the Users gRPC endpoint trusting only those CAs that are provided.
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
mfsdk "github.com/mainflux/mainflux/sdk/go"
"github.com/mainflux/mainflux/things"
thingsapi "github.com/mainflux/mainflux/things/api/things/http"
"github.com/opentracing/opentracing-go/mocktracer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -143,7 +144,7 @@ func newThingsService(users mainflux.UsersServiceClient) things.Service {
}

func newThingsServer(svc things.Service) *httptest.Server {
mux := thingsapi.MakeHandler(svc)
mux := thingsapi.MakeHandler(mocktracer.New(), svc)
return httptest.NewServer(mux)
}

Expand Down
36 changes: 18 additions & 18 deletions bootstrap/mocks/things.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewThingsService(things map[string]things.Thing, channels map[string]things
}
}

func (svc *mainfluxThings) AddThing(owner string, thing things.Thing) (things.Thing, error) {
func (svc *mainfluxThings) AddThing(_ context.Context, owner string, thing things.Thing) (things.Thing, error) {
svc.mu.Lock()
defer svc.mu.Unlock()

Expand All @@ -55,7 +55,7 @@ func (svc *mainfluxThings) AddThing(owner string, thing things.Thing) (things.Th
return thing, nil
}

func (svc *mainfluxThings) ViewThing(owner, id string) (things.Thing, error) {
func (svc *mainfluxThings) ViewThing(_ context.Context, owner, id string) (things.Thing, error) {
svc.mu.Lock()
defer svc.mu.Unlock()

Expand All @@ -72,7 +72,7 @@ func (svc *mainfluxThings) ViewThing(owner, id string) (things.Thing, error) {
return things.Thing{}, things.ErrNotFound
}

func (svc *mainfluxThings) Connect(owner, chanID, thingID string) error {
func (svc *mainfluxThings) Connect(_ context.Context, owner, chanID, thingID string) error {
svc.mu.Lock()
defer svc.mu.Unlock()

Expand All @@ -89,7 +89,7 @@ func (svc *mainfluxThings) Connect(owner, chanID, thingID string) error {
return nil
}

func (svc *mainfluxThings) Disconnect(owner, chanID, thingID string) error {
func (svc *mainfluxThings) Disconnect(_ context.Context, owner, chanID, thingID string) error {
svc.mu.Lock()
defer svc.mu.Unlock()

Expand Down Expand Up @@ -121,7 +121,7 @@ func (svc *mainfluxThings) Disconnect(owner, chanID, thingID string) error {
return nil
}

func (svc *mainfluxThings) RemoveThing(owner, id string) error {
func (svc *mainfluxThings) RemoveThing(_ context.Context, owner, id string) error {
svc.mu.Lock()
defer svc.mu.Unlock()

Expand Down Expand Up @@ -151,58 +151,58 @@ func (svc *mainfluxThings) RemoveThing(owner, id string) error {
return nil
}

func (svc *mainfluxThings) ViewChannel(owner, id string) (things.Channel, error) {
func (svc *mainfluxThings) ViewChannel(_ context.Context, owner, id string) (things.Channel, error) {
if c, ok := svc.channels[id]; ok {
return c, nil
}
return things.Channel{}, things.ErrNotFound
}

func (svc *mainfluxThings) UpdateThing(string, things.Thing) error {
func (svc *mainfluxThings) UpdateThing(context.Context, string, things.Thing) error {
panic("not implemented")
}

func (svc *mainfluxThings) UpdateKey(string, string, string) error {
func (svc *mainfluxThings) UpdateKey(context.Context, string, string, string) error {
panic("not implemented")
}

func (svc *mainfluxThings) ListThings(string, uint64, uint64, string) (things.ThingsPage, error) {
func (svc *mainfluxThings) ListThings(context.Context, string, uint64, uint64, string) (things.ThingsPage, error) {
panic("not implemented")
}

func (svc *mainfluxThings) ListChannelsByThing(string, string, uint64, uint64) (things.ChannelsPage, error) {
func (svc *mainfluxThings) ListChannelsByThing(context.Context, string, string, uint64, uint64) (things.ChannelsPage, error) {
panic("not implemented")
}

func (svc *mainfluxThings) ListThingsByChannel(string, string, uint64, uint64) (things.ThingsPage, error) {
func (svc *mainfluxThings) ListThingsByChannel(context.Context, string, string, uint64, uint64) (things.ThingsPage, error) {
panic("not implemented")
}

func (svc *mainfluxThings) CreateChannel(string, things.Channel) (things.Channel, error) {
func (svc *mainfluxThings) CreateChannel(context.Context, string, things.Channel) (things.Channel, error) {
panic("not implemented")
}

func (svc *mainfluxThings) UpdateChannel(string, things.Channel) error {
func (svc *mainfluxThings) UpdateChannel(context.Context, string, things.Channel) error {
panic("not implemented")
}

func (svc *mainfluxThings) ListChannels(string, uint64, uint64, string) (things.ChannelsPage, error) {
func (svc *mainfluxThings) ListChannels(context.Context, string, uint64, uint64, string) (things.ChannelsPage, error) {
panic("not implemented")
}

func (svc *mainfluxThings) RemoveChannel(string, string) error {
func (svc *mainfluxThings) RemoveChannel(context.Context, string, string) error {
panic("not implemented")
}

func (svc *mainfluxThings) CanAccess(string, string) (string, error) {
func (svc *mainfluxThings) CanAccess(context.Context, string, string) (string, error) {
panic("not implemented")
}

func (svc *mainfluxThings) CanAccessByID(string, string) error {
func (svc *mainfluxThings) CanAccessByID(context.Context, string, string) error {
panic("not implemented")
}

func (svc *mainfluxThings) Identify(string) (string, error) {
func (svc *mainfluxThings) Identify(context.Context, string) (string, error) {
panic("not implemented")
}

Expand Down
3 changes: 2 additions & 1 deletion bootstrap/redis/producer/streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/go-redis/redis"
"github.com/mainflux/mainflux"
"github.com/opentracing/opentracing-go/mocktracer"

"github.com/mainflux/mainflux/bootstrap"
"github.com/mainflux/mainflux/bootstrap/mocks"
Expand Down Expand Up @@ -88,7 +89,7 @@ func newThingsService(users mainflux.UsersServiceClient) things.Service {
}

func newThingsServer(svc things.Service) *httptest.Server {
mux := httpapi.MakeHandler(svc)
mux := httpapi.MakeHandler(mocktracer.New(), svc)
return httptest.NewServer(mux)
}
func TestAdd(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion bootstrap/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strconv"
"testing"

"github.com/opentracing/opentracing-go/mocktracer"

"github.com/gofrs/uuid"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/bootstrap"
Expand Down Expand Up @@ -74,7 +76,7 @@ func newThingsService(users mainflux.UsersServiceClient) things.Service {
}

func newThingsServer(svc things.Service) *httptest.Server {
mux := httpapi.MakeHandler(svc)
mux := httpapi.MakeHandler(mocktracer.New(), svc)
return httptest.NewServer(mux)
}

Expand Down
Loading