@@ -61,29 +61,50 @@ func Test_RepairGoTruncatedStacktraces(t *testing.T) {
6161 }
6262}
6363
64+ var goTruncatedStacktracesFixtures = []string {
65+ "testdata/gotruncatefix/heap_go_truncated_1.pb.gz" , // Cortex.
66+ "testdata/gotruncatefix/heap_go_truncated_2.pb.gz" , // Cortex.
67+ "testdata/gotruncatefix/heap_go_truncated_3.pb.gz" , // Loki. Pathological.
68+ "testdata/gotruncatefix/heap_go_truncated_4.pb.gz" , // Pyroscope.
69+ "testdata/gotruncatefix/cpu_go_truncated_1.pb.gz" , // Cloudwatch Exporter
70+ }
71+
72+ func Test_RepairGoTruncatedStacktraces_Fixtures (t * testing.T ) {
73+ for _ , path := range goTruncatedStacktracesFixtures {
74+ p , err := OpenFile (path )
75+ require .NoError (t , err , path )
76+ total := samplesTotal (p .Profile )
77+
78+ p .Profile = FixGoProfile (p .Profile )
79+ assert .Equal (t , total , samplesTotal (p .Profile ))
80+
81+ p .Normalize ()
82+ assert .Equal (t , total , samplesTotal (p .Profile ))
83+
84+ fixed , err := OpenFile (path + ".fixed" )
85+ require .NoError (t , err )
86+ assert .Equal (t , total , samplesTotal (fixed .Profile ))
87+ }
88+ }
89+
6490func Test_UpdateFixtures_RepairGoTruncatedStacktraces (t * testing.T ) {
6591 if os .Getenv ("UPDATE_FIXTURES" ) != "true" {
6692 t .Skip ()
6793 }
68- t .Helper ()
69- paths := []string {
70- "testdata/gotruncatefix/heap_go_truncated_1.pb.gz" , // Cortex.
71- "testdata/gotruncatefix/heap_go_truncated_2.pb.gz" , // Cortex.
72- "testdata/gotruncatefix/heap_go_truncated_3.pb.gz" , // Loki. Pathological.
73- "testdata/gotruncatefix/heap_go_truncated_4.pb.gz" , // Pyroscope.
74- "testdata/gotruncatefix/cpu_go_truncated_1.pb.gz" , // Cloudwatch Exporter
75- }
76- for _ , path := range paths {
77- func () {
78- p , err := OpenFile (path )
79- require .NoError (t , err , path )
80- f , err := os .Create (path + ".fixed" )
81- require .NoError (t , err , path )
82- defer f .Close ()
83- p .Profile = FixGoProfile (p .Profile )
84- RepairGoTruncatedStacktraces (p .Profile )
85- _ , err = p .WriteTo (f )
86- require .NoError (t , err , path )
87- }()
94+ for _ , path := range goTruncatedStacktracesFixtures {
95+ p , err := OpenFile (path )
96+ require .NoError (t , err , path )
97+ total := samplesTotal (p .Profile )
98+
99+ p .Profile = FixGoProfile (p .Profile )
100+ p .Normalize ()
101+ assert .Equal (t , total , samplesTotal (p .Profile ))
102+
103+ path += ".fixed"
104+ fixed , err := os .Create (path )
105+ require .NoError (t , err , path )
106+ _ , err = p .WriteTo (fixed )
107+ require .NoError (t , fixed .Close (), path )
108+ require .NoError (t , err , path )
88109 }
89110}
0 commit comments