Skip to content
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

nsqd: ability to skip ephemeral topics/channels in statsd output #1346

Merged
merged 1 commit into from
May 21, 2021
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
1 change: 1 addition & 0 deletions apps/nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func nsqdFlagSet(opts *nsqd.Options) *flag.FlagSet {
flagSet.Bool("statsd-mem-stats", opts.StatsdMemStats, "toggle sending memory and GC stats to statsd")
flagSet.String("statsd-prefix", opts.StatsdPrefix, "prefix used for keys sent to statsd (%s for host replacement)")
flagSet.Int("statsd-udp-packet-size", opts.StatsdUDPPacketSize, "the size in bytes of statsd UDP packets")
flagSet.Bool("statsd-exclude-ephemeral", opts.StatsdExcludeEphemeral, "Skip ephemeral topics and channels when sending stats to statsd")

// End to end percentile flags
e2eProcessingLatencyPercentiles := app.FloatArray{}
Expand Down
11 changes: 6 additions & 5 deletions nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ type Options struct {
MaxChannelConsumers int `flag:"max-channel-consumers"`

// statsd integration
StatsdAddress string `flag:"statsd-address"`
StatsdPrefix string `flag:"statsd-prefix"`
StatsdInterval time.Duration `flag:"statsd-interval"`
StatsdMemStats bool `flag:"statsd-mem-stats"`
StatsdUDPPacketSize int `flag:"statsd-udp-packet-size"`
StatsdAddress string `flag:"statsd-address"`
StatsdPrefix string `flag:"statsd-prefix"`
StatsdInterval time.Duration `flag:"statsd-interval"`
StatsdMemStats bool `flag:"statsd-mem-stats"`
StatsdUDPPacketSize int `flag:"statsd-udp-packet-size"`
StatsdExcludeEphemeral bool `flag:"statsd-exclude-ephemeral"`

// e2e message latency
E2EProcessingLatencyWindowTime time.Duration `flag:"e2e-processing-latency-window-time"`
Expand Down
10 changes: 10 additions & 0 deletions nsqd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"net"
"strings"
"time"

"github.com/nsqio/nsq/internal/statsd"
Expand Down Expand Up @@ -36,6 +37,7 @@ func (n *NSQD) statsdLoop() {
case <-ticker.C:
addr := n.getOpts().StatsdAddress
prefix := n.getOpts().StatsdPrefix
excludeEphemeral := n.getOpts().StatsdExcludeEphemeral
conn, err := net.DialTimeout("udp", addr, time.Second)
if err != nil {
n.logf(LOG_ERROR, "failed to create UDP socket to statsd(%s)", addr)
Expand All @@ -49,6 +51,10 @@ func (n *NSQD) statsdLoop() {

stats := n.GetStats("", "", false)
for _, topic := range stats.Topics {
if excludeEphemeral && strings.HasSuffix(topic.TopicName, "#ephemeral") {
continue
}

// try to find the topic in the last collection
lastTopic := TopicStats{}
for _, checkTopic := range lastStats.Topics {
Expand Down Expand Up @@ -80,6 +86,10 @@ func (n *NSQD) statsdLoop() {
}

for _, channel := range topic.Channels {
if excludeEphemeral && strings.HasSuffix(channel.ChannelName, "#ephemeral") {
ploxiln marked this conversation as resolved.
Show resolved Hide resolved
continue
}

// try to find the channel in the last collection
lastChannel := ChannelStats{}
for _, checkChannel := range lastTopic.Channels {
Expand Down