-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Simplify creating test data for profiles support #12554
Simplify creating test data for profiles support #12554
Comments
@atoulme Do you mind to assign the issue to me? I already have code locally. |
This has been moved to collector core. However, I'm not sure that's appropriate. The intent for these helpers it very similar to what telemetrygen does, as in generate fake data that can be used to test plugins that manipulate profiling data. So I think this should be moved back to the contrib repository, as this is not in the pdata area. |
) Fixes open-telemetry/opentelemetry-collector#12554 Currently, it is pretty tedious and error-prone to generate valid test profiles. This PR adds Go structs and transform functions for profiles types that allow creating valid test cases in a human readable way. It also takes care for some semantics that make a profile valid, for example that the first entry in the string table is the empty string. Here is an example from `profiles_test.go` **Before (this produces an invalid profile, btw)** ``` p := pprofile.NewProfiles() rl := p.ResourceProfiles().AppendEmpty() rl.Resource().Attributes().PutStr("key1", "value1") l := rl.ScopeProfiles().AppendEmpty().Profiles().AppendEmpty() attr := l.AttributeTable().AppendEmpty() attr.SetKey("scope-attr1") attr.Value().SetStr("value1") l.AttributeIndices().Append(0) l.SetProfileID(pprofile.NewProfileIDEmpty()) rl2 := p.ResourceProfiles().AppendEmpty() rl2.Resource().Attributes().PutStr("key2", "value2") l2 := rl2.ScopeProfiles().AppendEmpty().Profiles().AppendEmpty() attr = l2.AttributeTable().AppendEmpty() attr.SetKey("scope-attr2") attr.Value().SetStr("value2") l2.AttributeIndices().Append(0) l2.SetProfileID(pprofile.NewProfileIDEmpty()) return p ``` **After** ``` p := basicProfiles() p.ResourceProfiles = append(p.ResourceProfiles, ResourceProfile{ Resource: Resource{ Attributes: []Attribute{{"key2", "value2"}}, }, ScopeProfiles: []ScopeProfile{ { Profile: []Profile{ { Attributes: []Attribute{{"scope-attr2", "value2"}}, }, }, }, }, }) return p.Transform() ``` where `basicProfiles()` is a helper function that creates a basic test `Profiles`. Planned a follow-up PR with a validator for profiles (working locally already).
Component(s)
No response
Is your feature request related to a problem? Please describe.
Creating instances of pprofile.Profile for testing profiles related code is currently tedious and unnecessary hard to read. Example
Too many details of the protobuf definition are exposed and expected to be known to the writers of tests that involve profiles.
Every component that needs to create
pprofile.Profile
items to test with would benefit.Describe the solution you'd like
We could use Go types for the definition of test cases without exposing protocol internals (for example, how de-duplication of items is done), and a transformation function that transforms the test case into
pprofile.Profile
.Example
testcase
Describe alternatives you've considered
JSON definition: too error-prone, needs additional dependencies
Pre-recorded protobuf files: Requires extra amount of work, can't easily define corner-cases
Additional context
No response
The text was updated successfully, but these errors were encountered: