Skip to content

Commit

Permalink
fix: metrics options
Browse files Browse the repository at this point in the history
  • Loading branch information
linyyyang committed Dec 14, 2022
1 parent 834389c commit 1c4fc5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ type Application struct {

// Option
type Option struct {
Name string
Version string
GrpcAddr string
HttpAddr string
Name string
Version string
GrpcAddr string
HttpAddr string
MetricsAddr string
}

// NewOption
Expand Down Expand Up @@ -91,6 +92,11 @@ func NewApp(
server.WithHttpAddr(option.HttpAddr),
)
}
if option.MetricsAddr != "" {
opts = append(opts,
server.WithMetricsAddr(option.MetricsAddr),
)
}

opts = append(opts, opt...)
app.Server = server.NewServer(ctx, logger, opts...)
Expand Down
9 changes: 9 additions & 0 deletions server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ func WithHttpAddr(addr string) Option {
}
}

// WithMetricsAddr
func WithMetricsAddr(addr string) Option {
return func(o *options) {
if addr != "" {
o.metricsAddr = addr
}
}
}

// WithDiscover
func WithDiscover(d Discover) Option {
return func(o *options) {
Expand Down
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func (s *Server) Close(ctx context.Context) error {
if s.healthServer != nil {
s.healthServer.Close()
}
if s.metricsServer != nil {
s.metricsServer.Close()
}
// deRegister
err := s.deRegister(ctx)
if err != nil {
Expand Down

0 comments on commit 1c4fc5c

Please sign in to comment.