MCPcopy
hub / github.com/prometheus/prometheus / BenchmarkOTLP

Function BenchmarkOTLP

storage/remote/write_otlp_handler_test.go:424–674  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

422}
423
424func BenchmarkOTLP(b *testing.B) {
425 start := time.Date(2000, 1, 2, 3, 4, 5, 0, time.UTC)
426
427 type Type struct {
428 name string
429 data func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric
430 }
431 types := []Type{{
432 name: "sum",
433 data: func() func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric {
434 cumul := make(map[int]float64)
435 return func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric {
436 m := pmetric.NewMetric()
437 sum := m.SetEmptySum()
438 sum.SetAggregationTemporality(mode)
439 dps := sum.DataPoints()
440 for id := range dpc {
441 dp := dps.AppendEmpty()
442 dp.SetStartTimestamp(pcommon.NewTimestampFromTime(start))
443 dp.SetTimestamp(pcommon.NewTimestampFromTime(start.Add(time.Duration(epoch) * time.Minute)))
444 dp.Attributes().PutStr("id", strconv.Itoa(id))
445 v := float64(rand.IntN(100)) / 10
446 switch mode {
447 case pmetric.AggregationTemporalityDelta:
448 dp.SetDoubleValue(v)
449 case pmetric.AggregationTemporalityCumulative:
450 cumul[id] += v
451 dp.SetDoubleValue(cumul[id])
452 }
453 }
454 return []pmetric.Metric{m}
455 }
456 }(),
457 }, {
458 name: "histogram",
459 data: func() func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric {
460 bounds := [4]float64{1, 10, 100, 1000}
461 type state struct {
462 counts [4]uint64
463 count uint64
464 sum float64
465 }
466 var cumul []state
467 return func(mode pmetric.AggregationTemporality, dpc, epoch int) []pmetric.Metric {
468 if cumul == nil {
469 cumul = make([]state, dpc)
470 }
471 m := pmetric.NewMetric()
472 hist := m.SetEmptyHistogram()
473 hist.SetAggregationTemporality(mode)
474 dps := hist.DataPoints()
475 for id := range dpc {
476 dp := dps.AppendEmpty()
477 dp.SetStartTimestamp(pcommon.NewTimestampFromTime(start))
478 dp.SetTimestamp(pcommon.NewTimestampFromTime(start.Add(time.Duration(epoch) * time.Minute)))
479 dp.Attributes().PutStr("id", strconv.Itoa(id))
480 dp.ExplicitBounds().FromRaw(bounds[:])
481

Callers

nothing calls this directly

Calls 13

ResultSamplesMethod · 0.95
NewAppendableFunction · 0.92
sampleCountFunction · 0.85
NewOTLPWriteHandlerFunction · 0.85
DurationMethod · 0.80
SetCountMethod · 0.80
SetSumMethod · 0.80
SkipMethod · 0.80
AddMethod · 0.65
RunMethod · 0.65
SetMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…