diff --git a/statsd/fixtures.go b/fixtures/statsd.go similarity index 99% rename from statsd/fixtures.go rename to fixtures/statsd.go index 5e4170a4c..1a8ea12f7 100644 --- a/statsd/fixtures.go +++ b/fixtures/statsd.go @@ -1,4 +1,4 @@ -package statsd +package fixtures import ( "math" diff --git a/writer/fixtures.go b/writer/fixtures.go index 16334a648..62f74ac22 100644 --- a/writer/fixtures.go +++ b/writer/fixtures.go @@ -9,15 +9,15 @@ import ( "github.com/DataDog/datadog-trace-agent/fixtures" ) -// PayloadConstructedHandlerArgs encodes the arguments passed to a PayloadConstructedHandler call. -type PayloadConstructedHandlerArgs struct { +// payloadConstructedHandlerArgs encodes the arguments passed to a PayloadConstructedHandler call. +type payloadConstructedHandlerArgs struct { payload *Payload stats interface{} } -// TestEndpoint represents a mocked endpoint that replies with a configurable error and records successful and failed +// testEndpoint represents a mocked endpoint that replies with a configurable error and records successful and failed // payloads. -type TestEndpoint struct { +type testEndpoint struct { sync.RWMutex err error successPayloads []Payload @@ -26,7 +26,7 @@ type TestEndpoint struct { // Write mocks the writing of a payload to a remote endpoint, recording it and replying with the configured error (or // success in its absence). -func (e *TestEndpoint) Write(payload *Payload) error { +func (e *testEndpoint) Write(payload *Payload) error { e.Lock() defer e.Unlock() if e.err != nil { @@ -37,35 +37,35 @@ func (e *TestEndpoint) Write(payload *Payload) error { return e.err } -func (e *TestEndpoint) Error() error { +func (e *testEndpoint) Error() error { e.RLock() defer e.RUnlock() return e.err } // ErrorPayloads returns all the error payloads registered with the test endpoint. -func (e *TestEndpoint) ErrorPayloads() []Payload { +func (e *testEndpoint) ErrorPayloads() []Payload { e.RLock() defer e.RUnlock() return e.errorPayloads } // SuccessPayloads returns all the success payloads registered with the test endpoint. -func (e *TestEndpoint) SuccessPayloads() []Payload { +func (e *testEndpoint) SuccessPayloads() []Payload { e.RLock() defer e.RUnlock() return e.successPayloads } // SetError sets the passed error on the endpoint. -func (e *TestEndpoint) SetError(err error) { +func (e *testEndpoint) SetError(err error) { e.Lock() defer e.Unlock() e.err = err } -func (e *TestEndpoint) String() string { - return "TestEndpoint" +func (e *testEndpoint) String() string { + return "testEndpoint" } // RandomPayload creates a new payload instance using random data and up to 32 bytes. @@ -78,28 +78,28 @@ func RandomSizedPayload(size int) *Payload { return NewPayload(fixtures.RandomSizedBytes(size), fixtures.RandomStringMap()) } -// TestPayloadSender is a PayloadSender that is connected to a TestEndpoint, used for testing. -type TestPayloadSender struct { - testEndpoint *TestEndpoint +// testPayloadSender is a PayloadSender that is connected to a testEndpoint, used for testing. +type testPayloadSender struct { + testEndpoint *testEndpoint BasePayloadSender } -// NewTestPayloadSender creates a new instance of a TestPayloadSender. -func NewTestPayloadSender() *TestPayloadSender { - testEndpoint := &TestEndpoint{} - return &TestPayloadSender{ +// newTestPayloadSender creates a new instance of a testPayloadSender. +func newTestPayloadSender() *testPayloadSender { + testEndpoint := &testEndpoint{} + return &testPayloadSender{ testEndpoint: testEndpoint, BasePayloadSender: *NewBasePayloadSender(testEndpoint), } } // Start asynchronously starts this payload sender. -func (c *TestPayloadSender) Start() { +func (c *testPayloadSender) Start() { go c.Run() } // Run executes the core loop of this sender. -func (c *TestPayloadSender) Run() { +func (c *testPayloadSender) Run() { c.exitWG.Add(1) defer c.exitWG.Done() @@ -120,21 +120,21 @@ func (c *TestPayloadSender) Run() { } // Payloads allows access to all payloads recorded as being successfully sent by this sender. -func (c *TestPayloadSender) Payloads() []Payload { +func (c *testPayloadSender) Payloads() []Payload { return c.testEndpoint.SuccessPayloads() } -// Endpoint allows access to the underlying TestEndpoint. -func (c *TestPayloadSender) Endpoint() *TestEndpoint { +// Endpoint allows access to the underlying testEndpoint. +func (c *testPayloadSender) Endpoint() *testEndpoint { return c.testEndpoint } -func (c *TestPayloadSender) setEndpoint(endpoint Endpoint) { - c.testEndpoint = endpoint.(*TestEndpoint) +func (c *testPayloadSender) setEndpoint(endpoint Endpoint) { + c.testEndpoint = endpoint.(*testEndpoint) } -// TestPayloadSenderMonitor monitors a PayloadSender and stores all events -type TestPayloadSenderMonitor struct { +// testPayloadSenderMonitor monitors a PayloadSender and stores all events +type testPayloadSenderMonitor struct { SuccessEvents []SenderSuccessEvent FailureEvents []SenderFailureEvent RetryEvents []SenderRetryEvent @@ -145,21 +145,21 @@ type TestPayloadSenderMonitor struct { exitWG sync.WaitGroup } -// NewTestPayloadSenderMonitor creates a new TestPayloadSenderMonitor monitoring the specified sender. -func NewTestPayloadSenderMonitor(sender PayloadSender) *TestPayloadSenderMonitor { - return &TestPayloadSenderMonitor{ +// newTestPayloadSenderMonitor creates a new testPayloadSenderMonitor monitoring the specified sender. +func newTestPayloadSenderMonitor(sender PayloadSender) *testPayloadSenderMonitor { + return &testPayloadSenderMonitor{ sender: sender, exit: make(chan struct{}), } } // Start asynchronously starts this payload monitor. -func (m *TestPayloadSenderMonitor) Start() { +func (m *testPayloadSenderMonitor) Start() { go m.Run() } // Run executes the core loop of this monitor. -func (m *TestPayloadSenderMonitor) Run() { +func (m *testPayloadSenderMonitor) Run() { m.exitWG.Add(1) defer m.exitWG.Done() @@ -187,13 +187,13 @@ func (m *TestPayloadSenderMonitor) Run() { } // Stop stops this payload monitor and waits for it to stop. -func (m *TestPayloadSenderMonitor) Stop() { +func (m *testPayloadSenderMonitor) Stop() { close(m.exit) m.exitWG.Wait() } // SuccessPayloads returns a slice containing all successful payloads. -func (m *TestPayloadSenderMonitor) SuccessPayloads() []Payload { +func (m *testPayloadSenderMonitor) SuccessPayloads() []Payload { result := make([]Payload, len(m.SuccessEvents)) for i, successEvent := range m.SuccessEvents { @@ -204,7 +204,7 @@ func (m *TestPayloadSenderMonitor) SuccessPayloads() []Payload { } // FailurePayloads returns a slice containing all failed payloads. -func (m *TestPayloadSenderMonitor) FailurePayloads() []Payload { +func (m *testPayloadSenderMonitor) FailurePayloads() []Payload { result := make([]Payload, len(m.FailureEvents)) for i, successEvent := range m.FailureEvents { @@ -215,7 +215,7 @@ func (m *TestPayloadSenderMonitor) FailurePayloads() []Payload { } // RetryPayloads returns a slice containing all failed payloads. -func (m *TestPayloadSenderMonitor) RetryPayloads() []Payload { +func (m *testPayloadSenderMonitor) RetryPayloads() []Payload { result := make([]Payload, len(m.RetryEvents)) for i, successEvent := range m.RetryEvents { diff --git a/writer/payload_test.go b/writer/payload_test.go index e59ff4cef..f62a8f0cb 100644 --- a/writer/payload_test.go +++ b/writer/payload_test.go @@ -22,13 +22,13 @@ func TestQueuablePayloadSender_WorkingEndpoint(t *testing.T) { assert := assert.New(t) // Given an endpoint that doesn't fail - workingEndpoint := &TestEndpoint{} + workingEndpoint := &testEndpoint{} // And a queuable sender using that endpoint queuableSender := NewQueuablePayloadSender(workingEndpoint) // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) // When we start the sender monitor.Start() @@ -64,7 +64,7 @@ func TestQueuablePayloadSender_FlakyEndpoint(t *testing.T) { assert := assert.New(t) // Given an endpoint that initially works ok - flakyEndpoint := &TestEndpoint{} + flakyEndpoint := &testEndpoint{} // And a test backoff timer that can be triggered on-demand testBackoffTimer := fixtures.NewTestBackoffTimer() @@ -77,7 +77,7 @@ func TestQueuablePayloadSender_FlakyEndpoint(t *testing.T) { queuableSender.syncBarrier = syncBarrier // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) monitor.Start() queuableSender.Start() @@ -162,7 +162,7 @@ func TestQueuablePayloadSender_MaxQueuedPayloads(t *testing.T) { assert := assert.New(t) // Given an endpoint that continuously throws out retriable errors - flakyEndpoint := &TestEndpoint{} + flakyEndpoint := &testEndpoint{} flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand @@ -177,7 +177,7 @@ func TestQueuablePayloadSender_MaxQueuedPayloads(t *testing.T) { queuableSender.syncBarrier = syncBarrier // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) monitor.Start() queuableSender.Start() @@ -232,7 +232,7 @@ func TestQueuablePayloadSender_MaxQueuedBytes(t *testing.T) { assert := assert.New(t) // Given an endpoint that continuously throws out retriable errors - flakyEndpoint := &TestEndpoint{} + flakyEndpoint := &testEndpoint{} flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand @@ -247,7 +247,7 @@ func TestQueuablePayloadSender_MaxQueuedBytes(t *testing.T) { queuableSender.syncBarrier = syncBarrier // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) monitor.Start() queuableSender.Start() @@ -301,7 +301,7 @@ func TestQueuablePayloadSender_DropBigPayloadsOnRetry(t *testing.T) { assert := assert.New(t) // Given an endpoint that continuously throws out retriable errors - flakyEndpoint := &TestEndpoint{} + flakyEndpoint := &testEndpoint{} flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand @@ -316,7 +316,7 @@ func TestQueuablePayloadSender_DropBigPayloadsOnRetry(t *testing.T) { queuableSender.syncBarrier = syncBarrier // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) monitor.Start() queuableSender.Start() @@ -358,7 +358,7 @@ func TestQueuablePayloadSender_SendBigPayloadsIfNoRetry(t *testing.T) { assert := assert.New(t) // Given an endpoint that works - workingEndpoint := &TestEndpoint{} + workingEndpoint := &testEndpoint{} // And a test backoff timer that can be triggered on-demand testBackoffTimer := fixtures.NewTestBackoffTimer() @@ -372,7 +372,7 @@ func TestQueuablePayloadSender_SendBigPayloadsIfNoRetry(t *testing.T) { queuableSender.syncBarrier = syncBarrier // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) monitor.Start() queuableSender.Start() @@ -403,7 +403,7 @@ func TestQueuablePayloadSender_MaxAge(t *testing.T) { assert := assert.New(t) // Given an endpoint that continuously throws out retriable errors - flakyEndpoint := &TestEndpoint{} + flakyEndpoint := &testEndpoint{} flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand @@ -418,7 +418,7 @@ func TestQueuablePayloadSender_MaxAge(t *testing.T) { queuableSender.syncBarrier = syncBarrier // And a test monitor for that sender - monitor := NewTestPayloadSenderMonitor(queuableSender) + monitor := newTestPayloadSenderMonitor(queuableSender) monitor.Start() queuableSender.Start() diff --git a/writer/service_writer_test.go b/writer/service_writer_test.go index bc1a29c7d..d442e5c6a 100644 --- a/writer/service_writer_test.go +++ b/writer/service_writer_test.go @@ -11,7 +11,6 @@ import ( "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" - "github.com/DataDog/datadog-trace-agent/statsd" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/stretchr/testify/assert" ) @@ -190,15 +189,15 @@ func assertMetadata(assert *assert.Assertions, expectedHeaders map[string]string assert.Equal(expectedMetadata, servicesMetadata, "Service metadata should match expectation") } -func testServiceWriter() (*ServiceWriter, chan model.ServicesMetadata, *TestEndpoint, *statsd.TestStatsClient) { +func testServiceWriter() (*ServiceWriter, chan model.ServicesMetadata, *testEndpoint, *fixtures.TestStatsClient) { serviceChannel := make(chan model.ServicesMetadata) conf := &config.AgentConfig{ ServiceWriterConfig: writerconfig.DefaultServiceWriterConfig(), } serviceWriter := NewServiceWriter(conf, serviceChannel) - testEndpoint := &TestEndpoint{} + testEndpoint := &testEndpoint{} serviceWriter.BaseWriter.payloadSender.setEndpoint(testEndpoint) - testStatsClient := &statsd.TestStatsClient{} + testStatsClient := &fixtures.TestStatsClient{} serviceWriter.statsClient = testStatsClient return serviceWriter, serviceChannel, testEndpoint, testStatsClient diff --git a/writer/stats_writer_test.go b/writer/stats_writer_test.go index cd7ef4e9c..ecbce0554 100644 --- a/writer/stats_writer_test.go +++ b/writer/stats_writer_test.go @@ -13,7 +13,6 @@ import ( "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" - "github.com/DataDog/datadog-trace-agent/statsd" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/stretchr/testify/assert" ) @@ -200,7 +199,7 @@ func assertStatsPayload(assert *assert.Assertions, headers map[string]string, bu assert.Equal(buckets, statsPayload.Stats, "Stat buckets should match expectation") } -func testStatsWriter() (*StatsWriter, chan []model.StatsBucket, *TestEndpoint, *statsd.TestStatsClient) { +func testStatsWriter() (*StatsWriter, chan []model.StatsBucket, *testEndpoint, *fixtures.TestStatsClient) { statsChannel := make(chan []model.StatsBucket) conf := &config.AgentConfig{ HostName: testHostName, @@ -208,9 +207,9 @@ func testStatsWriter() (*StatsWriter, chan []model.StatsBucket, *TestEndpoint, * StatsWriterConfig: writerconfig.DefaultStatsWriterConfig(), } statsWriter := NewStatsWriter(conf, statsChannel) - testEndpoint := &TestEndpoint{} + testEndpoint := &testEndpoint{} statsWriter.BaseWriter.payloadSender.setEndpoint(testEndpoint) - testStatsClient := &statsd.TestStatsClient{} + testStatsClient := &fixtures.TestStatsClient{} statsWriter.statsClient = testStatsClient return statsWriter, statsChannel, testEndpoint, testStatsClient diff --git a/writer/trace_writer_test.go b/writer/trace_writer_test.go index ac7b1b298..46a9e1f36 100644 --- a/writer/trace_writer_test.go +++ b/writer/trace_writer_test.go @@ -13,7 +13,6 @@ import ( "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" - "github.com/DataDog/datadog-trace-agent/statsd" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" @@ -338,7 +337,7 @@ func assertPayloads(assert *assert.Assertions, traceWriter *TraceWriter, expecte } -func testTraceWriter() (*TraceWriter, chan *model.Trace, *TestEndpoint, *statsd.TestStatsClient) { +func testTraceWriter() (*TraceWriter, chan *model.Trace, *testEndpoint, *fixtures.TestStatsClient) { traceChannel := make(chan *model.Trace) transactionChannel := make(chan *model.Span) conf := &config.AgentConfig{ @@ -347,9 +346,9 @@ func testTraceWriter() (*TraceWriter, chan *model.Trace, *TestEndpoint, *statsd. TraceWriterConfig: writerconfig.DefaultTraceWriterConfig(), } traceWriter := NewTraceWriter(conf, traceChannel, transactionChannel) - testEndpoint := &TestEndpoint{} + testEndpoint := &testEndpoint{} traceWriter.BaseWriter.payloadSender.setEndpoint(testEndpoint) - testStatsClient := &statsd.TestStatsClient{} + testStatsClient := &fixtures.TestStatsClient{} traceWriter.statsClient = testStatsClient return traceWriter, traceChannel, testEndpoint, testStatsClient