Skip to content

Commit

Permalink
Revert "Export spans to hec (#359)" (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigrannajaryan committed Jun 30, 2020
1 parent 625973a commit 891b1bc
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 617 deletions.
67 changes: 1 addition & 66 deletions exporter/splunkhecexporter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ func (c *client) pushMetricsData(
if err != nil {
return exporterhelper.NumTimeSeries(md), consumererror.Permanent(err)
}
if len(splunkDataPoints) == 0 {
return numDroppedTimeseries, nil
}

body, compressed, err := encodeBody(&c.zippers, splunkDataPoints, c.config.DisableCompression)
if err != nil {
return exporterhelper.NumTimeSeries(md), consumererror.Permanent(err)
}

// TODO the client sends synchronously data as of now. It would make more sense to buffer data coming in, and send batches as supported by Splunk. To batch effectively, a ring buffer approach would work well - based on time and number of messages queued.
req, err := http.NewRequest("POST", c.url.String(), body)
if err != nil {
return exporterhelper.NumTimeSeries(md), consumererror.Permanent(err)
Expand Down Expand Up @@ -96,69 +94,6 @@ func (c *client) pushMetricsData(
return numDroppedTimeseries, nil
}

func (c *client) pushTraceData(
ctx context.Context,
td consumerdata.TraceData,
) (droppedSpans int, err error) {
c.wg.Add(1)
defer c.wg.Done()

splunkEvents, numDroppedSpans := traceDataToSplunk(c.logger, td, c.config)
if len(splunkEvents) == 0 {
return numDroppedSpans, nil
}

body, compressed, err := encodeBodyEvents(&c.zippers, splunkEvents, c.config.DisableCompression)
if err != nil {
return len(td.Spans), consumererror.Permanent(err)
}

req, err := http.NewRequest("POST", c.url.String(), body)
if err != nil {
return len(td.Spans), consumererror.Permanent(err)
}

for k, v := range c.headers {
req.Header.Set(k, v)
}

if compressed {
req.Header.Set("Content-Encoding", "gzip")
}

resp, err := c.client.Do(req)
if err != nil {
return len(td.Spans), err
}

io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()

// Splunk accepts all 2XX codes.
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
err = fmt.Errorf(
"HTTP %d %q",
resp.StatusCode,
http.StatusText(resp.StatusCode))
return len(td.Spans), err
}

return numDroppedSpans, nil
}

func encodeBodyEvents(zippers *sync.Pool, evs []*splunkEvent, disableCompression bool) (bodyReader io.Reader, compressed bool, err error) {
buf := new(bytes.Buffer)
encoder := json.NewEncoder(buf)
for _, e := range evs {
err := encoder.Encode(e)
if err != nil {
return nil, false, err
}
buf.WriteString("\r\n\r\n")
}
return getReader(zippers, buf, disableCompression)
}

func encodeBody(zippers *sync.Pool, dps []*splunkMetric, disableCompression bool) (bodyReader io.Reader, compressed bool, err error) {
buf := new(bytes.Buffer)
encoder := json.NewEncoder(buf)
Expand Down
306 changes: 0 additions & 306 deletions exporter/splunkhecexporter/client_test.go

This file was deleted.

Loading

0 comments on commit 891b1bc

Please sign in to comment.