-
Notifications
You must be signed in to change notification settings - Fork 669
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
NOISSUE - Add subtopic wildcard for twin attribute's definition #1214
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1214 +/- ##
==========================================
+ Coverage 77.02% 77.44% +0.41%
==========================================
Files 104 104
Lines 6868 6875 +7
==========================================
+ Hits 5290 5324 +34
+ Misses 1196 1164 -32
- Partials 382 387 +5
Continue to review full report at Codecov.
|
e2ba6da
to
95c291b
Compare
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
a9798df
to
16861ab
Compare
@@ -74,6 +74,11 @@ func (tc *twinCache) IDs(_ context.Context, channel, subtopic string) ([]string, | |||
if err != nil { | |||
return nil, errors.Wrap(ErrRedisTwinIDs, err) | |||
} | |||
idsWildcard, err := tc.client.SMembers(attrKey(channel, twins.SubtopicWildcard)).Result() |
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.
SMembers
could have better naming
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.
Please elaborate on this. SMembers
is redis function.
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
16861ab
to
e8852a1
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
@@ -38,6 +41,15 @@ func CreateDefinition(channels []string, subtopics []string) twins.Definition { | |||
return def | |||
} | |||
|
|||
// CreateTwin creates twin | |||
func CreateTwin(channels []string, subtopics []string) twins.Twin { | |||
id++ |
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 do not know if having a global var would be a good idea here. I do not go in deeper analysis, but there is some "code smell". I would prefer some internal structure, created in the main()
via New()
fnc, then passed back here... Or something like this.
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 id
is not a global var, it's a package level var, not exported, used for the sole purpose of generating unique id's for the mock entitites that we use to test service. It's rather so called closure variable. The function users can't know anything about it.
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.
You can probably use this UUID mock here: https://github.com/mainflux/mainflux/blob/master/pkg/uuid/mock.go
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.
Looks like you already have it here https://github.com/mainflux/mainflux/blob/e8852a16ec984045094612ae16512d5c8f082885/twins/mocks/service.go#L24
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.
@darkodraskovic sorry I did not see this was for the mock. I will approve then. I let you take a look at this Manu's remark optionally, but this is good to me.
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.
@manuio i purposefully didn't use the mock uuid generator, cause i don't want to handle uuid error creation. I really need only mock id's, can be really anything, it's just for the purpose of differentiating the twins, so I just give them unique serial number like this - no possibility of error, so no need for error handling.
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
@@ -38,6 +41,15 @@ func CreateDefinition(channels []string, subtopics []string) twins.Definition { | |||
return def | |||
} | |||
|
|||
// CreateTwin creates twin | |||
func CreateTwin(channels []string, subtopics []string) twins.Twin { | |||
id++ |
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.
@darkodraskovic sorry I did not see this was for the mock. I will approve then. I let you take a look at this Manu's remark optionally, but this is good to me.
* Add wildcard to attribute subtopic Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com> * Add MF_TWINS_SUBTOPIC_WILDCARD env var Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com> * Remove configurable wildcard env var and mqtt notif leftovers Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com> * Add mongodb RetrieveByAttribute tests Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com> * Add redis wildcard subtopic IDs retrieval Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com> * Add tests for wildcard state save Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
What does this do?
Twin stores semantic definition of a data system. Such definition consists of attributes which are uniquely defined by the combination of channel and subtopic. Currently, we can only define attribute to match the combination of an empty or non-empty subtopic and channel. However, we don't have means to define attribute to match all the combinations of a certain channel and subtopics, i.e. we don't have means to store to states all message of a channel irrespective of the subtopic used to send messages. Adition of a wildcard subtopic enables attribute to pick up all messages sent via it's channel.
List any changes that modify/break current functionality
N/A
Have you included tests for your changes?
Yes
Did you document any new/modified functionality?
Yes