-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nsqadmin/nsqd: refactor stats querying #929
nsqadmin/nsqd: refactor stats querying #929
Conversation
1c4dc28
to
8a4ba22
Compare
50027f4
to
d0ae961
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this @andyxning, just a few minor comments.
Are there any other test additions we should make here?
internal/clusterinfo/data.go
Outdated
endpoint := fmt.Sprintf("http://%s/stats?format=json", addr) | ||
|
||
var endpoint string | ||
if len(selectedChannel) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't entirely correct, as it doesn't test for selectedTopic
, let's just adopt the code in #925 wholesale for this block:
if selectedTopic == "" {
endpoint = fmt.Sprintf("http://%s/stats?format=json", addr)
} else if selectChannel == "" {
endpoint = fmt.Sprintf("http://%s/stats?topic=%s&format=json", addr, selectedTopic)
} else {
endpoint = fmt.Sprintf("http://%s/stats?topic=%s&channel=%s&format=json", addr, selectedTopic, selectChannel)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me humbly offer my own variant here:
endpoint := fmt.Sprintf("http://%s/stats?format=json", addr)
if selectedTopic != "" {
endpoint += "&topic=" + selectedTopic
if selectedChannel != "" {
endpoint += "&channel=" + selectedChannel
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review and the more simplified and clearer refactor. @ploxiln @mreiferson
nsqd/stats.go
Outdated
for _, t := range n.topicMap { | ||
realTopics = append(realTopics, t) | ||
var realTopics []*Topic | ||
if len(topic) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but In Go, this test should just be:
if topic == "" {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
nsqd/stats.go
Outdated
} | ||
} else { | ||
realTopics = make([]*Topic, 0, 1) | ||
realTopics = append(realTopics, n.topicMap[topic]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines can be simplified to:
realTopics = []*Topic{n.topicMap[topic]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
nsqd/stats.go
Outdated
for _, c := range t.channelMap { | ||
realChannels = append(realChannels, c) | ||
var realChannels []*Channel | ||
if len(channel) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same idiomatic improvement here:
if channel == "" {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
nsqd/stats.go
Outdated
} | ||
} else { | ||
realChannels = make([]*Channel, 0, 1) | ||
realChannels = append(realChannels, t.channelMap[channel]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And same simplification here:
realChannels = []*Channel{t.channelMap[channel]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
d0ae961
to
1ab3405
Compare
@mreiferson @ploxiln Comments addressed. PTAL. |
@@ -32,7 +32,7 @@ func TestStats(t *testing.T) { | |||
identify(t, conn, nil, frameTypeResponse) | |||
sub(t, conn, topicName, "ch") | |||
|
|||
stats := nsqd.GetStats() | |||
stats := nsqd.GetStats(topicName, "ch") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's probably a good idea to expand this test a bit - put a message to one other topic and channel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. Done.
looking pretty good to me |
1ab3405
to
bb8fc4c
Compare
@ploxiln Comments addressed. PTAL. |
nsqd/stats.go
Outdated
realTopics = append(realTopics, t) | ||
} | ||
} else { | ||
realTopics = []*Topic{n.topicMap[topic]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized we're not checking if the topic exists in topicMap
, can you add that check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mreiferson Good catch! I also have enhanced the test for both of none exist topic and channel.
PTAL.
nsqd/stats.go
Outdated
realChannels = append(realChannels, c) | ||
} | ||
} else { | ||
realChannels = []*Channel{t.channelMap[channel]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, need to check if channel is in channelMap
first
1bd8e4a
to
bf589db
Compare
bf589db
to
9fe3205
Compare
@andyxning fixed up the commits, LGTM, thanks! |
As nsqd
stats
api supportsformat
,topic
andchannel
url parameters. When displaying info for a specific topic and channel, nsqadmin should query nsqdstats
api with the specifiedtopic
andchannel
instead querying all channels under the specifiedtopic
and laterly filter out the specified channel stats.Query stats on demand can reduce the time for nsqadmin api to return and will reduce the possibility that nsqadmin report timeout when to query a topic with many channels and each channel with many consumer clients.
/cc @mreiferson @ploxiln