mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Incorporating suggestions and fixes
Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
@@ -833,7 +833,6 @@ func (s *Server) leafNodeConnected(sub *subscription, _ *client, subject, reply
|
||||
}
|
||||
|
||||
// Common filter options for system requests STATSZ VARZ SUBSZ CONNZ ROUTEZ GATEWAYZ LEAFZ
|
||||
// These options are
|
||||
type EventFilterOptions struct {
|
||||
Name string `json:"server_name,omitempty"` // filter by server name
|
||||
Cluster string `json:"cluster,omitempty"` // filter by cluster name
|
||||
@@ -886,9 +885,6 @@ type LeafzEventOptions struct {
|
||||
// returns true if the request does NOT apply to this server and can be ignored.
|
||||
// DO NOT hold the server lock when
|
||||
func (s *Server) filterRequest(fOpts *EventFilterOptions) bool {
|
||||
if fOpts == nil {
|
||||
return false
|
||||
}
|
||||
if fOpts.Name != "" && !strings.Contains(s.info.Name, fOpts.Name) {
|
||||
return true
|
||||
}
|
||||
@@ -912,18 +908,19 @@ func (s *Server) statszReq(sub *subscription, _ *client, subject, reply string,
|
||||
return
|
||||
}
|
||||
opts := StatszEventOptions{}
|
||||
if len(msg) == 0 {
|
||||
} else if err := json.Unmarshal(msg, &opts); err != nil {
|
||||
server := &ServerInfo{}
|
||||
response := map[string]interface{}{"server": server}
|
||||
response["error"] = map[string]interface{}{
|
||||
"code": http.StatusBadRequest,
|
||||
"description": err.Error(),
|
||||
if len(msg) != 0 {
|
||||
if err := json.Unmarshal(msg, &opts); err != nil {
|
||||
server := &ServerInfo{}
|
||||
response := map[string]interface{}{"server": server}
|
||||
response["error"] = map[string]interface{}{
|
||||
"code": http.StatusBadRequest,
|
||||
"description": err.Error(),
|
||||
}
|
||||
s.sendInternalMsgLocked(reply, _EMPTY_, server, response)
|
||||
return
|
||||
} else if ignore := s.filterRequest(&opts.EventFilterOptions); ignore {
|
||||
return
|
||||
}
|
||||
s.sendInternalMsgLocked(reply, _EMPTY_, server, response)
|
||||
return
|
||||
} else if ignore := s.filterRequest(&opts.EventFilterOptions); ignore {
|
||||
return
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.sendStatsz(reply)
|
||||
|
||||
@@ -1564,8 +1564,8 @@ func TestServerEventsPingStatsZ(t *testing.T) {
|
||||
strRequestTbl := []string{
|
||||
`{"cluster":"TEST"}`,
|
||||
`{"cluster":"CLUSTER"}`,
|
||||
`{"server-name":"SRV"}`,
|
||||
`{"server-name":"_"}`,
|
||||
`{"server_name":"SRV"}`,
|
||||
`{"server_name":"_"}`,
|
||||
fmt.Sprintf(`{"host":"%s"}`, optsB.Host),
|
||||
fmt.Sprintf(`{"host":"%s", "cluster":"CLUSTER", "name":"SRV"}`, optsB.Host),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user