Description
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
tp := &testProfile{
sampleType: []testValueType{
{
typ: "samples",
unit: "count",
aggregationTemporality: pprofile.AggregationTemporalityDelta,
},
},
sample: []testSample{
{
timestamp: 42,
link: testLink{
traceID: [16]byte{0x01, 0x02},
spanID: [16]byte{0x03, 0x04},
},
value: 1,
locations: []testLocation{
{
mapping: &testMapping{
memoryStart: 0x1000,
memoryLimit: 0x2000,
fileOffset: 0x3000,
fileName: "file1",
attributes: []testAttribute{
{
key: "mapping.attribute.key",
value: "mapping.attribute.value",
},
},
hasFunctions: true,
hasFileNames: true,
hasLineNumbers: true,
hasInlineFrames: true,
},
address: 0x1000,
line: []testLine{
{
line: 1,
column: 2,
function: testFunction{
name: "func1",
systemName: "system1",
fileName: "file1",
startLine: 1,
},
},
},
isFolded: true,
attributes: []testAttribute{
{
key: "location.attribute.key",
value: "location.attribute.value",
},
},
},
},
attributes: []testAttribute{
{
key: "sample.attribute.key",
value: "sample.attribute.value",
},
},
},
},
timeNanos: 42,
durationNanos: 84,
periodType: testValueType{
typ: "cpu",
unit: "nanoseconds",
},
period: 1e9 / 20,
comment: []string{"comment1", "comment2"},
defaultSampleType: testValueType{
typ: "samples",
unit: "count",
},
profileID: [16]byte{0x05, 0x06},
droppedAttributesCount: 1,
originalPayloadFormat: "payloadFormat",
originalPayload: []byte{0x07, 0x08},
attributes: []testAttribute{
{
key: "profile.attribute.key",
value: "profile.attribute.value",
},
},
}
pp, err := td.ToPProfile()
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