Skip to content

reporter: Do not generate unique dummy mappings#598

Merged
christos68k merged 2 commits intomainfrom
ck/dummy
Jul 14, 2025
Merged

reporter: Do not generate unique dummy mappings#598
christos68k merged 2 commits intomainfrom
ck/dummy

Conversation

@christos68k
Copy link
Copy Markdown
Member

@christos68k christos68k commented Jul 11, 2025

Summary

mapping_table[0] should now be the only dummy mapping. Previously, the agent generated a unique dummy mapping per frame.

Also see:

NOTE: Devfiler needs to be updated to account for dummy mappings.

@christos68k christos68k requested review from a team as code owners July 11, 2025 03:01
@christos68k christos68k marked this pull request as draft July 11, 2025 03:01
@christos68k christos68k self-assigned this Jul 11, 2025
@christos68k christos68k linked an issue Jul 11, 2025 that may be closed by this pull request
@christos68k christos68k changed the title reporter: do not generate unique dummy mappings reporter: Do not generate unique dummy mappings Jul 11, 2025
Comment thread reporter/internal/pdata/generate.go
Comment on lines 47 to +49
stringSet.Add("")
funcSet.Add(funcInfo{nameIdx: stringSet.Add(""), fileNameIdx: stringSet.Add("")})
mappingSet.Add(dummyFileID)
dic.MappingTable().AppendEmpty()
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.

@dmathieu Is there a chance that we can change pprofile.NewProfiles() in a way that the dictionary tables are already set up appropriately with default values?
Because to generate valid Profiles, this is currently done at "thousand" places and instead should be done only at a single place.

@christos68k christos68k marked this pull request as ready for review July 11, 2025 12:59
@christos68k christos68k requested a review from florianl July 11, 2025 12:59
Comment thread reporter/internal/pdata/generate.go Outdated
mappingSet.Add(dummyFileID)
dic.MappingTable().AppendEmpty()
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.

Should we do the same for the link table right in this PR?
Because the .proto says

// link_table[0] must always be set to a zero value default link,
// so that _index fields can use 0 to indicate null/unset.

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.

There are no links being set in the current code so we shouldn't explicitly add a zero value in this case as the entire field is optional as per proto3.

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.

The documentation says "must always be", that's pretty clear to me.
Also there is validator code in pdatatest that validates if a given profile is valid or not. In the future, it will consider a message invalid if the default entry is missing.
Adding the default link value won't hurt, performance or overhead wise.

Copy link
Copy Markdown
Member Author

@christos68k christos68k Jul 11, 2025

Choose a reason for hiding this comment

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

We should clarify this in the next SIG, I think we've previously discussed it when we talked about how to handle 'optional'. I don't think that the 'must always be' wording in the documentation overrides the optional nature of proto3 fields as it makes no sense to add an element to a field that shouldn't be there.

In my view, a validator would first check if the field is present and then perform checks on that field. If there are no links in the message, then a message with a missing link_table should pass validation. If there are links in the message, then the link_table should be present and obey the documented semantics.

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.

In my view, a validator would first check if the field is present and then perform checks on that field. If there are no links in the message, then a message with a missing link_table should pass validation. If there are links in the message, then the link_table should be present and obey the documented semantics.

That makes things unnecessarily complex and error-prone. Insisting on having a default value without "thinking" thus makes sense to me.

optional nature of proto3 fields

The proto doesn't use the optional keyword any more. So an optional index boils down to have a zero index value and thus requires a default table entry. For example

  // Reference to link in ProfilesDictionary.link_table. [optional]
  // It can be unset / set to 0 if no link exists, as link_table[0] is always a 'null' default value.
  int32 link_index = 5;

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.

We should clarify and not address this in this PR (which is about something else entirely).

Copy link
Copy Markdown
Contributor

@rockdaboot rockdaboot Jul 11, 2025

Choose a reason for hiding this comment

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

SGTM. Just suggested it as it would be a two-line change and the docs seemed to be clear.

@christos68k christos68k merged commit 57a2f57 into main Jul 14, 2025
27 checks passed
@christos68k christos68k deleted the ck/dummy branch July 14, 2025 14:50
@fabled
Copy link
Copy Markdown
Contributor

fabled commented Jul 19, 2025

NOTE: Devfiler needs to be updated to account for dummy mappings.

Is there PR or fix for Devfiler on this? Seems Devfiler is now defunct unless I revert this change locally.

@christos68k
Copy link
Copy Markdown
Member Author

NOTE: Devfiler needs to be updated to account for dummy mappings.

Is there PR or fix for Devfiler on this? Seems Devfiler is now defunct unless I revert this change locally.

See elastic/devfiler#36

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.

Profiler generates multiple unique dummy mappings

4 participants