Skip to content

Commit

Permalink
[chore] Improve empty tag value tests (#22850) (#26036)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>

InfluxDB does not allow empty tag values in line protocol. This change
adds a second test to confirm that the InfluxDB exporter does not emit
empty tag values.
    
See #21526 for the original fix to handling empty attribute values. This
PR exists because I forgot I had fixed #21474, then tried to fix #22850
and now realize that #22850 and #21474 are dupes. Live and learn.

**Link to tracking Issue:**

Closes #22850

**Testing:**

**Documentation:**
  • Loading branch information
jacobmarble authored Sep 15, 2023
1 parent 1db5684 commit cd25ada
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions exporter/influxdbexporter/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package influxdbexporter

import (
"context"
"io"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"time"
Expand All @@ -15,6 +17,8 @@ import (
"github.com/influxdata/line-protocol/v2/lineprotocol"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
)

func Test_influxHTTPWriterBatch_optimizeTags(t *testing.T) {
Expand Down Expand Up @@ -141,3 +145,44 @@ func Test_influxHTTPWriterBatch_maxPayload(t *testing.T) {
})
}
}

func Test_influxHTTPWriterBatch_EnqueuePoint_emptyTagValue(t *testing.T) {
var recordedRequest *http.Request
var recordedRequestBody []byte
noopHTTPServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if assert.Nil(t, recordedRequest) {
recordedRequest = r
recordedRequestBody, _ = io.ReadAll(r.Body)
}
}))
t.Cleanup(noopHTTPServer.Close)

nowTime := time.Unix(1000, 2000)

influxWriter, err := newInfluxHTTPWriter(
new(common.NoopLogger),
&Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: noopHTTPServer.URL,
},
},
component.TelemetrySettings{})
require.NoError(t, err)
influxWriter.httpClient = noopHTTPServer.Client()
influxWriterBatch := influxWriter.NewBatch()

err = influxWriterBatch.EnqueuePoint(
context.Background(),
"m",
map[string]string{"k": "v", "empty": ""},
map[string]interface{}{"f": int64(1)},
nowTime,
common.InfluxMetricValueTypeUntyped)
require.NoError(t, err)
err = influxWriterBatch.WriteBatch(context.Background())
require.NoError(t, err)

if assert.NotNil(t, recordedRequest) {
assert.Equal(t, "m,k=v f=1i 1000000002000", strings.TrimSpace(string(recordedRequestBody)))
}
}

0 comments on commit cd25ada

Please sign in to comment.