Skip to content

Conversation

jhalliday
Copy link
Contributor

Adds a builder to map raw observations to SampleData objects suitable for serialization to Sample messages

@jhalliday jhalliday requested a review from a team as a code owner October 6, 2025 10:18
Copy link

codecov bot commented Oct 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.16%. Comparing base (a3b635d) to head (132ac82).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7727   +/-   ##
=========================================
  Coverage     90.16%   90.16%           
  Complexity     7190     7190           
=========================================
  Files           814      814           
  Lines         21702    21702           
  Branches       2125     2125           
=========================================
  Hits          19568    19568           
  Misses         1467     1467           
  Partials        667      667           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

* <p>Note that, whilst not enforced by the API, it is required that all observations in a
* collection share the same 'shape'. That is, they have either a value without timestamp, a
* timestamp without value, or both timestamp and value. Thus each array (values, timestamps) in
* the collection is either zero length, or the same length as the other.
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be simple enough to enforce in this method, right? Would it be worth doing, and rejecting observations that aren't conformant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's a problem in practice, as the data isn't hand crafted, it's from e.g. JFR which should be generating uniform structures already. However, I may add checks once the spec is settled - right now we're still debating how to handle non-timestamped values see here, here and here

public SampleCompositionKey(int stackIndex, List<Integer> attributeIndices, int linkIndex) {
this.stackIndex = stackIndex;
List<Integer> tmp = new ArrayList<>(attributeIndices);
Collections.sort(tmp);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any restrictions on duplicate values in the indices here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the spec level, no. Realistically the user level API will probably be Attributes which has Set semantics. I expect the building flow will be passing an Attributes to the dictionary to get back the List, rather than hand crafting the list, but here, as with e.g. the dictionary not enforcing referential integrity, it is possible to construct bad pointers if you try.
It's trickier than it looks to fully validate input here, as merely checking for duplicate Integers isn't sufficient to check for duplicate keys, because the underlying dictionary entries deliberately use the whole key+value+type attribute tuple, not just the key, so you have to dereference the pointers to extract the key, which you can't do without a handle on the dictionary. Likewise the stackIndex and linkIndex can't be range checked without the dictionary.
I'm not adverse to putting more safeguards in, but the current design philosophy leans more towards flexibility for users who know what they are doing, as it's focussed on use by a small set of profiler libraries than than a wide audience of application developers that something like the metrics API has. There is some help baked in, such as the sort operation here to enforce the right equality semantics, but I'm not attempting to bullet proof it.

@jhalliday
Copy link
Contributor Author

@jkwatson are there specific code changes you would like here, or shall I resolve these so it can be merged?

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.

2 participants