Skip to content

Commit

Permalink
Log warn for empty batch instead of error (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored Dec 26, 2023
1 parent 6e42eb5 commit d3671df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
9 changes: 4 additions & 5 deletions exporter/clickhousemetricsexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/SigNoz/signoz-otel-collector/usage"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -316,10 +315,10 @@ func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti
prwe.mux.Unlock()
var errs []error
// Calls the helper function to convert and batch the TsMap to the desired format
requests, err := batchTimeSeries(tsMap, maxBatchByteSize)
if err != nil {
errs = append(errs, consumererror.NewPermanent(err))
return errs
requests := batchTimeSeries(tsMap, maxBatchByteSize)
if requests == nil {
prwe.logger.Warn("empty batch, skipping")
return nil
}

input := make(chan *prompb.WriteRequest, len(requests))
Expand Down
7 changes: 3 additions & 4 deletions exporter/clickhousemetricsexporter/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package clickhousemetricsexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter"

import (
"errors"
"log"
"math"
"sort"
Expand Down Expand Up @@ -249,9 +248,9 @@ func getPromMetricName(metric pmetric.Metric, ns string) string {
}

// batchTimeSeries splits series into multiple batch write requests.
func batchTimeSeries(tsMap map[string]*prompb.TimeSeries, maxBatchByteSize int) ([]*prompb.WriteRequest, error) {
func batchTimeSeries(tsMap map[string]*prompb.TimeSeries, maxBatchByteSize int) []*prompb.WriteRequest {
if len(tsMap) == 0 {
return nil, errors.New("invalid tsMap: cannot be empty map")
return nil
}

var requests []*prompb.WriteRequest
Expand All @@ -278,7 +277,7 @@ func batchTimeSeries(tsMap map[string]*prompb.TimeSeries, maxBatchByteSize int)
requests = append(requests, wrapped)
}

return requests, nil
return requests
}

// convertTimeStamp converts OTLP timestamp in ns to timestamp in ms
Expand Down
13 changes: 2 additions & 11 deletions exporter/clickhousemetricsexporter/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,39 +340,30 @@ func Test_batchTimeSeries(t *testing.T) {
tsMap map[string]*prompb.TimeSeries
maxBatchByteSize int
numExpectedRequests int
returnErr bool
}{
{
"no_timeseries",
tsMap1,
100,
-1,
true,
0,
},
{
"normal_case",
tsMap2,
300,
1,
false,
},
{
"two_requests",
tsMap3,
300,
2,
false,
},
}
// run tests
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
requests, err := batchTimeSeries(tt.tsMap, tt.maxBatchByteSize)
if tt.returnErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
requests := batchTimeSeries(tt.tsMap, tt.maxBatchByteSize)
assert.Equal(t, tt.numExpectedRequests, len(requests))
})
}
Expand Down

0 comments on commit d3671df

Please sign in to comment.