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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,14 @@ The rate limit service generates various statistics for each configured rate lim
users both for visibility and for setting alarms. Ratelimit uses [gostats](https://github.com/lyft/gostats) as its statistics library. Please refer
to [gostats' documentation](https://godoc.org/github.com/lyft/gostats) for more information on the library.

Statistics default to using [StatsD](https://github.com/statsd/statsd) and configured via the env vars from [gostats](https://github.com/lyft/gostats).

To output statistics to stdout instead, set env var `USE_STATSD` to `false`

Configure statistics output frequency with `STATS_FLUSH_INTERVAL`, where the type is `time.Duration`, e.g. `10s` is the default value.

To disable statistics entirely, set env var `DISABLE_STATS` to `true`

Rate Limit Statistic Path:

```
Expand Down
15 changes: 11 additions & 4 deletions src/service_cmd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,21 @@ type Runner struct {

func NewRunner(s settings.Settings) Runner {
var store gostats.Store
// use statsd
if s.UseStatsd {

if s.DisableStats {
logger.Info("Stats disabled")
store = gostats.NewStore(gostats.NewNullSink(), false)
} else if s.UseStatsd {
logger.Info("Stats initialized for statsd")
store = gostats.NewStore(gostats.NewTCPStatsdSink(gostats.WithStatsdHost(s.StatsdHost), gostats.WithStatsdPort(s.StatsdPort)), false)
} else {
store = gostats.NewStore(gostats.NewNullSink(), false)
logger.Info("Stats initialized for stdout")
store = gostats.NewStore(gostats.NewLoggingSink(), false)
}

go store.Start(time.NewTicker(10 * time.Second))
logger.Infof("Stats flush interval: %s", s.StatsFlushInterval)

go store.Start(time.NewTicker(s.StatsFlushInterval))

return Runner{
statsManager: stats.NewStatManager(store, s),
Expand Down
10 changes: 6 additions & 4 deletions src/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ type Settings struct {
XdsClientBackoffJitter bool `envconfig:"XDS_CLIENT_BACKOFF_JITTER" default:"true"`

// Stats-related settings
UseStatsd bool `envconfig:"USE_STATSD" default:"true"`
StatsdHost string `envconfig:"STATSD_HOST" default:"localhost"`
StatsdPort int `envconfig:"STATSD_PORT" default:"8125"`
ExtraTags map[string]string `envconfig:"EXTRA_TAGS" default:""`
UseStatsd bool `envconfig:"USE_STATSD" default:"true"`
StatsdHost string `envconfig:"STATSD_HOST" default:"localhost"`
StatsdPort int `envconfig:"STATSD_PORT" default:"8125"`
ExtraTags map[string]string `envconfig:"EXTRA_TAGS" default:""`
StatsFlushInterval time.Duration `envconfig:"STATS_FLUSH_INTERVAL" default:"10s"`
DisableStats bool `envconfig:"DISABLE_STATS" default:"false"`

// Settings for rate limit configuration
RuntimePath string `envconfig:"RUNTIME_ROOT" default:"/srv/runtime_data/current"`
Expand Down