Skip to content

Commit

Permalink
Merge pull request #33 from maier/master
Browse files Browse the repository at this point in the history
v0.0.15
  • Loading branch information
maier authored Jan 3, 2024
2 parents a81db1a + 62e4933 commit 74afc32
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# unreleased

## v0.0.15

* feat: add SubmissionTimeout option -- default 10s -- controls timing out requests to broker
* build(deps): bump github.com/google/uuid from 1.4.0 to 1.5.0
* build(deps): bump github.com/circonus-labs/go-apiclient from 0.7.23 to 0.7.24
* fix: check tests to correctly initialize broker list
* fix: GetBroker tests to work with broker_list

Expand Down
9 changes: 5 additions & 4 deletions submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ type TrapResult struct {
}

const (
compressionThreshold = 1024
traceTSFormat = "20060102_150405.000000000"
compressionThreshold = 1024
traceTSFormat = "20060102_150405.000000000"
defaultSubmissionTimeout = "10s"
)

func (tc *TrapCheck) submit(ctx context.Context, metrics bytes.Buffer) (*TrapResult, bool, error) {
Expand Down Expand Up @@ -74,7 +75,7 @@ func (tc *TrapCheck) submit(ctx context.Context, metrics bytes.Buffer) (*TrapRes
MaxIdleConns: 1,
MaxIdleConnsPerHost: 0,
},
Timeout: 60 * time.Second, // hard 60s timeout
Timeout: tc.submissionTimeout,
}
} else {
client = &http.Client{
Expand All @@ -90,7 +91,7 @@ func (tc *TrapCheck) submit(ctx context.Context, metrics bytes.Buffer) (*TrapRes
MaxIdleConns: 1,
MaxIdleConnsPerHost: 0,
},
Timeout: 60 * time.Second, // hard 60s timeout
Timeout: tc.submissionTimeout,
}
}

Expand Down
31 changes: 27 additions & 4 deletions trapcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Config struct {
Logger Logger
// SubmissionURL explicit submission url (e.g. submitting to an agent, if tls used a SubmitTLSConfig is required)
SubmissionURL string
// SubmissionTimeout sets the timeout for submitting metrics to a broker
SubmissionTimeout string
// BrokerMaxResponseTime defines the timeout in which brokers must respond when selecting
BrokerMaxResponseTime string
// TraceMetrics path to write traced metrics to (must be writable by the user running app)
Expand All @@ -61,6 +63,7 @@ type TrapCheck struct {
submissionURL string
checkSearchTags apiclient.TagType
brokerSelectTags apiclient.TagType
submissionTimeout time.Duration
brokerMaxResponseTime time.Duration
newCheckBundle bool
usingPublicCA bool
Expand Down Expand Up @@ -124,7 +127,7 @@ func New(cfg *Config) (*TrapCheck, error) {
tc.brokerMaxResponseTime = maxDur

if cfg.TraceMetrics != "" {
err := testTraceMetricsDir(cfg.TraceMetrics)
err := testTraceMetricsDir(cfg.TraceMetrics) //nolint:govet
if err != nil {
tc.Log.Warnf("trace metrics directory (%s): %s -- disabling", cfg.TraceMetrics, err)
} else {
Expand All @@ -142,7 +145,7 @@ func New(cfg *Config) (*TrapCheck, error) {

tc.submissionURL = tc.custSubmissionURL
if tc.submissionURL == "" {
if err := tc.initializeCheck(); err != nil {
if err := tc.initializeCheck(); err != nil { //nolint:govet
return nil, err
}
if surl, ok := tc.checkBundle.Config[config.SubmissionURL]; ok {
Expand All @@ -155,6 +158,16 @@ func New(cfg *Config) (*TrapCheck, error) {
tc.checkBundle = tc.checkConfig
}

sto := cfg.SubmissionTimeout
if sto == "" {
sto = defaultSubmissionTimeout
}
stdur, err := time.ParseDuration(sto)
if err != nil {
return nil, fmt.Errorf("parsing submission timeout (%s): %w", sto, err)
}
tc.submissionTimeout = stdur

if err := tc.initBrokerList(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -222,7 +235,7 @@ func NewFromCheckBundle(cfg *Config, bundle *apiclient.CheckBundle) (*TrapCheck,
tc.brokerMaxResponseTime = maxDur

if cfg.TraceMetrics != "" {
err := testTraceMetricsDir(cfg.TraceMetrics)
err := testTraceMetricsDir(cfg.TraceMetrics) //nolint:govet
if err != nil {
tc.Log.Warnf("trace metrics directory (%s): %s -- disabling", cfg.TraceMetrics, err)
} else {
Expand All @@ -243,6 +256,16 @@ func NewFromCheckBundle(cfg *Config, bundle *apiclient.CheckBundle) (*TrapCheck,

tc.submissionURL = surl

sto := cfg.SubmissionTimeout
if sto == "" {
sto = defaultSubmissionTimeout
}
stdur, err := time.ParseDuration(sto)
if err != nil {
return nil, fmt.Errorf("parsing submission timeout (%s): %w", sto, err)
}
tc.submissionTimeout = stdur

if err := tc.initBrokerList(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -314,7 +337,7 @@ func (tc *TrapCheck) IsNewCheckBundle() bool {
}

// GetCheckBundle returns the trap check bundle currently in use - can be used
// for caching checks on disk and re-using the ckeck quickly by passing
// for caching checks on disk and re-using the check quickly by passing
// the CID in via the check bundle config.
func (tc *TrapCheck) GetCheckBundle() (apiclient.CheckBundle, error) {
if tc.checkBundle == nil {
Expand Down

0 comments on commit 74afc32

Please sign in to comment.