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 all commits
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
23 changes: 7 additions & 16 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"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 Down Expand Up @@ -55,7 +54,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 Down Expand Up @@ -145,18 +143,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 := errgroup.Group{}
if srv.Config.Stats != nil {
errg.Go(func() error {
return srv.stats.Start()
return srv.Config.Stats.Start()
})
}
errg.Go(func() error {
Expand All @@ -170,8 +165,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 {
if srv.Config.Stats != nil {
if err := srv.Config.Stats.Shutdown(ctx); err != nil {
return err
}
}
Expand Down Expand Up @@ -205,7 +200,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 +215,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.

4 changes: 4 additions & 0 deletions server/stats/stats.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package stats

import "context"

// Stats provides an interface that different stats backend can implement to
// track server usage.
type Stats interface {
Start() error
Shutdown(context.Context) error
APILinkGen()
APILinkRequest()
APIUnlink()
Expand Down