-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from snapp-incubator/initial-metric
Use JetStream Instead of Regular NATS and Add Metrics
- Loading branch information
Showing
14 changed files
with
508 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ linters: | |
- govet | ||
- revive | ||
- staticcheck | ||
- errcheck | ||
- errcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package metric | ||
|
||
type Config struct { | ||
Server Server `json:"server,omitempty" koanf:"server"` | ||
Enabled bool `json:"enabled,omitempty" koanf:"enabled"` | ||
} | ||
|
||
type Server struct { | ||
Address string `json:"address,omitempty" koanf:"address"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package metric | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// MetricServer contains information about metrics server. | ||
type ServerInfo struct { | ||
srv *http.ServeMux | ||
address string | ||
} | ||
|
||
// NewServer creates a new monitoring server. | ||
func NewServer(cfg Config) ServerInfo { | ||
var srv *http.ServeMux | ||
|
||
if cfg.Enabled { | ||
srv = http.NewServeMux() | ||
srv.Handle("/metrics", promhttp.Handler()) | ||
} | ||
|
||
return ServerInfo{ | ||
address: cfg.Server.Address, | ||
srv: srv, | ||
} | ||
} | ||
|
||
// Start creates and run a metric server for prometheus in new go routine. | ||
// nolint: mnd | ||
func (s ServerInfo) Start(logger *zap.Logger) { | ||
go func() { | ||
// nolint: exhaustruct | ||
srv := http.Server{ | ||
Addr: s.address, | ||
Handler: s.srv, | ||
ReadTimeout: 10 * time.Second, | ||
WriteTimeout: 10 * time.Second, | ||
IdleTimeout: 30 * time.Second, | ||
TLSConfig: nil, | ||
} | ||
|
||
if err := srv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { | ||
logger.Error("metric server initiation failed", zap.Error(err)) | ||
} | ||
}() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.