diff --git a/exporter/influxdbexporter/writer_test.go b/exporter/influxdbexporter/writer_test.go index f59145422891..ff64a462d5a3 100644 --- a/exporter/influxdbexporter/writer_test.go +++ b/exporter/influxdbexporter/writer_test.go @@ -5,8 +5,10 @@ package influxdbexporter import ( "context" + "io" "net/http" "net/http/httptest" + "strings" "sync" "testing" "time" @@ -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) { @@ -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))) + } +}