Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: enhance payloads API to allow for ephemeral payloads #60997

Open
tbg opened this issue Feb 23, 2021 · 0 comments
Open

tracing: enhance payloads API to allow for ephemeral payloads #60997

tbg opened this issue Feb 23, 2021 · 0 comments
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-observability

Comments

@tbg
Copy link
Member

tbg commented Feb 23, 2021

Is your feature request related to a problem? Please describe.
Payloads, once emitted, are immutable. That means that payloads are generally emitted after something interesting happened. That "something interesting" may block for a long time; maybe forever! So it should ideally be observable as well.

At the time of writing, the best we've got is finding the open trace span, getting the goroutine ID, and looking at goroutine dumps (where hopefully the goroutine that created the span is also the one still blocking on the "something interesting").

This could be a lot more useful if there were a way to attach "ephemeral" payloads to the trace that convert to a full payload once finalized.

Describe the solution you'd like

From today:

{
  var item MyPayload
  time.Sleep(10*time.Second)
  item.Info1 = "foo"
  time.Sleep(10*time.Second)
  item.Info2 = "bar"
}
sp.LogStructured(item)

to some variation on:

item := sp.Ephemeral(&MyPayloadType{})

// Turns the item into an immutable payload of
// the span.
defer item.LogStructured()
{
  time.Sleep(10*time.Second)
  item.Do(func(inner interface{}) {
    inner.(*MyPayloadType).Info1 = "foo"
  }
  time.Sleep(10*time.Second)
  item.Do(func(inner tracing.Structured) {
    inner.(*MyPayloadType).Info2 = "foo"
  }
}

type Ephemeral struct {
  mu sync.Mutex
  wrapped Structured
}

func (e *Ephemeral) Do(f func(Structured) {
  e.mu.Lock()
  defer e.mu.Unlock()
  f(e.wrapped)
}

func (sp *Span) GetRecording(ephemeral bool) Recording {
  // If ephemeral == true, also return the ephemeral parts
  // as regular payloads (the caller agrees that it can
  // handle these). We could also wrap them in a payload
  // so that any caller not prepared to handle them would
  // ignore them?
}

Describe alternatives you've considered
There are probably better APIs than the above.

Additional context
This would definitely come in handy for contention events:

h.ev = &roachpb.ContentionEvent{
Key: s.key,
TxnMeta: *s.txn,
}
h.tBegin = timeutil.Now()

But there has also been interest in making long-running backups more observable, for which this mechanism might be useful. For example, various backup spans could hang a progress report or latest error payload off the trace. The details here are unclear.

Jira issue: CRDB-3091

Epic CRDB-20779

@tbg tbg added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Feb 23, 2021
@mwang1026 mwang1026 added T-observability-inf and removed T-kv KV Team labels Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-observability
Projects
None yet
Development

No branches or pull requests

3 participants