-
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
MG-2142 - Consume Things connect/disconnect event in bootstrap #2192
Conversation
90b9f69
to
3198bd8
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.
I have question here, The event published by connectThingEvent
and disconnectThingEvent
are same event published by thing service on disconnect
and connect
?
They are not the same. The event published by things service is a notification that a thing has been connected or disconnected from a channel. The event published by |
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.
@JeffMboya I have suggestion for handling error rollbacks
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.
While trying to assign parent group for channel , like below request
curl --location 'http://localhost/channels/795b0be8-f8d9-4101-a40f-859ed573c71c/groups/assign' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <Token>' \
--data '{
"group_ids" : [ "5c6de392-6dc4-46fc-8e2c-e6f4ce4fffab" ]
}'
In events received below logs, which use group.assign
operation , the same operation is used for thing connect, so could not different between thing connection event and group assign channel events
[#8] Received on "events.magistrala.things" with reply "_INBOX.7g7jymtBXH0wOSok79kUGo.0LlN1Z1P"
*�{"group_id":"795b0be8-f8d9-4101-a40f-859ed573c71c","member_ids":["5c6de392-6dc4-46fc-8e2c-e6f4ce4fffab"],"occurred_at":1714131210669902557,"operation":"group.assign"}
Additionally,
In the event message group_id filed contains channel id
actually here we should have group id
In member_ids field , it contains
group_id , actually here we should have channel id
This issue might be a blocker for this PR
0b87686
to
9380eef
Compare
15ddd1f
to
068d129
Compare
b78c9aa
to
f6aa2fe
Compare
repo := postgres.NewConfigRepository(db, testLog) | ||
err := deleteChannels(context.Background(), repo) | ||
require.Nil(t, err, "Channels cleanup expected to succeed.") | ||
|
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.
Test this occurrences using table testing:
- Connect for an already connected thing
- Connect for a disconnected thing
- Connect for an invalid thing
- Connect for a random thing
- Connect for an empty thing
386c14c
to
73f7017
Compare
bootstrap/service.go
Outdated
channelsPage, err := bs.sdk.ChannelsByThing(cfg.ThingID, pm, token) | ||
if err != nil { | ||
return Config{}, errors.Wrap(errCheckChannels, err) | ||
} |
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.
This will not work , if thing is connect to 100 of channels.
By default the query limit is 10. So with this bs.sdk.ChannelsByThing(cfg.ThingID, pm, token)
we could not get all the 100 channels of thing.
There are two options:
- Iterate on
channelsPage.Total
and get all the channels - New API endpoint things to verify the thing and channel are connected. (This option looks for me most efficent way)
bootstrap/service.go
Outdated
|
||
channelsPage, err := bs.sdk.ChannelsByThing(cfg.ThingID, pm, token) | ||
if err != nil { | ||
return errors.Wrap(errChangeState, err) | ||
} | ||
|
||
for _, channel := range channelsPage.Channels { | ||
existingChannels[channel.ID] = true | ||
} |
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.
I think we don't want this, because sending connect request to already connected channel should not throw error.
If things API throw error. then we should think about changing the response of things API
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.
I think we don't want this, because sending connect request to already connected channel should not throw error. If things API throw error. then we should think about changing the response of things API
@arvindh123 yes, things API throws http status 409
when you send a connect request to an already connected channel.
magistrala-things | {"time":"2024-06-12T10:04:36.568921712Z","level":"WARN","msg":"Assign member to group failed to complete successfully","duration":"67.069682ms","group_id":"8fac693b-dc98-4178-b828-a4d4a8008d05","relation":"group","member_kind":"things","member_ids":["f2097dff-8e03-4461-92f1-80b972bb3c10"],"error":{"error":"entity already exists","message":"failed to add policies"}}
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]> Add ConnectThing method to bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect in bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect in bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect in bootstrap Signed-off-by: JeffMboya <[email protected]> Consume ThingConnect event Signed-off-by: JeffMboya <[email protected]> Consume ThingsConnect event Signed-off-by: JeffMboya <[email protected]> Consume ThingsConnect event Signed-off-by: JeffMboya <[email protected]> Consume ThingsConnect event Signed-off-by: JeffMboya <[email protected]> Implement ReadStringSlice Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add memberKind and relation checks Signed-off-by: JeffMboya <[email protected]> Add TestDisconnectThing to configs_test Signed-off-by: JeffMboya <[email protected]> Update mocks Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]> Refactor: revert to thingID and channelID Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]> Refactor: add memberKind ans relation constants Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
Signed-off-by: JeffMboya <[email protected]>
MG-2142 - Consume Things connect/disconnect event in Bootstrap (absmach#2192) NOISSUE - add CreatedAt and UpdatedAt fields for mgclients.Client (absmach#2306) NOISSUE - Fix failed log message (absmach#2307) MF-2299 - Update influxdb2 volumes path (absmach#2300) NOISSUE - Remove redundant relation check (absmach#2197) NOISSUE - Add domain events for Auth service (absmach#2313) NOISSUE - Update CI tools (absmach#2314) MG-888 - Update consumers SDK tests (absmach#2271) MG-888 - Add bootstrap SDK tests (absmach#2261) MG-2026 - Fix JSON page response key from groups to channels (absmach#2298) MG-1965 - Process Event Logs (absmach#2057) MG-1529 - User Removal (absmach#2122)
What type of PR is this?
This is a feature because it adds the connectEvent struct to the consumer package.
What does this do?
channel
andthing
are connected , change state of config toActive
channel
andthing
are disconnected, change state of config toInactive
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
Yes, I have included tests for my changes.
Did you document any new/modified feature?
No