Skip to content

Commit ddffe6d

Browse files
committed
Ensure location IDs get rewritten correctly
1 parent c4d02e9 commit ddffe6d

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

pkg/firedb/head.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ func (h *Head) convertSamples(ctx context.Context, r *rewriter, in []*profilev1.
217217
Labels: r.strings.rewritePprofLabels(in[pos].Label),
218218
}
219219

220+
// rewrite location ids
221+
for posLoc := range in[pos].LocationId {
222+
r.locations.rewriteUint64(&in[pos].LocationId[posLoc])
223+
}
224+
220225
// build full stack traces
221226
stacktraces[pos] = &schemav1.Stacktrace{
222227
LocationIDs: in[pos].LocationId,

pkg/firedb/head_test.go

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package firedb
33
import (
44
"compress/gzip"
55
"context"
6+
"encoding/json"
67
"io/ioutil"
78
"os"
89
"testing"
@@ -270,9 +271,13 @@ func TestSelectProfiles(t *testing.T) {
270271

271272
// todo write more robust tests.
272273
for i := int64(0); i < 4; i++ {
273-
p := newProfileBar()
274-
p.TimeNanos = int64(time.Second * time.Duration(i))
275-
err = head.Ingest(context.Background(), p, &commonv1.LabelPair{Name: "job", Value: "bar"}, &commonv1.LabelPair{Name: "__name__", Value: "memory"})
274+
pF := newProfileFoo()
275+
pB := newProfileBar()
276+
pF.TimeNanos = int64(time.Second * time.Duration(i))
277+
pB.TimeNanos = int64(time.Second * time.Duration(i))
278+
err = head.Ingest(context.Background(), pF, &commonv1.LabelPair{Name: "job", Value: "foo"}, &commonv1.LabelPair{Name: "__name__", Value: "foomemory"})
279+
require.NoError(t, err)
280+
err = head.Ingest(context.Background(), pB, &commonv1.LabelPair{Name: "job", Value: "bar"}, &commonv1.LabelPair{Name: "__name__", Value: "memory"})
276281
require.NoError(t, err)
277282
}
278283

@@ -290,7 +295,60 @@ func TestSelectProfiles(t *testing.T) {
290295
}))
291296
require.NoError(t, err)
292297
require.Equal(t, 2, len(resp.Msg.Profiles))
293-
require.Equal(t, 1, len(resp.Msg.FunctionNames))
298+
299+
// compare the first profile deep
300+
profileJSON, err := json.Marshal(&resp.Msg.Profiles[0])
301+
require.NoError(t, err)
302+
require.JSONEq(t, `{
303+
"type": {
304+
"name": "memory",
305+
"sampleType": "type",
306+
"sampleUnit": "unit",
307+
"periodType": "type",
308+
"periodUnit": "unit"
309+
},
310+
"labels": [
311+
{
312+
"name": "__name__",
313+
"value": "memory"
314+
},
315+
{
316+
"name": "__period_type__",
317+
"value": "type"
318+
},
319+
{
320+
"name": "__period_unit__",
321+
"value": "unit"
322+
},
323+
{
324+
"name": "__profile_type__",
325+
"value": "memory:type:unit:type:unit"
326+
},
327+
{
328+
"name": "__type__",
329+
"value": "type"
330+
},
331+
{
332+
"name": "__unit__",
333+
"value": "unit"
334+
},
335+
{
336+
"name": "job",
337+
"value": "bar"
338+
}
339+
],
340+
"timestamp": 1000,
341+
"stacktraces": [
342+
{
343+
"function_ids": [
344+
0
345+
],
346+
"value": 2345
347+
}
348+
]}`, string(profileJSON))
349+
350+
// ensure the func name matches
351+
require.Equal(t, []string{"func_a"}, resp.Msg.FunctionNames)
294352
}
295353

296354
func BenchmarkHeadIngestProfiles(t *testing.B) {

0 commit comments

Comments
 (0)