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

feat: remove sqlite metrics #137

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 10 additions & 24 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
charm "github.com/charmbracelet/charm/proto"
"github.com/charmbracelet/charm/server/db"
"github.com/charmbracelet/charm/server/db/sqlite"
"github.com/charmbracelet/charm/server/stats"
"github.com/charmbracelet/charm/server/stats/prometheus"
sls "github.com/charmbracelet/charm/server/stats/sqlite"
"github.com/charmbracelet/charm/server/storage"
lfs "github.com/charmbracelet/charm/server/storage/local"
gossh "golang.org/x/crypto/ssh"
Expand All @@ -43,7 +41,7 @@ type Config struct {
PrivateKey []byte
DB db.DB
FileStore storage.FileStore
Stats stats.Stats
Stats *prometheus.Stats
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
linkQueue charm.LinkQueue
tlsConfig *tls.Config
jwtKeyPair JSONWebKeyPair
Expand All @@ -55,7 +53,6 @@ type Server struct {
Config *Config
ssh *SSHServer
http *HTTPServer
stats *prometheus.Stats
}

// DefaultConfig returns a Config with the values populated with the defaults
Expand All @@ -82,7 +79,7 @@ func (cfg *Config) WithFileStore(fs storage.FileStore) *Config {
}

// WithStats returns a Config with the provided Stats implementation.
func (cfg *Config) WithStats(s stats.Stats) *Config {
func (cfg *Config) WithStats(s *prometheus.Stats) *Config {
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
cfg.Stats = s
return cfg
}
Expand Down Expand Up @@ -145,20 +142,15 @@ func NewServer(cfg *Config) (*Server, error) {
return nil, err
}
s.http = hs
if cfg.EnableMetrics {
s.stats = prometheus.NewStats(cfg.DB, cfg.StatsPort)
}
return s, nil
}

// Start starts the HTTP, SSH and health HTTP servers for the Charm Cloud.
func (srv *Server) Start() error {
errg, _ := errgroup.WithContext(context.Background())
if srv.stats != nil {
errg.Go(func() error {
return srv.stats.Start()
})
}
errg := errgroup.Group{}
errg.Go(func() error {
return srv.Config.Stats.Start()
})
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
errg.Go(func() error {
return srv.http.Start()
})
Expand All @@ -170,10 +162,8 @@ func (srv *Server) Start() error {

// Shutdown shuts down the HTTP, and SSH and health HTTP servers for the Charm Cloud.
func (srv *Server) Shutdown(ctx context.Context) error {
if srv.stats != nil {
if err := srv.stats.Shutdown(ctx); err != nil {
return err
}
if err := srv.Config.Stats.Shutdown(ctx); err != nil {
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
if err := srv.ssh.Shutdown(ctx); err != nil {
return err
Expand Down Expand Up @@ -205,7 +195,7 @@ func (srv *Server) Close() error {
func (srv *Server) init(cfg *Config) {
if cfg.DB == nil {
dp := filepath.Join(cfg.DataDir, "db")
err := storage.EnsureDir(dp, 0700)
err := storage.EnsureDir(dp, 0o700)
if err != nil {
log.Fatalf("could not init sqlite path: %s", err)
}
Expand All @@ -220,10 +210,6 @@ func (srv *Server) init(cfg *Config) {
srv.Config = cfg.WithFileStore(fs)
}
if cfg.Stats == nil {
sts, err := sls.NewStats(filepath.Join(cfg.DataDir, "stats"))
if err != nil {
log.Fatalf("could not init stats db: %s", err)
}
srv.Config = cfg.WithStats(sts)
srv.Config = cfg.WithStats(prometheus.NewStats(cfg.DB, cfg.StatsPort))
}
}
191 changes: 0 additions & 191 deletions server/stats/sqlite/sqlite.go

This file was deleted.

23 changes: 0 additions & 23 deletions server/stats/stats.go

This file was deleted.