Add a CLI flag for cluster name and include it in /status response

This commit is contained in:
Alan Bernstein 2020-08-11 10:57:59 -05:00
parent 8fad2b92c2
commit 5705b45864
7 changed files with 36 additions and 8 deletions

10
api.go
View file

@ -1739,6 +1739,16 @@ func (api *API) State() string {
return api.cluster.State()
}
// ClusterID returns the cluster ID.
func (api *API) ClusterID() string {
return api.cluster.id
}
// ClusterName returns the cluster name.
func (api *API) ClusterName() string {
return api.cluster.Name
}
// Version returns the Pilosa version.
func (api *API) Version() string {
return strings.TrimPrefix(Version, "v")

View file

@ -208,6 +208,9 @@ type cluster struct { // nolint: maligned
// The number of replicas a partition has.
ReplicaN int
// Human-readable name of the cluster.
Name string
// Threshold for logging long-running queries
// TODO(2.0) move this out of cluster. (why is it here??)
longQueryTime time.Duration

View file

@ -47,6 +47,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) {
flags.IntVarP(&srv.Config.Cluster.ReplicaN, "cluster.replicas", "", 1, "Number of hosts each piece of data should be stored on.")
flags.StringSliceVarP(&srv.Config.Cluster.Hosts, "cluster.hosts", "", []string{}, "Comma separated list of hosts in cluster. Only used for testing.")
flags.DurationVarP((*time.Duration)(&srv.Config.Cluster.LongQueryTime), "cluster.long-query-time", "", time.Minute, "Duration that will trigger log and stat messages for slow queries.")
flags.StringVar(&srv.Config.Cluster.Name, "cluster.name", srv.Config.Cluster.Name, "Human-readable name for the cluster.")
// Translation
flags.StringVarP(&srv.Config.Translation.PrimaryURL, "translation.primary-url", "", srv.Config.Translation.PrimaryURL, "DEPRECATED: URL for primary translation node for replication.")

View file

@ -700,10 +700,12 @@ func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
return
}
status := getStatusResponse{
State: h.api.State(),
Nodes: h.api.Hosts(r.Context()),
NodeStates: h.api.HostStates(r.Context()),
LocalID: h.api.Node().ID,
State: h.api.State(),
Nodes: h.api.Hosts(r.Context()),
NodeStates: h.api.HostStates(r.Context()),
LocalID: h.api.Node().ID,
ClusterID: h.api.ClusterID(),
ClusterName: h.api.ClusterName(),
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(status); err != nil {
@ -759,10 +761,12 @@ type getSchemaResponse struct {
}
type getStatusResponse struct {
State string `json:"state"`
Nodes []*pilosa.Node `json:"nodes"`
NodeStates map[string]string `json:"nodeStates"`
LocalID string `json:"localID"`
State string `json:"state"`
Nodes []*pilosa.Node `json:"nodes"`
NodeStates map[string]string `json:"nodeStates"`
LocalID string `json:"localID"`
ClusterID string `json:"clusterID"`
ClusterName string `json:"clusterName"`
}
func hash(s string) string {

View file

@ -269,6 +269,14 @@ func OptServerClusterDisabled(disabled bool, hosts []string) ServerOption {
}
}
// OptServerClusterName sets the human-readable cluster name.
func OptServerClusterName(name string) ServerOption {
return func(s *Server) error {
s.cluster.Name = name
return nil
}
}
// OptServerSerializer is a functional option on Server
// used to set the serializer.
func OptServerSerializer(ser Serializer) ServerOption {

View file

@ -122,6 +122,7 @@ type Config struct {
Coordinator bool `toml:"coordinator"`
ReplicaN int `toml:"replicas"`
Hosts []string `toml:"hosts"`
Name string `toml:"name"`
// TODO(2.0) move this out of cluster. (why is it here??)
LongQueryTime toml.Duration `toml:"long-query-time"`
} `toml:"cluster"`

View file

@ -406,6 +406,7 @@ func (m *Command) SetupServer() error {
pilosa.OptServerGRPCURI(advertiseGRPCURI),
pilosa.OptServerInternalClient(http.NewInternalClientFromURI(uri, c)),
pilosa.OptServerClusterDisabled(m.Config.Cluster.Disabled, m.Config.Cluster.Hosts),
pilosa.OptServerClusterName(m.Config.Cluster.Name),
pilosa.OptServerSerializer(proto.Serializer{}),
pilosa.OptServerTxsrc(m.Config.Txsrc),
coordinatorOpt,