Skip to content

Commit

Permalink
better transport naming
Browse files Browse the repository at this point in the history
  • Loading branch information
endorama committed Jan 23, 2024
1 parent 6c680d5 commit 9c9a470
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions internal/loadgen/eventhandler/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func NewAPM(config Config) (i.Handler, error) {
return New(config, &APMEventCollector{})
}

// APM sends the contents of a reader to a remote APM Server.
type APM struct {
// APMTransport sends the contents of a reader to a remote APMTransport Server.
type APMTransport struct {
client *http.Client
intakeHeaders http.Header
intakeV2URL string
Expand All @@ -35,15 +35,15 @@ func NewAPMTransport(c *http.Client, srvURL, token, apiKey string, headers map[s
for name, header := range headers {
intakeHeaders.Set(name, header)
}
return &APM{
return &APMTransport{
client: c,
intakeV2URL: srvURL + `/intake/v2/events`,
intakeHeaders: intakeHeaders,
}
}

// SendEvents sends the reader contents to `/intake/v2/events` as a batch.
func (t *APM) SendEvents(ctx context.Context, r io.Reader, ignoreErrs bool) error {
func (t *APMTransport) SendEvents(ctx context.Context, r io.Reader, ignoreErrs bool) error {
req, err := http.NewRequestWithContext(ctx, "POST", t.intakeV2URL, r)
if err != nil {
return err
Expand All @@ -55,7 +55,7 @@ func (t *APM) SendEvents(ctx context.Context, r io.Reader, ignoreErrs bool) erro
return t.sendEvents(req, r, ignoreErrs)
}

func (t *APM) sendEvents(req *http.Request, r io.Reader, ignoreErrs bool) error {
func (t *APMTransport) sendEvents(req *http.Request, r io.Reader, ignoreErrs bool) error {
res, err := t.client.Do(req)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions internal/loadgen/eventhandler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestHandlerNew(t *testing.T) {
t.Run("success-matches-files", func(t *testing.T) {
h, err := New(Config{
Path: `*.ndjson`,
Transport: &APM{},
Transport: &APMTransport{},
Storage: storage,
Writer: writeAPMEvents,
}, &APMEventCollector{})
Expand All @@ -180,7 +180,7 @@ func TestHandlerNew(t *testing.T) {
t.Run("failure-matches-no-files", func(t *testing.T) {
h, err := New(Config{
Path: `go*.ndjson`,
Transport: &APM{},
Transport: &APMTransport{},
Storage: storage,
Writer: writeAPMEvents,
}, &APMEventCollector{})
Expand All @@ -190,7 +190,7 @@ func TestHandlerNew(t *testing.T) {
t.Run("failure-invalid-glob", func(t *testing.T) {
h, err := New(Config{
Path: "",
Transport: &APM{},
Transport: &APMTransport{},
Storage: storage,
Writer: writeAPMEvents,
}, &APMEventCollector{})
Expand All @@ -201,7 +201,7 @@ func TestHandlerNew(t *testing.T) {
storage := os.DirFS(filepath.Join("testdata", "intake-v3"))
h, err := New(Config{
Path: `*.ndjson`,
Transport: &APM{},
Transport: &APMTransport{},
Storage: storage,
Writer: writeAPMEvents,
}, &APMEventCollector{})
Expand Down
8 changes: 4 additions & 4 deletions internal/loadgen/eventhandler/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"github.com/elastic/apm-perf/internal/loadgen/i"
)

type OTLP struct {
type OTLPTransport struct {
client *http.Client
headers http.Header
url string
}

func (o *OTLP) SendEvents(ctx context.Context, r io.Reader, ignoreErrs bool) error {
func (o *OTLPTransport) SendEvents(ctx context.Context, r io.Reader, ignoreErrs bool) error {
req, err := http.NewRequestWithContext(ctx, "POST", o.url, r)
if err != nil {
return err
Expand All @@ -44,7 +44,7 @@ func (o *OTLP) SendEvents(ctx context.Context, r io.Reader, ignoreErrs bool) err
return nil
}

func newOTLPTransport(c *http.Client, srvURL, u, apiKey string, headers map[string]string) *OTLP {
func newOTLPTransport(c *http.Client, srvURL, u, apiKey string, headers map[string]string) *OTLPTransport {
h := make(http.Header)
h.Set("Content-Encoding", "deflate")
h.Set("Content-Type", "application/x-ndjson")
Expand All @@ -55,7 +55,7 @@ func newOTLPTransport(c *http.Client, srvURL, u, apiKey string, headers map[stri
h.Set(name, header)
}

return &OTLP{
return &OTLPTransport{
client: c,
url: srvURL + u,
headers: h,
Expand Down

0 comments on commit 9c9a470

Please sign in to comment.