Skip to content

Custom labels for native and go #407

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

Closed

Conversation

gnurizen
Copy link
Contributor

@gnurizen gnurizen commented Mar 17, 2025

Add custom labels for native processes utilizing the PolarSignals
TLS based native custom labels library:

https://github.com/polarsignals/custom-labels

Go custom labels are auto extracted from the go env pprof labels set.

Go 1.23 and 1.24 style map and slice approaches are both supported.

Label keys are 16 bytes and values are 48 bytes. Each sample can have
up to 10 labels which are stored in the Trace object adding 640 bytes.

Unit test added for go custom labels and an Rust based example for
the native custom labels is added.

Co-authored-by: umanwizard brennan@umanwizard.com

@gnurizen gnurizen force-pushed the custom-labels-upstream branch from ad9d6cc to 9a7fb3b Compare March 17, 2025 16:54
Add custom labels for native processes utilizing the PolarSignals
TLS based native custom labels library:

https://github.com/polarsignals/custom-labels

Go custom labels are auto extracted from the go env pprof labels set.

Go 1.23 and 1.24 style map and slice approaches are both supported.

Label keys are 16 bytes and values are 48 bytes.  Each sample can have
up to 10 labels which are stored in the Trace object adding 640 bytes.

Unit test added for go custom labels and an Rust based example for
the native custom labels is added.

Co-authored-by: umanwizard <brennan@umanwizard.com>
@gnurizen
Copy link
Contributor Author

I need to sort out the arm failure but this is ready for an initial review, thanks in advance!

@gnurizen gnurizen marked this pull request as ready for review March 17, 2025 18:46
@gnurizen gnurizen requested review from a team as code owners March 17, 2025 18:46
@gnurizen gnurizen force-pushed the custom-labels-upstream branch 2 times, most recently from bed5bca to 4558729 Compare March 17, 2025 21:47
@gnurizen gnurizen force-pushed the custom-labels-upstream branch from 4558729 to fd0cfcf Compare March 17, 2025 22:01
@gnurizen
Copy link
Contributor Author

Okay seems to be passing all tests and has test coverage for native and golang labels.

@jordanisaacs
Copy link

jordanisaacs commented Mar 17, 2025

This is awesome, thanks for working on it! (Closes #388). One concern for native libraries is the custom labels API uses a single thread local stack that does allocations.

The nice thing about the strobemeta API is it lets the user set up multiple TLS of different types (map/string/int). The program however has to be profiler aware and register with profiler using a ebpf map for configuration. The upside is non-allocating tag values. Data storage is just the thread local.

My takeaway is the custom labels library can be thought of as auto-discovery of a map type.

Can the two approaches be combined, auto-discovery and multiple TLS values? Would need to auto-discover the the multiple TLS locations/types.

edit: Read a bit more, into how the profiler discovers the TLS value. Allowing a config file that lets you specify TLS names+types would work. The custom label API would also have to change to let you declare your own thread locals. The tag name of non map types could be the name of the TLS.

@gnurizen
Copy link
Contributor Author

Thanks for the feedback @jordanisaacs! Curious why doing allocations is a deal breaker, our thought was that labels would be setup at the beginning of fairly long running tasks and the allocations would be minimal.

Having multiple TLS variables of different types shouldn't be too hard to add to this implementation, support for single TLS strings and ints that allowed for zero-allocation library free usage would be nice. Where does this TLS names+types config live? Maybe in the binary as a special debug elf section?

@jordanisaacs
Copy link

jordanisaacs commented Mar 17, 2025

Not a deal breaker but something I think would be really useful. One use case I can imagine is having an enum that represents the phases of a query execution. Updating the query phase is simply assigning an int instead of allocating a string.

I like the ELF idea a lot. The ELF section should be non-debug. So stripped binaries still support custom metadata. Could it just be a list of addresses of the TLS? The initial keys would just be the TLS address. Since symbolization is already done elsewhere for native libraries, symbolization would also turn addresses into their names.

@fabled fabled mentioned this pull request Mar 18, 2025
@fabled
Copy link
Contributor

fabled commented Mar 18, 2025

Would it be possible to split this to separate commits or even PRs?
E.g

  • changes to libraries
  • support for native
  • support for golang

Also, the golang interpreter needs to be coordinated. Also #408 is adding the same interpreter for different purposes with different code.

@gnurizen
Copy link
Contributor Author

Yeah I can break it up, I feel like the go stuff should be pretty uncontroversial so maybe I should structure it as a go labels PR with a follow on native labels PR? Although with all the shared code the first one will still be pretty big. Its unclear to me what "changes to libraries" means.

@gnurizen
Copy link
Contributor Author

Here's another PR with just the go custom labels:
#409

@gnurizen
Copy link
Contributor Author

I'll close this one and open another one with the native custom labels when/if the go labels one lands.

@gnurizen gnurizen closed this Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants