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-780 - Use Normalizer as a lib #915

Merged
merged 13 commits into from
Oct 31, 2019
Merged

MF-780 - Use Normalizer as a lib #915

merged 13 commits into from
Oct 31, 2019

Conversation

dborovcanin
Copy link
Collaborator

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.

@codecov-io
Copy link

codecov-io commented Oct 28, 2019

Codecov Report

Merging #915 into master will increase coverage by 0.42%.
The diff coverage is 84.7%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
writers/mongodb/messages.go 100% <100%> (ø) ⬆️
writers/postgres/messages.go 79.68% <35.71%> (-1.98%) ⬇️
writers/influxdb/messages.go 90.9% <84.61%> (+4.99%) ⬆️
writers/cassandra/messages.go 94.11% <92.59%> (-5.89%) ⬇️
users/users.go 68.42% <0%> (-4.66%) ⬇️
users/api/http/requests.go 61.53% <0%> (-2.75%) ⬇️
users/api/http/transport.go 82.08% <0%> (-2.71%) ⬇️
users/api/http/responses.go 66.66% <0%> (ø) ⬆️
users/api/http/endpoint.go 86.2% <0%> (+0.87%) ⬆️
users/service.go 28.57% <0%> (+1.54%) ⬆️

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 380af87...1c76adb. Read the comment docs.

@chombium
Copy link
Collaborator

@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 ;)

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.

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.>"
Copy link
Contributor

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.

@@ -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 {
Copy link
Contributor

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.

@@ -0,0 +1,64 @@
// Copyright (c) Mainflux
Copy link
Contributor

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>
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>
@dborovcanin dborovcanin marked this pull request as ready for review October 30, 2019 15:55
@dborovcanin dborovcanin requested a review from a team as a code owner October 30, 2019 15:55
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
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))
Copy link
Contributor

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 @@

Copy link
Contributor

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>
Makefile Show resolved Hide resolved
topics.go Show resolved Hide resolved
nmarcetic
nmarcetic previously approved these changes Oct 31, 2019
Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
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 8be2516 into absmach:master Oct 31, 2019
@dborovcanin dborovcanin deleted the MF-780 branch December 18, 2019 10:35
manuio pushed a commit that referenced this pull request Oct 12, 2020
* 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>
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.

Consider message normalization design changes
7 participants