Skip to content
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
11 changes: 11 additions & 0 deletions pkg/collector/api/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ type clusterMember struct {
LockedTargets []string `json:"locked-targets,omitempty"`
}

func (s *Server) requireClustering(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if s.locker == nil {
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(APIErrors{Errors: []string{"clustering is not enabled"}})
return
}
next.ServeHTTP(w, r)
})
}

func (s *Server) handleClusteringGet(w http.ResponseWriter, r *http.Request) {
// clusteringResponse
clusteringCfg, ok, err := s.store.Config.Get("clustering", "clustering")
Expand Down
16 changes: 9 additions & 7 deletions pkg/collector/api/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ func (s *Server) adminRoutes(r *mux.Router) {
}

func (s *Server) clusterRoutes(r *mux.Router) {
r.HandleFunc("/cluster", s.handleClusteringGet).Methods(http.MethodGet)
r.HandleFunc("/cluster/rebalance", s.handleClusterRebalance).Methods(http.MethodPost)
r.HandleFunc("/cluster/leader", s.handleClusteringLeaderGet).Methods(http.MethodGet)
r.HandleFunc("/cluster/leader", s.handleClusteringLeaderDelete).Methods(http.MethodDelete)
r.HandleFunc("/cluster/members", s.handleClusteringMembersGet).Methods(http.MethodGet)
r.HandleFunc("/cluster/members/{id}/drain", s.handleClusteringDrainInstance).Methods(http.MethodPost)
r.HandleFunc("/cluster/move", s.handleClusterMove).Methods(http.MethodPost) // TODO: implement move target
cluster := r.PathPrefix("/cluster").Subrouter()
cluster.Use(s.requireClustering)
cluster.HandleFunc("", s.handleClusteringGet).Methods(http.MethodGet)
cluster.HandleFunc("/rebalance", s.handleClusterRebalance).Methods(http.MethodPost)
cluster.HandleFunc("/leader", s.handleClusteringLeaderGet).Methods(http.MethodGet)
cluster.HandleFunc("/leader", s.handleClusteringLeaderDelete).Methods(http.MethodDelete)
cluster.HandleFunc("/members", s.handleClusteringMembersGet).Methods(http.MethodGet)
cluster.HandleFunc("/members/{id}/drain", s.handleClusteringDrainInstance).Methods(http.MethodPost)
cluster.HandleFunc("/move", s.handleClusterMove).Methods(http.MethodPost)
}

func (s *Server) configRoutes(r *mux.Router) {
Expand Down
Loading