-
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-780 - Use Normalizer as a lib #915
Conversation
Codecov Report
@@ Coverage Diff @@
## master #915 +/- ##
==========================================
+ Coverage 83.16% 83.59% +0.42%
==========================================
Files 75 75
Lines 5484 5341 -143
==========================================
- Hits 4561 4465 -96
+ Misses 652 610 -42
+ Partials 271 266 -5
Continue to review full report at Codecov.
|
@dusanb94 Don't forget to add documentation with description of the library and it's api. This would be helpful for the others who will write custom components/writers in some other programming languages ;) |
4c889e9
to
a53720b
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 scanned through the PR. Looks like we are really on good track here - I like the simplification!
topics.go
Outdated
@@ -7,3 +7,4 @@ package mainflux | |||
|
|||
// OutputSenML represents subject SenML messages will be published to. | |||
const OutputSenML = "out.senml" | |||
const OutputChannels = "channel.>" |
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 don't think that you can publish using the wild card as part of the topic.
writers/cassandra/messages.go
Outdated
@@ -20,37 +20,44 @@ func New(session *gocql.Session) writers.MessageRepository { | |||
return &cassandraRepository{session} | |||
} | |||
|
|||
func (cr *cassandraRepository) Save(msg mainflux.Message) error { | |||
func (cr *cassandraRepository) Save(messages []mainflux.Message) error { |
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.
Think about updating the interface to have a variadic function.
internal/normalizer/normalizer.go
Outdated
@@ -0,0 +1,64 @@ | |||
// Copyright (c) Mainflux |
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 that the normalizer shouldn't be in the internal
package. AFAIK, everything that's in the internal
cannot be used from the outside and as far as I understood, we want this lib to be usable from the outside too. At least think about creating an interface for the normalizer. Maybe this interface should have:
Normalize(msg mainflux.RawMessage) ([]interface{}, error)
You'll later have to cast this interface{}
but that's part of the language (if it had generics maybe we could have done something about it). This way you'll be able to create an interface for any other message type.
To normalize messages on the consumer side, Normalizer is moved to the internal pkgs. Writers being message consumers are modified to do message normalization instead of subscribing to normalized messages subject. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
As we agreed on absmach#919, we'll use normalizer as an interface and provide the default SenML implementation. Because of that, Normalizer is removed from `internal` and we'll use the project structure proposed in the aforementioned issue. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Move Normalizer service to `addons`. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
readers/api/logging.go
Outdated
defer func(begin time.Time) { | ||
lm.logger.Info(fmt.Sprintf(`Method read_all for offset %d and limit %d took %s to complete without errors.`, offset, limit, time.Since(begin))) | ||
message := fmt.Sprintf("Method read_all for offset %d and limit %d took %s to complete", offset, limit, 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.
You could log the Channel ID here
@@ -0,0 +1,28 @@ | |||
|
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.
Add Mainflux header insted of this blank line at the top.
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin <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
* Use Normalizer as a lib To normalize messages on the consumer side, Normalizer is moved to the internal pkgs. Writers being message consumers are modified to do message normalization instead of subscribing to normalized messages subject. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix logging middleware for readers and writers Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove normalizer interface Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Use Normalizer in writers As we agreed on #919, we'll use normalizer as an interface and provide the default SenML implementation. Because of that, Normalizer is removed from `internal` and we'll use the project structure proposed in the aforementioned issue. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Fix tests Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove unused batch settings from influxDB reader Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update docs Move Normalizer service to `addons`. Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Rename channels input topic Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update Noramlizer docs Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Remove commented code Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update readers logging Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update addons docker-compose files Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Update topcis explanations Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
Signed-off-by: Dušan Borovčanin dusan.borovcanin@mainflux.com
What does this do?
This pull request removes Normalizer service in favor of using normalizer as a lib on the message consumer side.
Which issue(s) does this PR fix/relate to?
Resolves #780.
List any changes that modify/break current functionality
Message consumers (writers) are modified to listen to all the message topics and normalize and persist messages.
Have you included tests for your changes?
Yes.
Did you document any new/modified functionality?
Yes.