Просмотр исходного кода

revert application lifecycle event support

Marcus Efraimsson 7 лет назад
Родитель
Сommit
5d4dc18bbc
5 измененных файлов с 8 добавлено и 74 удалено
  1. 4 3
      pkg/cmd/grafana-server/server.go
  2. 0 22
      pkg/lifecycle/lifecycle.go
  3. 0 35
      pkg/lifecycle/lifecycle_test.go
  4. 3 6
      pkg/login/auth.go
  5. 1 8
      pkg/social/social.go

+ 4 - 3
pkg/cmd/grafana-server/server.go

@@ -15,9 +15,10 @@ import (
 	"github.com/grafana/grafana/pkg/api"
 	"github.com/grafana/grafana/pkg/api"
 	"github.com/grafana/grafana/pkg/api/routing"
 	"github.com/grafana/grafana/pkg/api/routing"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
-	"github.com/grafana/grafana/pkg/lifecycle"
+	"github.com/grafana/grafana/pkg/login"
 	"github.com/grafana/grafana/pkg/middleware"
 	"github.com/grafana/grafana/pkg/middleware"
 	"github.com/grafana/grafana/pkg/registry"
 	"github.com/grafana/grafana/pkg/registry"
+	"github.com/grafana/grafana/pkg/social"
 
 
 	"golang.org/x/sync/errgroup"
 	"golang.org/x/sync/errgroup"
 
 
@@ -69,7 +70,8 @@ func (g *GrafanaServerImpl) Run() error {
 	g.loadConfiguration()
 	g.loadConfiguration()
 	g.writePIDFile()
 	g.writePIDFile()
 
 
-	lifecycle.Notify(lifecycle.ApplicationStarting)
+	login.Init()
+	social.NewOAuthService()
 
 
 	serviceGraph := inject.Graph{}
 	serviceGraph := inject.Graph{}
 	serviceGraph.Provide(&inject.Object{Value: bus.GetBus()})
 	serviceGraph.Provide(&inject.Object{Value: bus.GetBus()})
@@ -142,7 +144,6 @@ func (g *GrafanaServerImpl) Run() error {
 	}
 	}
 
 
 	sendSystemdNotification("READY=1")
 	sendSystemdNotification("READY=1")
-	lifecycle.Notify(lifecycle.ApplicationStarted)
 	return g.childRoutines.Wait()
 	return g.childRoutines.Wait()
 }
 }
 
 

+ 0 - 22
pkg/lifecycle/lifecycle.go

@@ -1,22 +0,0 @@
-package lifecycle
-
-type Event int
-
-const (
-	ApplicationStarting Event = iota
-	ApplicationStarted
-)
-
-type EventHandlerFunc func()
-
-var listeners = map[int][]EventHandlerFunc{}
-
-func AddListener(evt Event, fn EventHandlerFunc) {
-	listeners[int(evt)] = append(listeners[int(evt)], fn)
-}
-
-func Notify(evt Event) {
-	for _, handler := range listeners[int(evt)] {
-		handler()
-	}
-}

+ 0 - 35
pkg/lifecycle/lifecycle_test.go

@@ -1,35 +0,0 @@
-package lifecycle
-
-import (
-	"testing"
-
-	. "github.com/smartystreets/goconvey/convey"
-)
-
-func TestLifecycle(t *testing.T) {
-	Convey("TestLifecycle", t, func() {
-		Convey("Given listeners", func() {
-			applicationStartingCounter := 0
-			AddListener(ApplicationStarting, func() {
-				applicationStartingCounter++
-			})
-
-			applicationStartedCounter := 0
-			AddListener(ApplicationStarted, func() {
-				applicationStartedCounter++
-			})
-
-			Convey("When notify application starting should call listener", func() {
-				Notify(ApplicationStarting)
-				So(applicationStartingCounter, ShouldEqual, 1)
-				So(applicationStartedCounter, ShouldEqual, 0)
-			})
-
-			Convey("When notify application started should call listener", func() {
-				Notify(ApplicationStarted)
-				So(applicationStartingCounter, ShouldEqual, 0)
-				So(applicationStartedCounter, ShouldEqual, 1)
-			})
-		})
-	})
-}

+ 3 - 6
pkg/login/auth.go

@@ -4,7 +4,6 @@ import (
 	"errors"
 	"errors"
 
 
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/bus"
-	"github.com/grafana/grafana/pkg/lifecycle"
 	m "github.com/grafana/grafana/pkg/models"
 	m "github.com/grafana/grafana/pkg/models"
 )
 )
 
 
@@ -20,11 +19,9 @@ var (
 	ErrGettingUserQuota      = errors.New("Error getting user quota")
 	ErrGettingUserQuota      = errors.New("Error getting user quota")
 )
 )
 
 
-func init() {
-	lifecycle.AddListener(lifecycle.ApplicationStarting, func() {
-		bus.AddHandler("auth", AuthenticateUser)
-		loadLdapConfig()
-	})
+func Init() {
+	bus.AddHandler("auth", AuthenticateUser)
+	loadLdapConfig()
 }
 }
 
 
 func AuthenticateUser(query *m.LoginUserQuery) error {
 func AuthenticateUser(query *m.LoginUserQuery) error {

+ 1 - 8
pkg/social/social.go

@@ -8,18 +8,11 @@ import (
 
 
 	"golang.org/x/oauth2"
 	"golang.org/x/oauth2"
 
 
-	"github.com/grafana/grafana/pkg/lifecycle"
 	"github.com/grafana/grafana/pkg/log"
 	"github.com/grafana/grafana/pkg/log"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func init() {
-	lifecycle.AddListener(lifecycle.ApplicationStarting, func() {
-		initOAuthService()
-	})
-}
-
 type BasicUserInfo struct {
 type BasicUserInfo struct {
 	Id      string
 	Id      string
 	Name    string
 	Name    string
@@ -63,7 +56,7 @@ var (
 	allOauthes    = []string{"github", "gitlab", "google", "generic_oauth", "grafananet", grafanaCom}
 	allOauthes    = []string{"github", "gitlab", "google", "generic_oauth", "grafananet", grafanaCom}
 )
 )
 
 
-func initOAuthService() {
+func NewOAuthService() {
 	setting.OAuthService = &setting.OAuther{}
 	setting.OAuthService = &setting.OAuther{}
 	setting.OAuthService.OAuthInfos = make(map[string]*setting.OAuthInfo)
 	setting.OAuthService.OAuthInfos = make(map[string]*setting.OAuthInfo)