mirror of
https://github.com/alibaba/higress.git
synced 2026-03-07 01:50:51 +08:00
Co-authored-by: Kent Dong <ch3cho@qq.com>
This commit is contained in:
@@ -398,6 +398,7 @@ func (s *Server) initHttpServer() error {
|
||||
}
|
||||
s.xdsServer.AddDebugHandlers(s.httpMux, nil, true, nil)
|
||||
s.httpMux.HandleFunc("/ready", s.readyHandler)
|
||||
s.httpMux.HandleFunc("/registry/watcherStatus", s.registryWatcherStatusHandler)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -413,6 +414,43 @@ func (s *Server) readyHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Server) registryWatcherStatusHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
ingressTranslation, ok := s.environment.IngressStore.(*translation.IngressTranslation)
|
||||
if !ok {
|
||||
http.Error(w, "IngressStore not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
ingressConfig := ingressTranslation.GetIngressConfig()
|
||||
if ingressConfig == nil {
|
||||
http.Error(w, "IngressConfig not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
registryReconciler := ingressConfig.RegistryReconciler
|
||||
if registryReconciler == nil {
|
||||
http.Error(w, "RegistryReconciler not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
watcherStatusList := registryReconciler.GetRegistryWatcherStatusList()
|
||||
writeJSON(w, watcherStatusList)
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, obj interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
b, err := config.ToJSON(obj)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
_, err = w.Write(b)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// cachesSynced checks whether caches have been synced.
|
||||
func (s *Server) cachesSynced() bool {
|
||||
return s.configController.HasSynced()
|
||||
|
||||
@@ -73,6 +73,10 @@ func (m *IngressTranslation) InitializeCluster(ingressController common.IngressC
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *IngressTranslation) GetIngressConfig() *ingressconfig.IngressConfig {
|
||||
return m.ingressConfig
|
||||
}
|
||||
|
||||
func (m *IngressTranslation) RegisterEventHandler(kind config.GroupVersionKind, f model.EventHandler) {
|
||||
m.ingressConfig.RegisterEventHandler(kind, f)
|
||||
if m.kingressConfig != nil {
|
||||
|
||||
@@ -162,3 +162,7 @@ func (w *watcher) generateServiceEntry(host string) *v1alpha3.ServiceEntry {
|
||||
}
|
||||
return se
|
||||
}
|
||||
|
||||
func (w *watcher) GetRegistryType() string {
|
||||
return w.RegistryConfig.Type
|
||||
}
|
||||
|
||||
@@ -278,3 +278,25 @@ func (r *Reconciler) getAuthOption(registry *apiv1.RegistryConfig) (AuthOption,
|
||||
|
||||
return authOption, nil
|
||||
}
|
||||
|
||||
type RegistryWatcherStatus struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Healthy bool `json:"healthy"`
|
||||
Ready bool `json:"ready"`
|
||||
}
|
||||
|
||||
func (r *Reconciler) GetRegistryWatcherStatusList() []RegistryWatcherStatus {
|
||||
var registryStatusList []RegistryWatcherStatus
|
||||
for key, watcher := range r.watchers {
|
||||
_, name := path.Split(key)
|
||||
registryStatus := RegistryWatcherStatus{
|
||||
Name: name,
|
||||
Type: watcher.GetRegistryType(),
|
||||
Healthy: watcher.IsHealthy(),
|
||||
Ready: watcher.IsReady(),
|
||||
}
|
||||
registryStatusList = append(registryStatusList, registryStatus)
|
||||
}
|
||||
return registryStatusList
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ type Watcher interface {
|
||||
Run()
|
||||
Stop()
|
||||
IsHealthy() bool
|
||||
IsReady() bool
|
||||
GetRegistryType() string
|
||||
AppendServiceUpdateHandler(f func())
|
||||
ReadyHandler(f func(bool))
|
||||
@@ -57,17 +58,22 @@ type Watcher interface {
|
||||
type BaseWatcher struct {
|
||||
UpdateService ServiceUpdateHandler
|
||||
Ready ReadyHandler
|
||||
ReadyStatus bool
|
||||
}
|
||||
|
||||
func (w *BaseWatcher) Run() {}
|
||||
func (w *BaseWatcher) Stop() {}
|
||||
func (w *BaseWatcher) IsHealthy() bool { return true }
|
||||
func (w *BaseWatcher) IsReady() bool { return w.ReadyStatus }
|
||||
func (w *BaseWatcher) GetRegistryType() string { return "" }
|
||||
func (w *BaseWatcher) AppendServiceUpdateHandler(f func()) {
|
||||
w.UpdateService = f
|
||||
}
|
||||
func (w *BaseWatcher) ReadyHandler(f func(bool)) {
|
||||
w.Ready = f
|
||||
func (w *BaseWatcher) ReadyHandler(f func(isReady bool)) {
|
||||
w.Ready = func(isReady bool) {
|
||||
w.ReadyStatus = isReady
|
||||
f(isReady)
|
||||
}
|
||||
}
|
||||
|
||||
type ServiceUpdateHandler func()
|
||||
|
||||
@@ -678,7 +678,7 @@ func (w *watcher) Run() {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
var needNewFetch bool
|
||||
if w.IsReady() {
|
||||
if w.watcherReady() {
|
||||
w.Ready(true)
|
||||
needNewFetch = true
|
||||
}
|
||||
@@ -727,7 +727,7 @@ func (w *watcher) GetRegistryType() string {
|
||||
return w.RegistryType.String()
|
||||
}
|
||||
|
||||
func (w *watcher) IsReady() bool {
|
||||
func (w *watcher) watcherReady() bool {
|
||||
if w.serviceRemaind == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user