Skip to content

Commit

Permalink
Capnp: Use segment from existing message
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <[email protected]>
  • Loading branch information
fpetkovski committed Nov 28, 2024
1 parent 1d76335 commit 00a3a12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
15 changes: 1 addition & 14 deletions pkg/receive/writecapnp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,9 @@ func (r *RemoteWriteClient) writeWithReconnect(ctx context.Context, numReconnect
if err := r.connect(ctx); err != nil {
return nil, err
}
arena := capnp.SingleSegment(nil)
defer arena.Release()

result, release := r.writer.Write(ctx, func(params Writer_write_Params) error {
_, seg, err := capnp.NewMessage(arena)
if err != nil {
return err
}
wr, err := NewRootWriteRequest(seg)
if err != nil {
return err
}
if err := params.SetWr(wr); err != nil {
return err
}
wr, err = params.Wr()
wr, err := params.NewWr()
if err != nil {
return err
}
Expand Down
21 changes: 13 additions & 8 deletions pkg/receive/writecapnp/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package writecapnp
import (
"capnproto.org/go/capnp/v3"

"github.com/pkg/errors"

"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb/prompb"
)
Expand Down Expand Up @@ -46,7 +48,7 @@ func Build(tenant string, tsreq []prompb.TimeSeries) (WriteRequest, error) {

func BuildInto(wr WriteRequest, tenant string, tsreq []prompb.TimeSeries) error {
if err := wr.SetTenant(tenant); err != nil {
return err
return errors.Wrap(err, "set tenant")
}

series, err := wr.NewTimeSeries(int32(len(tsreq)))
Expand All @@ -59,27 +61,30 @@ func BuildInto(wr WriteRequest, tenant string, tsreq []prompb.TimeSeries) error

lblsc, err := tsc.NewLabels(int32(len(ts.Labels)))
if err != nil {
return err
return errors.Wrap(err, "new labels")
}
if err := marshalLabels(lblsc, ts.Labels, builder); err != nil {
return err
return errors.Wrap(err, "marshal labels")
}
if err := marshalSamples(tsc, ts.Samples); err != nil {
return err
return errors.Wrap(err, "marshal samples")
}
if err := marshalHistograms(tsc, ts.Histograms); err != nil {
return err
return errors.Wrap(err, "marshal histograms")
}
if err := marshalExemplars(tsc, ts.Exemplars, builder); err != nil {
return err
return errors.Wrap(err, "marshal exemplars")
}
}

symbols, err := wr.NewSymbols()
if err != nil {
return err
return errors.Wrap(err, "new symbols")
}
return marshalSymbols(builder, symbols)
if err := marshalSymbols(builder, symbols); err != nil {
return errors.Wrap(err, "marshal symbols")
}
return nil
}

func marshalSymbols(builder *symbolsBuilder, symbols Symbols) error {
Expand Down

0 comments on commit 00a3a12

Please sign in to comment.