Sqlstore refactor (#11908)

* refactor: tracing service refactoring

* refactor: sqlstore to instance service

* refactor: sqlstore & registory priority

* refactor: sqlstore refactor wip

* sqlstore: progress on getting tests to work again

* sqlstore: progress on refactoring and getting tests working

* sqlstore: connection string fix

* fix: not sure why this test is not working and required changing expires

* fix: updated grafana-cli
This commit is contained in:
Torkel Ödegaard
2018-05-18 11:10:10 +02:00
committed by GitHub
parent 78e837cf39
commit 6c0752473a
13 changed files with 228 additions and 201 deletions
+3 -1
View File
@@ -22,7 +22,9 @@ func runDbCommand(command func(commandLine CommandLine) error) func(context *cli
Args: flag.Args(),
})
sqlstore.NewEngine()
engine := &sqlstore.SqlStore{}
engine.Cfg = cfg
engine.Init()
if err := command(cmd); err != nil {
logger.Errorf("\n%s: ", color.RedString("Error"))
+10 -15
View File
@@ -8,7 +8,6 @@ import (
"net"
"os"
"path/filepath"
"reflect"
"strconv"
"time"
@@ -23,7 +22,6 @@ import (
"github.com/grafana/grafana/pkg/api"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/login"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
@@ -37,6 +35,7 @@ import (
_ "github.com/grafana/grafana/pkg/services/notifications"
_ "github.com/grafana/grafana/pkg/services/provisioning"
_ "github.com/grafana/grafana/pkg/services/search"
_ "github.com/grafana/grafana/pkg/services/sqlstore"
_ "github.com/grafana/grafana/pkg/tracing"
)
@@ -70,10 +69,6 @@ func (g *GrafanaServerImpl) Run() error {
g.loadConfiguration()
g.writePIDFile()
// initSql
sqlstore.NewEngine() // TODO: this should return an error
sqlstore.EnsureAdminUser()
login.Init()
social.NewOAuthService()
@@ -88,7 +83,7 @@ func (g *GrafanaServerImpl) Run() error {
// Add all services to dependency graph
for _, service := range services {
serviceGraph.Provide(&inject.Object{Value: service})
serviceGraph.Provide(&inject.Object{Value: service.Instance})
}
serviceGraph.Provide(&inject.Object{Value: g})
@@ -100,25 +95,25 @@ func (g *GrafanaServerImpl) Run() error {
// Init & start services
for _, service := range services {
if registry.IsDisabled(service) {
if registry.IsDisabled(service.Instance) {
continue
}
g.log.Info("Initializing " + reflect.TypeOf(service).Elem().Name())
g.log.Info("Initializing " + service.Name)
if err := service.Init(); err != nil {
if err := service.Instance.Init(); err != nil {
return fmt.Errorf("Service init failed: %v", err)
}
}
// Start background services
for index := range services {
service, ok := services[index].(registry.BackgroundService)
for _, descriptor := range services {
service, ok := descriptor.Instance.(registry.BackgroundService)
if !ok {
continue
}
if registry.IsDisabled(services[index]) {
if registry.IsDisabled(descriptor.Instance) {
continue
}
@@ -133,9 +128,9 @@ func (g *GrafanaServerImpl) Run() error {
// If error is not canceled then the service crashed
if err != context.Canceled && err != nil {
g.log.Error("Stopped "+reflect.TypeOf(service).Elem().Name(), "reason", err)
g.log.Error("Stopped "+descriptor.Name, "reason", err)
} else {
g.log.Info("Stopped "+reflect.TypeOf(service).Elem().Name(), "reason", err)
g.log.Info("Stopped "+descriptor.Name, "reason", err)
}
// Mark that we are in shutdown mode