|
1 | 1 | package pprofsplit
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
| 5 | + "math/rand" |
4 | 6 | "testing"
|
5 | 7 |
|
6 | 8 | "github.com/prometheus/common/model"
|
@@ -350,22 +352,72 @@ func Test_VisitSampleSeries(t *testing.T) {
|
350 | 352 | },
|
351 | 353 | },
|
352 | 354 | },
|
| 355 | + { |
| 356 | + description: "does not drop samples when a label is dropped", |
| 357 | + rules: []*relabel.Config{ |
| 358 | + { |
| 359 | + Action: relabel.LabelDrop, |
| 360 | + Regex: relabel.MustNewRegexp("^label_to_drop$"), |
| 361 | + }, |
| 362 | + }, |
| 363 | + labels: []*typesv1.LabelPair{}, |
| 364 | + profile: &profilev1.Profile{ |
| 365 | + StringTable: []string{"", "label_to_drop", "value_1", "value_2"}, |
| 366 | + Sample: []*profilev1.Sample{ |
| 367 | + { |
| 368 | + LocationId: []uint64{1, 2}, |
| 369 | + Value: []int64{2}, |
| 370 | + Label: []*profilev1.Label{{Key: 1, Str: 2}}, |
| 371 | + }, |
| 372 | + { |
| 373 | + LocationId: []uint64{1, 3}, |
| 374 | + Value: []int64{2}, |
| 375 | + Label: []*profilev1.Label{{Key: 1, Str: 2}}, |
| 376 | + }, |
| 377 | + { |
| 378 | + LocationId: []uint64{1, 3}, |
| 379 | + Value: []int64{2}, |
| 380 | + Label: []*profilev1.Label{{Key: 1, Str: 3}}, // will get merged with the previous one |
| 381 | + }, |
| 382 | + { |
| 383 | + LocationId: []uint64{1, 4}, |
| 384 | + Value: []int64{2}, |
| 385 | + Label: []*profilev1.Label{{Key: 1, Str: 3}}, |
| 386 | + }, |
| 387 | + }, |
| 388 | + }, |
| 389 | + expectProfilesDropped: 0, |
| 390 | + expectBytesDropped: 0, |
| 391 | + expected: []sampleSeries{ |
| 392 | + { |
| 393 | + labels: []*typesv1.LabelPair{}, |
| 394 | + samples: []*profilev1.Sample{ |
| 395 | + { |
| 396 | + LocationId: []uint64{1, 2}, |
| 397 | + Label: []*profilev1.Label{}, |
| 398 | + Value: []int64{2}, |
| 399 | + }, |
| 400 | + { |
| 401 | + LocationId: []uint64{1, 3}, |
| 402 | + Label: []*profilev1.Label{}, |
| 403 | + Value: []int64{4}, |
| 404 | + }, |
| 405 | + { |
| 406 | + LocationId: []uint64{1, 4}, |
| 407 | + Label: []*profilev1.Label{}, |
| 408 | + Value: []int64{2}, |
| 409 | + }, |
| 410 | + }, |
| 411 | + }, |
| 412 | + }, |
| 413 | + }, |
353 | 414 | {
|
354 | 415 | description: "ensure only samples of same stacktraces get grouped",
|
355 | 416 | labels: []*typesv1.LabelPair{
|
356 | 417 | {Name: "__name__", Value: "profile"},
|
357 | 418 | },
|
358 | 419 | profile: &profilev1.Profile{
|
359 | 420 | StringTable: []string{"", "foo", "bar", "binary", "span_id", "aaaabbbbccccdddd", "__name__"},
|
360 |
| - Location: []*profilev1.Location{ |
361 |
| - {Id: 1, MappingId: 1, Line: []*profilev1.Line{{FunctionId: 1}}}, |
362 |
| - {Id: 2, MappingId: 1, Line: []*profilev1.Line{{FunctionId: 2}}}, |
363 |
| - }, |
364 |
| - Mapping: []*profilev1.Mapping{{}, {Id: 1, Filename: 3}}, |
365 |
| - Function: []*profilev1.Function{ |
366 |
| - {Id: 1, Name: 1}, |
367 |
| - {Id: 2, Name: 2}, |
368 |
| - }, |
369 | 421 | Sample: []*profilev1.Sample{
|
370 | 422 | {
|
371 | 423 | LocationId: []uint64{1, 2},
|
@@ -456,3 +508,51 @@ func Test_VisitSampleSeries(t *testing.T) {
|
456 | 508 | })
|
457 | 509 | }
|
458 | 510 | }
|
| 511 | + |
| 512 | +func Benchmark_VisitSampleSeries_HighCardinality(b *testing.B) { |
| 513 | + defaultRelabelConfigs := validation.MockDefaultOverrides().IngestionRelabelingRules("") |
| 514 | + defaultRelabelConfigs = append(defaultRelabelConfigs, &relabel.Config{ |
| 515 | + Action: relabel.LabelDrop, |
| 516 | + Regex: relabel.MustNewRegexp("^high_cardinality_label$"), |
| 517 | + }) |
| 518 | + |
| 519 | + stringTable := []string{"", "foo", "bar", "binary", "span_id", "aaaabbbbccccdddd", "high_cardinality_label"} |
| 520 | + highCardinalityOffset := int64(len(stringTable)) |
| 521 | + for i := 0; i < 10000; i++ { |
| 522 | + stringTable = append(stringTable, fmt.Sprintf("value_%d", i)) |
| 523 | + } |
| 524 | + |
| 525 | + profile := &profilev1.Profile{ |
| 526 | + StringTable: stringTable, |
| 527 | + Location: []*profilev1.Location{{Id: 1, MappingId: 1, Line: []*profilev1.Line{{FunctionId: 1}}}}, |
| 528 | + Mapping: []*profilev1.Mapping{{}, {Id: 1, Filename: 3}}, |
| 529 | + Function: []*profilev1.Function{{Id: 1, Name: 1}}, |
| 530 | + } |
| 531 | + |
| 532 | + for i := 0; i < 30000; i++ { |
| 533 | + labelValue := highCardinalityOffset + int64(i/10) |
| 534 | + if rand.Float64() < 0.3 { |
| 535 | + labelValue = highCardinalityOffset - 2 // lower the cardinality to create large groups |
| 536 | + } |
| 537 | + labels := []*profilev1.Label{ |
| 538 | + {Key: highCardinalityOffset - 1, Str: labelValue}, |
| 539 | + } |
| 540 | + profile.Sample = append(profile.Sample, &profilev1.Sample{ |
| 541 | + LocationId: []uint64{uint64(i + 1)}, |
| 542 | + Value: []int64{2}, |
| 543 | + Label: labels, |
| 544 | + }) |
| 545 | + } |
| 546 | + |
| 547 | + b.ResetTimer() |
| 548 | + b.ReportAllocs() |
| 549 | + |
| 550 | + for i := 0; i < b.N; i++ { |
| 551 | + visitor := new(mockVisitor) |
| 552 | + err := VisitSampleSeries(profile, []*typesv1.LabelPair{ |
| 553 | + {Name: "__name__", Value: "profile"}, |
| 554 | + {Name: "foo", Value: "bar"}, |
| 555 | + }, defaultRelabelConfigs, visitor) |
| 556 | + require.NoError(b, err) |
| 557 | + } |
| 558 | +} |
0 commit comments