-
Notifications
You must be signed in to change notification settings - Fork 674
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-552 - Use event sourcing to keep Bootstrap service in sync with Things service #603
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
c39bc67
to
469bedb
Compare
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
b8255a2
to
f463c0c
Compare
Codecov Report
@@ Coverage Diff @@
## master #603 +/- ##
==========================================
- Coverage 87.13% 86.72% -0.42%
==========================================
Files 62 62
Lines 3437 3623 +186
==========================================
+ Hits 2995 3142 +147
- Misses 304 327 +23
- Partials 138 154 +16
Continue to review full report at Codecov.
|
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
c38d20f
to
2743bbf
Compare
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
c82982c
to
3ee8e1f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
bootstrap/api/endpoint_test.go
Outdated
assert.Equal(t, tc.res, data, fmt.Sprintf("%s: expected response '%s' got '%s'", tc.desc, tc.res, data)) | ||
var view config | ||
err = json.NewDecoder(res.Body).Decode(&view) | ||
if err != io.EOF { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline.
bootstrap/api/logging.go
Outdated
|
||
func (lm *loggingMiddleware) RemoveConfigHandler(id string) (err error) { | ||
defer func(begin time.Time) { | ||
message := fmt.Sprintf("Method removeConfig for config %s took %s to complete", id, time.Since(begin)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
bootstrap/api/logging.go
Outdated
|
||
func (lm *loggingMiddleware) UpdateChannelHandler(channel bootstrap.Channel) (err error) { | ||
defer func(begin time.Time) { | ||
message := fmt.Sprintf("Method updateChannel for channel %s took %s to complete", channel.ID, time.Since(begin)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
bootstrap/postgres/configs.go
Outdated
|
||
for rows.Next() { | ||
c := bootstrap.Channel{} | ||
if err = rows.Scan(&c.ID, &c.Name, &c.Metadata); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use :=
.
bootstrap/postgres/configs.go
Outdated
|
||
for rows.Next() { | ||
c := bootstrap.Channel{} | ||
if err = rows.Scan(&c.ID, &c.Name, &c.Metadata); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use :=
.
bootstrap/postgres/configs.go
Outdated
return err | ||
} | ||
|
||
if err = insertChannels(key, channels, tx); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use :=
.
bootstrap/postgres/configs.go
Outdated
return err | ||
} | ||
|
||
if err = updateConnections(key, id, connections, tx); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use :=
.
bootstrap/postgres/configs.go
Outdated
var channels []bootstrap.Channel | ||
for rows.Next() { | ||
var ch bootstrap.Channel | ||
if err = rows.Scan(&ch.ID, &ch.Name, &ch.Metadata); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use :=
.
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
bootstrap/mocks/configs.go
Outdated
@@ -205,6 +242,75 @@ func (crm *configRepositoryMock) RemoveUnknown(key, id string) error { | |||
} | |||
|
|||
func (crm *configRepositoryMock) SaveUnknown(key, id string) error { | |||
crm.mu.Lock() | |||
crm.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't defer
needed here?
bootstrap/mocks/configs.go
Outdated
|
||
func (crm *configRepositoryMock) DisconnectThing(channelID, thingID string) error { | ||
crm.mu.Lock() | ||
crm.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - defer
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ings service (absmach#603) * Use separate table for Channels Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add inital event sourcing subscription Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Channel update sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Thing remove sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Channel remove sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update service add method marshalling metadata Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Make separate methods for connection update Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add diconnect event sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update Configs repository mock Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix service tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update repository tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update API docs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update Location header Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update README.md Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix tests mutex lock Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix method names in logs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
…ings service (#603) * Use separate table for Channels Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add inital event sourcing subscription Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Channel update sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Thing remove sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add Channel remove sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update service add method marshalling metadata Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Make separate methods for connection update Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Add diconnect event sync Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update Configs repository mock Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix service tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update repository tests Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update API docs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update Location header Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Update README.md Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix tests mutex lock Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com> * Fix method names in logs Signed-off-by: Dusan Borovcanin <dusan.borovcanin@mainflux.com>
What does this do?
This PR adds the use of event sourcing from Things service to keep corresponding Bootstrap service entities in sync.
Which issue(s) does this PR fix/relate to?
This PR resolves #552.
List any changes that modify/break current functionality
There are 2 major API changes:
- List of Configs does not return Channels
- Update Config is split to Config fields update and Config connections update
Have you included tests for your changes?
Yes.
Did you document any new/modified functionality?
Yes, docs are up to date.