-
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-1556 - Move the most used functions in main.go to internal package #1601
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #1601 +/- ##
==========================================
+ Coverage 70.32% 70.38% +0.06%
==========================================
Files 148 146 -2
Lines 11501 11394 -107
==========================================
- Hits 8088 8020 -68
+ Misses 2745 2724 -21
+ Partials 668 650 -18
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -0,0 +1,41 @@ | |||
// 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.
API util does not look like a good place for this. Something like internal/db/connect.go
. Also, the most commonly used DB connection (Postgres) is missing.
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.
So with Postgres, there is a slight issue. For instance when the auth service connects to Postgres, it will do a migration which is specific to the auth service and hence the bootstrap can't use it.
If we implement a common connect to Postgres this would mean we will import the different modules. Is that okay?
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.
@dborovcanin, Moving of postgres connect to internal package could be done in this PR or could we do it in seperate PR?
internal/apiutil/metrics.go
Outdated
stdprometheus "github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func MakeMetrics(svcName string) (*kitprometheus.Counter, *kitprometheus.Summary) { |
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.
No need for this complex logic. You can simply pass namespace and subsystem and use:
counter := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "request_count",
Help: "Number of requests received.",
}, []string{"method"})
latency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "request_latency_microseconds",
Help: "Total duration of requests in microseconds.",
}, []string{"method"})
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.
Do we need to differentiate the help message between a reader and a writer?
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.
@dborovcanin, changed, Please reveiew this part and give your comments,
internal/apiutil/auth.go
Outdated
@@ -0,0 +1,39 @@ | |||
// 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.
Consider renaming apiutil
to something closer to what this package is for - maybe initutil
or just init
.
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.
@dborovcanin, The init is misleading so we decided to use apiutil. And the internal folder is restrucutred.
Please review the latest code and give your comments
type GRPCServer struct { | ||
mfserver.BaseServer | ||
server *grpc.Server | ||
authSrvSvr mainflux.AuthServiceServer |
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.
Auth service sounds implementation-specific. What with other gRPC services, such as ThingsServiceServer
?
} | ||
|
||
func stopAllServer(servers ...Server) error { | ||
var err 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.
What's this error for?
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.
To be able to aggregate all the errors. For instance, we have two errors out of 5 servers, we will be able to return all the errors rather than the error it checked first
auth/api/grpc/server.go
Outdated
@@ -11,7 +11,7 @@ import ( | |||
"github.com/golang/protobuf/ptypes/empty" | |||
mainflux "github.com/mainflux/mainflux" | |||
"github.com/mainflux/mainflux/auth" | |||
"github.com/mainflux/mainflux/internal/apiutil" | |||
apiutil "github.com/mainflux/mainflux/internal/init" |
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 and for other imports
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.
Renaming to initutil
cmd/http/main.go
Outdated
"github.com/mainflux/mainflux" | ||
adapter "github.com/mainflux/mainflux/http" | ||
"github.com/mainflux/mainflux/http/api" | ||
initutil "github.com/mainflux/mainflux/internal/init" | ||
"github.com/mainflux/mainflux/internal/init/mfserver" | ||
"github.com/mainflux/mainflux/internal/init/mfserver/httpserver" |
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 is quite redundant. I'd use "github.com/mainflux/mainflux/internal/servers/http"
I'd prpose the next organisation:
internal/auth/auth.go
internal/auth/keto.go
internal/auth/things.go
internal/db/redis.go
internal/db/mongo.go
internal/server/http.go
internal/server/coap.go
internal/server/grpc.go
internal/apiutil/transport.go
internal/apiutil/responses.go
internal/apiutil/tokens.go
internal/apiutil/errors.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.
@manuio, changed as per you proposal
cmd/auth/main.go
Outdated
@@ -19,8 +19,8 @@ import ( | |||
"github.com/mainflux/mainflux/auth/tracing" | |||
"github.com/mainflux/mainflux/internal" | |||
"github.com/mainflux/mainflux/internal/server" | |||
"github.com/mainflux/mainflux/internal/server/grpcserver" | |||
"github.com/mainflux/mainflux/internal/server/httpserver" | |||
mfgrpcserver "github.com/mainflux/mainflux/internal/server/grpc" |
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'd remove mf
prefix
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, removed mf prefix
auth/api/grpc/server.go
Outdated
@@ -253,6 +253,6 @@ func encodeError(err error) error { | |||
case errors.Contains(err, errors.ErrAuthorization): | |||
return status.Error(codes.PermissionDenied, err.Error()) | |||
default: | |||
return status.Error(codes.Internal, "internal server error") | |||
return status.Error(codes.Internal, "apiutil server 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.
What this means? Can we find something more meaningfull?
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 ,changed to internal server 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.
If the lib @drasko suggested works for us - I'd go for it. It looks well written, tested, broadly used, and lightweight enough for us. I like having our solution, but we'd need to invest in testing and maintenance with no obvious benefits.
Start() error | ||
Stop() 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.
Maybe Serve
and Shutdown
are more similar to Go HTTP server terminology.
Ctx context.Context | ||
Cancel context.CancelFunc | ||
Name string | ||
Address string |
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.
Do we need Address
field?
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.
@dborovcanin, Yes required. Now it is used properly.
* Add : errgroup to cmd/auth Signed-off-by: Arvindh <arvindh91@gmail.com> * Add : Handle graceful stop for auth service Remove : errgroups from auth service Signed-off-by: Arvindh <arvindh91@gmail.com> * Add : Wait till server shutdown Signed-off-by: Arvindh <arvindh91@gmail.com> * Change : instead of waitgroup changed to errgroups Signed-off-by: Arvindh <arvindh91@gmail.com> * change : KillSignalHandler return type to error Signed-off-by: Arvindh <arvindh91@gmail.com> * Empty Commit Signed-off-by: Arvindh <arvindh91@gmail.com> * Add : Context to http server shutdown Rename : varaible from proto to protocol Signed-off-by: Arvindh <arvindh91@gmail.com> * change : to default log level Signed-off-by: Arvindh <arvindh91@gmail.com> * Add : Sign-off Signed-off-by: Arvindh <arvindh91@gmail.com> * Add: graceful stop of http and grpc server Signed-off-by: Arvindh <arvindh91@gmail.com> * Fix: typos and caps Signed-off-by: Arvindh <arvindh91@gmail.com> * Add: Signed-off Signed-off-by: Arvindh <arvindh91@gmail.com> * Rename: Func KillSignalHandler to SignalHandler Add: SIGABRT Signed-off-by: Arvindh <arvindh91@gmail.com> * Fix: auth service Signed-off-by: Arvindh <arvindh91@gmail.com> * Add: timeout for grpc gracefulstop Fix: typos Signed-off-by: Arvindh <arvindh91@gmail.com> * Add: .vscode folder to git ignore Signed-off-by: Arvindh <arvindh91@gmail.com> * change: variable name to stopWaitTime Signed-off-by: Arvindh <arvindh91@gmail.com> * remove: .vscode folder Signed-off-by: Arvindh <arvindh91@gmail.com> * remove: .vscode from .gitignore Signed-off-by: Arvindh <arvindh91@gmail.com> * Add : logger to handlers Signed-off-by: Arvindh <arvindh91@gmail.com> * Add : New line at end of .gitignore file Signed-off-by: Arvindh <arvindh91@gmail.com> * Fix : variable naming Add : graceful stop for timescale Signed-off-by: Arvindh <arvindh91@gmail.com> * Remove : unsued NATS library from import Signed-off-by: Arvindh <arvindh91@gmail.com> * Move: "https" and "https" to moved to const var Signed-off-by: Arvindh <arvindh91@gmail.com> * Move: "http" and "https" to moved to const var Signed-off-by: Arvindh <arvindh91@gmail.com> * update: branch with master Signed-off-by: Arvindh <arvindh91@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
* Initial commit Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Update subscriber interface Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add tests Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Add tests Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * check subscription map Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Check topic id after topic Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * reword description Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Setup empty queue Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Change mqtt implementation Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Switch statements Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Simplify Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Change mqtt subscriber Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Protect subscription map Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Fix subscription Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Set client id Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Format Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Change delete method Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
* Add max and min limit size Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Format Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> * Format Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: zhangchuanfeng <654300242@qq.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com> Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Done |
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
Signed-off-by: dusanb94 <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.
This is all good, just please remove full-stops from one-sentence comments and I will approve.
auth/postgres/init.go
Outdated
|
||
func migrateDB(db *sqlx.DB) error { | ||
migrations := &migrate.MemoryMigrationSource{ | ||
// Migration of Auth service. |
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.
No need for a full-stop at the end of the comment. Only if the comment spans more than one sentences, then putting full-stops makes sense.
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.
Removed end dot in single line comments
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.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
Signed-off-by: Arvindh <arvindh91@gmail.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
What does this do?
This pull request for moving the HTTP Server and GRPC server from cmd/service/main.go to internal/mfserver package
Which issue(s) does this PR fix/relate to?
Resolve partially #1556 because need to check other functions feasibility to move to internal package
List any changes that modify/break current functionality
N/A
Have you included tests for your changes?
N/A
Did you document any new/modified functionality?
N/A
Notes
N/A