Skip to content

Commit

Permalink
Add prefix to sampling decision key to separate from events to improv…
Browse files Browse the repository at this point in the history
…e perf
  • Loading branch information
carsonip committed Jan 15, 2025
1 parent c35dcb9 commit ea7b481
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions x-pack/apm-server/sampling/eventstorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

const (
prefixSamplingDecision string = "!"
// NOTE(axw) these values (and their meanings) must remain stable
// over time, to avoid misinterpreting historical data.
entryMetaTraceSampled byte = 's'
Expand Down Expand Up @@ -154,7 +155,7 @@ func (rw *ReadWriter) Flush() error {
func (rw *ReadWriter) WriteTraceSampled(traceID string, sampled bool, opts WriterOpts) error {
rw.lazyInit()

key := []byte(traceID)
key := []byte(prefixSamplingDecision + traceID)
meta := entryMetaTraceUnsampled
if sampled {
meta = entryMetaTraceSampled
Expand All @@ -172,7 +173,7 @@ func (rw *ReadWriter) IsTraceSampled(traceID string) (bool, error) {
// It should minimize disk IO on miss due to
// 1. (pubsub) remote sampling decision
// 2. (hot path) sampling decision not made yet
item, closer, err := rw.batch.Get([]byte(traceID))
item, closer, err := rw.batch.Get([]byte(prefixSamplingDecision + traceID))
if err == pebble.ErrNotFound {
return false, ErrNotFound
}
Expand Down Expand Up @@ -203,7 +204,7 @@ func (rw *ReadWriter) WriteTraceEvent(traceID string, id string, event *modelpb.
func (rw *ReadWriter) writeEntry(key, data []byte) error {
rw.pendingWrites++
// FIXME: possibly change key structure, because the append is going to be expensive
if err := rw.batch.Set(key, append([]byte{entryMetaTraceEvent}, data...), pebble.NoSync); err != nil {
if err := rw.batch.Set(key, data, pebble.NoSync); err != nil {
return err
}

Expand Down Expand Up @@ -256,7 +257,7 @@ func (rw *ReadWriter) ReadTraceEvents(traceID string, out *modelpb.Batch) error
if err != nil {
return err
}
if err := rw.s.codec.DecodeEvent(data[1:], event); err != nil {
if err := rw.s.codec.DecodeEvent(data, event); err != nil {
return fmt.Errorf("codec failed to decode event: %w", err)
}
*out = append(*out, event)
Expand Down

0 comments on commit ea7b481

Please sign in to comment.