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 1413 - Use per-service URL in SDK #1444

Merged
merged 17 commits into from
Aug 11, 2021
Merged

MF 1413 - Use per-service URL in SDK #1444

merged 17 commits into from
Aug 11, 2021

Conversation

drasko
Copy link
Contributor

@drasko drasko commented Aug 8, 2021

Signed-off-by: Drasko DRASKOVIC drasko.draskovic@gmail.com

What does this do?

Fixes SDK to use per-service URL instead of BaseURL.

Which issue(s) does this PR fix/relate to?

Resolves #1413

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
@drasko drasko requested a review from a team as a code owner August 8, 2021 19:45
Signed-off-by: mteodor <mirko.teodorovic@gmail.com>
Signed-off-by: mteodor <mirko.teodorovic@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2021

Codecov Report

Merging #1444 (37461c8) into master (d6a3830) will increase coverage by 0.03%.
The diff coverage is 50.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1444      +/-   ##
==========================================
+ Coverage   70.86%   70.90%   +0.03%     
==========================================
  Files         123      123              
  Lines        9600     9564      -36     
==========================================
- Hits         6803     6781      -22     
+ Misses       2270     2256      -14     
  Partials      527      527              
Impacted Files Coverage Δ
certs/service.go 88.46% <ø> (ø)
pkg/sdk/go/bootstrap.go 0.00% <0.00%> (ø)
pkg/sdk/go/certs.go 0.00% <0.00%> (ø)
pkg/sdk/go/groups.go 0.00% <0.00%> (ø)
bootstrap/postgres/configs.go 70.32% <30.00%> (-0.47%) ⬇️
pkg/sdk/go/users.go 22.78% <40.00%> (ø)
pkg/sdk/go/message.go 34.88% <50.00%> (-0.68%) ⬇️
pkg/sdk/go/channels.go 56.52% <100.00%> (-2.16%) ⬇️
pkg/sdk/go/sdk.go 100.00% <100.00%> (+3.33%) ⬆️
pkg/sdk/go/things.go 57.74% <100.00%> (-1.72%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6a3830...37461c8. Read the comment docs.

@@ -160,7 +160,7 @@ func dec(in []byte) ([]byte, error) {
func newService(auth mainflux.AuthServiceClient, url string) bootstrap.Service {
things := mocks.NewConfigsRepository()
config := mfsdk.Config{
BootstrapURL: url,
ThingsURL: url,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why ThingsURL? It looks that caller is calling this newService() funtion with the URL of Bootstrap server, right? And we are giving this to ThingsURL.

Copy link
Contributor

Choose a reason for hiding this comment

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

ThingsURL is used to reach things service API endpoints.
Bootstrap test server is created after newService with
bs := newBootstrapServer(svc)
and then you can test bootstrap endpoints using bs.URL

	for _, tc := range cases {
		req := testRequest{
			client:      bs.Client(),
			method:      http.MethodPost,
			url:         fmt.Sprintf("%s/configs", bs.URL),```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naming of these functions is confusing. Calling something called newService() inside of Boostrap code, I would expect that it gives me back Boostrap service.

Also, take a look at the callers - what URLs do they provide? URLs of Things? How do you know where Things is - this is something that user should tell you via ENV var, no?

@@ -65,7 +65,7 @@ func newService(tokens map[string]string) (certs.Service, error) {

auth := thmocks.NewAuthService(tokens)
config := mfsdk.Config{
CertsURL: server.URL,
ThingsURL: server.URL,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is this server? Is it Bootstrap server? If yes - why we are giving this URL to Things service configuration - in realistic deployment these will be two completely different URLs.

Copy link
Contributor

Choose a reason for hiding this comment

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

server here is http server serving API calls to things service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, serving HTTP API of a Bootstrap service, i.e. it is a Bootstrap service httptest server. This is why I am saying that this is fundamentally wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

not bootstrap, but things

@@ -58,6 +58,7 @@ func newService(auth mainflux.AuthServiceClient, url string) bootstrap.Service {
things := mocks.NewConfigsRepository()
config := mfsdk.Config{
BootstrapURL: url,
ThingsURL: url,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same question here.

Copy link
Contributor

Choose a reason for hiding this comment

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

answer is similar as above, additionaly providing ThingsURL here is configuring bootstrap service so that it can reach things service API endpoints to create things, channels, check connections

drasko and others added 3 commits August 9, 2021 16:24
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
@@ -102,12 +102,3 @@ rundev:
run:
docker-compose -f docker/docker-compose.yml up

runlora:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this clutter because it is rarely launched and should be documented somewhere and not burden the main Makefile.

-f docker/addons/lora-adapter/docker-compose.yml up \

# Run all Mainflux core services except distributed tracing system - Jaeger. Recommended on gateways:
rungw:
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 might be useful, but again - rarely used. Should be rather documented somewhere and executd manually when needed.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
@@ -57,7 +57,8 @@ var (
func newService(auth mainflux.AuthServiceClient, url string) bootstrap.Service {
things := mocks.NewConfigsRepository()
config := mfsdk.Config{
BaseURL: url,
BootstrapURL: url,
Copy link
Contributor

Choose a reason for hiding this comment

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

we dont need this BootstrapURL

TLSVerification: false,
ThingsURL: ts.URL,
MsgContentType: contentType,
TLSVerification: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we perform tests with TLSVerification = true

tls = true
users_location = ""
users_url = ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not defaulting to the correct Users' service URL? Also, TLS is on, but URLs are http.

dborovcanin and others added 5 commits August 10, 2021 13:35
Update tests, remove linter warnings, remove dead code.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>
@drasko drasko merged commit d73a5d5 into master Aug 11, 2021
buraksekili pushed a commit to buraksekili/mainflux that referenced this pull request Sep 14, 2021
* Use per-service URL in SDK

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>

* Fix CLI

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix CLI messaging

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix message tests

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Simplify Bootstrap

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Update API doc and responses

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* fix failing certs, bootstrap tests

Signed-off-by: mteodor <mirko.teodorovic@gmail.com>

* fix failing certs, bootstrap tests

Signed-off-by: mteodor <mirko.teodorovic@gmail.com>

* Fix tests and rename to auth service

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Clean the code

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Remove unnecessary Repository logs

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Always return error in case of repo failure

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Cleanup SDK and CLI

Update tests, remove linter warnings, remove dead code.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Clean the code

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Undo Bootstrap changes

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix tests

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix linter

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

Co-authored-by: mteodor <mirko.teodorovic@gmail.com>
Co-authored-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: Burak Sekili <buraksekili@gmail.com>
mteodor added a commit to mteodor/mainflux that referenced this pull request Sep 15, 2021
* Use per-service URL in SDK

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>

* Fix CLI

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix CLI messaging

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix message tests

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Simplify Bootstrap

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Update API doc and responses

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* fix failing certs, bootstrap tests

Signed-off-by: mteodor <mirko.teodorovic@gmail.com>

* fix failing certs, bootstrap tests

Signed-off-by: mteodor <mirko.teodorovic@gmail.com>

* Fix tests and rename to auth service

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Clean the code

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Remove unnecessary Repository logs

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Always return error in case of repo failure

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Cleanup SDK and CLI

Update tests, remove linter warnings, remove dead code.

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>

* Clean the code

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Undo Bootstrap changes

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix tests

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

* Fix linter

Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com>

Co-authored-by: mteodor <mirko.teodorovic@gmail.com>
Co-authored-by: dusanb94 <dusan.borovcanin@mainflux.com>
@manuio manuio deleted the sdk branch May 14, 2022 10:14
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.

Use per-service URL in SDK
4 participants