Skip to content

Commit

Permalink
metrics/circonus: Adding support for sending to a local circonus agent
Browse files Browse the repository at this point in the history
There are times that we want to send metrics to a local circonus agent
rather than across the wire to the Circonus API. This is now supported

You either need to supply Circonus APIKey or Circonus SubmissionURL and
the circonus go-metrics library will choose as expected

This follows the same configuration options as that of Vault, Nomad & Consul
  • Loading branch information
stack72 committed Nov 20, 2018
1 parent 02a2b1c commit e248942
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
11 changes: 6 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ type Runtime struct {
}

type Circonus struct {
APIKey string
APIApp string
APIURL string
CheckID string
BrokerID string
APIKey string
APIApp string
APIURL string
CheckID string
BrokerID string
SubmissionURL string
}

type Log struct {
Expand Down
1 change: 1 addition & 0 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
f.StringVar(&cfg.Metrics.Circonus.APIURL, "metrics.circonus.apiurl", defaultConfig.Metrics.Circonus.APIURL, "Circonus API URL")
f.StringVar(&cfg.Metrics.Circonus.BrokerID, "metrics.circonus.brokerid", defaultConfig.Metrics.Circonus.BrokerID, "Circonus Broker ID")
f.StringVar(&cfg.Metrics.Circonus.CheckID, "metrics.circonus.checkid", defaultConfig.Metrics.Circonus.CheckID, "Circonus Check ID")
f.StringVar(&cfg.Metrics.Circonus.SubmissionURL, "metrics.circonus.submissionurl", defaultConfig.Metrics.Circonus.SubmissionURL, "Circonus Check SubmissionURL")
f.StringVar(&cfg.Registry.Backend, "registry.backend", defaultConfig.Registry.Backend, "registry backend")
f.DurationVar(&cfg.Registry.Timeout, "registry.timeout", defaultConfig.Registry.Timeout, "timeout for registry to become available")
f.DurationVar(&cfg.Registry.Retry, "registry.retry", defaultConfig.Registry.Retry, "retry interval during startup")
Expand Down
7 changes: 7 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,13 @@ func TestLoad(t *testing.T) {
return cfg
},
},
{
args: []string{"-metrics.circonus.submissionurl", "value"},
cfg: func(cfg *Config) *Config {
cfg.Metrics.Circonus.SubmissionURL = "value"
return cfg
},
},
{
args: []string{"-runtime.gogc", "555"},
cfg: func(cfg *Config) *Config {
Expand Down
5 changes: 3 additions & 2 deletions metrics/circonus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func circonusRegistry(prefix string, circ config.Circonus, interval time.Duratio
var initError error

once.Do(func() {
if circ.APIKey == "" {
initError = errors.New("metrics: Circonus API token key")
if circ.APIKey == "" && circ.SubmissionURL == "" {
initError = errors.New("metrics: Circonus API token key or SubmissionURL")
return
}

Expand All @@ -41,6 +41,7 @@ func circonusRegistry(prefix string, circ config.Circonus, interval time.Duratio

cfg := &cgm.Config{}

cfg.CheckManager.Check.SubmissionURL = circ.SubmissionURL
cfg.CheckManager.API.TokenKey = circ.APIKey
cfg.CheckManager.API.TokenApp = circ.APIApp
cfg.CheckManager.API.URL = circ.APIURL
Expand Down
15 changes: 8 additions & 7 deletions metrics/circonus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ func TestTimer(t *testing.T) {
func TestAll(t *testing.T) {
start := time.Now()

if os.Getenv("CIRCONUS_API_TOKEN") == "" {
t.Skip("skipping test; $CIRCONUS_API_TOKEN not set")
if os.Getenv("CIRCONUS_API_TOKEN") == "" && os.Getenv("CIRCONUS_SUBMISSION_URL") == "" {
t.Skip("skipping test; $CIRCONUS_API_TOKEN or $CIRCONUS_SUBMISSION_URL not set")
}

t.Log("Testing cgm functionality -- this *will* create/use a check")

cfg := config.Circonus{
APIKey: os.Getenv("CIRCONUS_API_TOKEN"),
APIApp: os.Getenv("CIRCONUS_API_APP"),
APIURL: os.Getenv("CIRCONUS_API_URL"),
CheckID: os.Getenv("CIRCONUS_CHECK_ID"),
BrokerID: os.Getenv("CIRCONUS_BROKER_ID"),
SubmissionURL: os.Getenv("CIRCONUS_SUBMISSION_URL"),
APIKey: os.Getenv("CIRCONUS_API_TOKEN"),
APIApp: os.Getenv("CIRCONUS_API_APP"),
APIURL: os.Getenv("CIRCONUS_API_URL"),
CheckID: os.Getenv("CIRCONUS_CHECK_ID"),
BrokerID: os.Getenv("CIRCONUS_BROKER_ID"),
}

interval, err := time.ParseDuration("60s")
Expand Down

0 comments on commit e248942

Please sign in to comment.