Skip to content

reporter: use tree to populate pprofile.Profiles#528

Merged
christos68k merged 2 commits intomainfrom
issue-517
Jun 18, 2025
Merged

reporter: use tree to populate pprofile.Profiles#528
christos68k merged 2 commits intomainfrom
issue-517

Conversation

@florianl
Copy link
Copy Markdown
Member

Fixes #517

Comment thread reporter/internal/pdata/generate.go Outdated
Comment thread reporter/internal/pdata/generate.go
Comment thread reporter/internal/pdata/generate.go

// TraceEventsTree stores samples and their related metadata in a tree-like
// structure optimized for the OTel Profiling protocol representation.
type TraceEventsTree map[ContainerID]map[libpf.Origin]KeyToEventMapping
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TraceEventsTree is very generic.
Since it's a grouping by container, maybe name it more specific like TraceEventsByContainer or similar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard and suggestions are welcome.
I do think, TraceEventsByContainer is not the best name, as first level of the nested maps, maps ContainerID to libpf.Origin. From TraceEventsByContainer I would expect to get a faster/direct access to a trace event, once I have a container ID.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea is to have a dedicated type for map[libpf.Origin]KeyToEventMapping. That should make it easier to find a better name for TraceEventsTree.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These indirections in namings will make the code less readable and harder to follow. In particular if every nested level gets their own type name.
It does make sense to use dedicated subnames for some part of nested maps, if these parts are used outside of the scope of the tree. But I think this is not the case here.

}

// mkProfileID creates a random profile ID.
func mkProfileID() []byte {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped this function already in compliance with open-telemetry/opentelemetry-proto#665.

@florianl florianl marked this pull request as ready for review June 16, 2025 15:26
@florianl florianl requested review from a team as code owners June 16, 2025 15:26
// Do not append empty profiles, if there
// is not profiling data for this origin.

for containerID, originToEvents := range tree {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably aggravate the behavior reported in #534, should it be looked at before this PR is merged?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should first review and merge this PR, as #534 and #515 depend on it in the sense that they'd probably need to be reworked otherwise.

Copy link
Copy Markdown
Member

@christos68k christos68k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do another pass

Comment thread collector/internal/controller.go Outdated
// Do not append empty profiles, if there
// is not profiling data for this origin.

for containerID, originToEvents := range tree {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should first review and merge this PR, as #534 and #515 depend on it in the sense that they'd probably need to be reworked otherwise.

Comment thread main.go
intervals := times.New(cfg.ReporterInterval,
cfg.MonitorInterval, cfg.ProbabilisticInterval)

kernelVersion, err := helpers.GetKernelVersion()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the plan for these (and hostID) ?

Copy link
Copy Markdown
Member Author

@florianl florianl Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like for the additional k8s attributes, the recommended way is to use OTel processors to enrich the data. Here is an example to enrich ResourceProfile with information like host.id:

processors:
  resourcedetection:
    detectors: [ system ]
    system:
      hostname_sources: [ "os" ]
      resource_attributes:
        host.id:
          enabled: true
        host.name:
          enabled: true

I'm well aware of discussions like open-telemetry/semantic-conventions#581. Dropping here the costum host.id and using OTel processors to gather it, aligns with OTel and simplifies correlation.

Comment thread reporter/internal/pdata/generate.go
florianl added 2 commits June 18, 2025 18:10
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
@florianl
Copy link
Copy Markdown
Member Author

I had to force push to the branch in order to resolve merge conflicts (in go.sum) with current main.

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.

reporter: proper handling of ResourceProfile

4 participants