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-906 - Change single creation endpoints to use bulk service calls #927

Merged
merged 8 commits into from
Nov 4, 2019
Merged

MF-906 - Change single creation endpoints to use bulk service calls #927

merged 8 commits into from
Nov 4, 2019

Conversation

nwneisen
Copy link
Contributor

What does this do?

Changes the single things and channels creation endpoints to use bulk service calls. All code for single creation is removed and tests updated to use bulk creation calls.

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

Resolves #906

List any changes that modify/break current functionality

Single creation endpoints behave the same from a user's perspective.

Have you included tests for your changes?

Tests were updated to use bulk creation methods.

Did you document any new/modified functionality?

NA

Notes

Signed-off-by: Nick Neisen <nwneisen@gmail.com>
Signed-off-by: Nick Neisen <nwneisen@gmail.com>
Signed-off-by: Nick Neisen <nwneisen@gmail.com>
@nwneisen nwneisen requested a review from a team as a code owner October 31, 2019 16:56
things/postgres/things_test.go Outdated Show resolved Hide resolved
things/postgres/channels_test.go Outdated Show resolved Hide resolved
Signed-off-by: Nick Neisen <nwneisen@gmail.com>
Copy link
Collaborator

@nmarcetic nmarcetic left a comment

Choose a reason for hiding this comment

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

@nwneisen I would prefer to keep method naming simple and clean by removing Bulk word :) So I would prefer Create() vs BulkCreate() etc... even if method accept a slice of things/channels
Word bulk adds complexity and confusion IMHO, keeps things simple as they are and documenting interface (good comments) is perfect.
I am approving PR, good job really! This is just my personal feeling about naming, which you can accept or not :) It's your call.

nmarcetic
nmarcetic previously approved these changes Nov 1, 2019
@drasko
Copy link
Contributor

drasko commented Nov 1, 2019

@nwneisen you have a message from the SemaphoreCI:

ok  	github.com/mainflux/mainflux/things/api/things/http	3.091s	coverage: 95.3% of statements
?   	github.com/mainflux/mainflux/things/mocks	[no test files]
# github.com/mainflux/mainflux/things/postgres_test [github.com/mainflux/mainflux/things/postgres.test]
things/postgres/channels_test.go:624:22: thingRepo.SaveSave undefined (type things.ThingRepository has no field or method SaveSave)
FAIL	github.com/mainflux/mainflux/things/postgres [build failed]
FAIL```

;)

things/service.go Outdated Show resolved Hide resolved
@nwneisen
Copy link
Contributor Author

nwneisen commented Nov 1, 2019

@nmarcetic I agree completely. When I do a search for remaining "bulk" word usages, I only see it still used with the single vs bulk endpoints. Let me know if there is somewhere I am missing.

I will say that I am still in favor of depreciating this single endpoint as well. If only one thing/channel is needed, then a user would simply send an array of size one. This would make it so the user only needs to understand one method to create a thing/channel.

@drasko
Copy link
Contributor

drasko commented Nov 1, 2019

I will say that I am still in favor of depreciating this single endpoint as well. If only one thing/channel is needed, then a user would simply send an array of size one.

@nwneisen exactly, this would be the best approach.

@nwneisen
Copy link
Contributor Author

nwneisen commented Nov 1, 2019

@manuio

@drasko Making sure everyone is on board as this was my previous suggestion.

It's also worth noting that with the exception of the blank payload, the bulk provisioning could be used to replace creating a single thing. This would be a breaking change but might be worth considering in the future to reduce maintenance. If sending a blank payload to create a thing is desired, then this could also be added to the bulk provisioning endpoint.

The single endpoint will create a thing/channel when is passed an empty payload. It also returns the created thing's/channel's ID in the location header.

@drasko
Copy link
Contributor

drasko commented Nov 1, 2019

The single endpoint will create a thing/channel when is passed an empty payload. It also returns the created thing's/channel's ID in the location header.

I am interested what would the others say, but personally this looks OK for me - passing an empty call means "create one thing without metadata", while passing a call with array of length 1 in a parameter might mean "create one thing with this meatadata".

I am however thinking that we might be interested in creating for example 100 things without metadata, and I do not know how we can do it with this API...

@nmarcetic @anovakovic01 @dusanb94 ^

Signed-off-by: Nick Neisen <nwneisen@gmail.com>
@codecov-io
Copy link

codecov-io commented Nov 1, 2019

Codecov Report

Merging #927 into master will decrease coverage by 0.89%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #927     +/-   ##
=========================================
- Coverage   83.85%   82.95%   -0.9%     
=========================================
  Files          75       75             
  Lines        5667     5298    -369     
=========================================
- Hits         4752     4395    -357     
+ Misses        655      643     -12     
  Partials      260      260
Impacted Files Coverage Δ
things/redis/streams.go 92.18% <100%> (-0.99%) ⬇️
things/api/things/http/endpoint.go 98.54% <100%> (ø) ⬆️
things/service.go 90.44% <100%> (-1.56%) ⬇️
things/postgres/channels.go 81.3% <100%> (-4.1%) ⬇️
things/api/things/http/requests.go 87.5% <100%> (ø) ⬆️
things/api/things/http/transport.go 93.77% <100%> (ø) ⬆️
things/api/things/http/responses.go 97.56% <100%> (+0.06%) ⬆️
things/postgres/things.go 79.62% <100%> (-7.31%) ⬇️
... 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 28a176a...6301379. Read the comment docs.

@nwneisen
Copy link
Contributor Author

nwneisen commented Nov 1, 2019

@drasko Using bulk create, an empty JSON payload ("" or "[]") will not create the thing/channel. A payload with an empty JSON object ("[{}]") will. To create 100 things without metadata, a JSON array with 100 empty objects could be used.

@drasko
Copy link
Contributor

drasko commented Nov 1, 2019

@nwneisen yep, I see.

It looks OK to me, I think there is no particular need to complicate the code and add other options - especially that most of the time interaction with the REST API will be via CLI or SDK (meaning that CLI and SDK must be changed as well in this PR, if the API changes).

Never the less, I'd like to hear the opinion of other maintainers.

things/things.go Outdated Show resolved Hide resolved
@anovakovic01
Copy link
Contributor

anovakovic01 commented Nov 4, 2019

@drasko I don't think that we need an endpoint for the creation of a single thing.

@nmarcetic
Copy link
Collaborator

@drasko I don't think that we need an endpoint for the creation of a single thing.

I agree with @anovakovic01
@nwneisen You can merge those two endpoints and keep just on which will accept a slice of things/channels. This will keep things simpler but will require changes in SDK, UI also, etc... its breaking change. Maybe is better idea to keep it like this, for now, 2 endpoints like you did, then in the next release merge it and make an announcement.

What do you think @nwneisen ?

@dborovcanin
Copy link
Collaborator

I agree with @nmarcetic. @nwneisen Please resolve remaining remark (variadic Save), so that we can approve and merge.

@nwneisen
Copy link
Contributor Author

nwneisen commented Nov 4, 2019

@nmarcetic I was thinking leave the single endpoint for now but look at adding a depreciation warning and/or announcement for when it would be completely removed.

Signed-off-by: Nick Neisen <nwneisen@gmail.com>
@nmarcetic
Copy link
Collaborator

@nmarcetic I was thinking leave the single endpoint for now but look at adding a deprecation warning and/or announcement for when it would be completely removed.

@nwneisen c I was thinking to leave the single endpoint for now Now is not a single endpoint, there is 2 endpoints POST on /things and things/bulk
Let's leave it for now and as you said, make a deprecation warning and/or announcement and remove it in the next milestone.

nmarcetic
nmarcetic previously approved these changes Nov 4, 2019
@nwneisen
Copy link
Contributor Author

nwneisen commented Nov 4, 2019

@nmarcetic

I was thinking leave the single endpoint for now

I was thinking leave the single creation endpoint (/things) for now*

@drasko
Copy link
Contributor

drasko commented Nov 4, 2019

@nmarcetic @nwneisen can we open an issue for this merging of endpoints not to forget?

drasko
drasko previously approved these changes Nov 4, 2019
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@nwneisen
Copy link
Contributor Author

nwneisen commented Nov 4, 2019

@drasko @nmarcetic I will add the depreciation warning and place a warning in the docs before this PR gets merged

Signed-off-by: Nick Neisen <nwneisen@gmail.com>
Copy link
Contributor

@anovakovic01 anovakovic01 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit 1a31ecd into absmach:master Nov 4, 2019
@drasko
Copy link
Contributor

drasko commented Nov 4, 2019

Thanks @nwneisen, again a great contribution!

I like PRs that remove code :).

@nwneisen nwneisen deleted the MF-906 branch November 25, 2019 17:18
manuio pushed a commit that referenced this pull request Oct 12, 2020
…927)

* Change single endpoints to use bulk creation

Signed-off-by: Nick Neisen <nwneisen@gmail.com>

* Remove single creation from thing's service

Signed-off-by: Nick Neisen <nwneisen@gmail.com>

* Remove single save from thing's postgres

Signed-off-by: Nick Neisen <nwneisen@gmail.com>

* Change BulkSave to Save

Signed-off-by: Nick Neisen <nwneisen@gmail.com>

* Change service calls to use variadic parameters

Signed-off-by: Nick Neisen <nwneisen@gmail.com>

* Change postgres things to use variadic functions

Signed-off-by: Nick Neisen <nwneisen@gmail.com>

* Add depreciation warnings

Signed-off-by: Nick Neisen <nwneisen@gmail.com>
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.

Change single creation endpoints to use bulk service calls
6 participants