MCPcopy Create free account
hub / github.com/cortexproject/cortex / makeWriteRequestWithNHCB

Function makeWriteRequestWithNHCB

pkg/distributor/distributor_test.go:3450–3490  ·  view source on GitHub ↗

makeWriteRequestWithNHCB builds a write request with optional NHCB (native histogram custom buckets) timeseries.

(startTimestampMs int64, samples int, metadata int, histograms int, nhcb int)

Source from the content-addressed store, hash-verified

3448
3449// makeWriteRequestWithNHCB builds a write request with optional NHCB (native histogram custom buckets) timeseries.
3450func makeWriteRequestWithNHCB(startTimestampMs int64, samples int, metadata int, histograms int, nhcb int) *cortexpb.WriteRequest {
3451 request := &cortexpb.WriteRequest{}
3452 for i := range samples {
3453 request.Timeseries = append(request.Timeseries, makeWriteRequestTimeseries(
3454 []cortexpb.LabelAdapter{
3455 {Name: model.MetricNameLabel, Value: "foo"},
3456 {Name: "bar", Value: "baz"},
3457 {Name: "sample", Value: fmt.Sprintf("%d", i)},
3458 }, startTimestampMs+int64(i), int64(i), false))
3459 }
3460
3461 for i := range histograms {
3462 request.Timeseries = append(request.Timeseries, makeWriteRequestTimeseries(
3463 []cortexpb.LabelAdapter{
3464 {Name: model.MetricNameLabel, Value: "foo"},
3465 {Name: "bar", Value: "baz"},
3466 {Name: "histogram", Value: fmt.Sprintf("%d", i)},
3467 }, startTimestampMs+int64(i), int64(i), true))
3468 }
3469
3470 for i := range nhcb {
3471 ts := startTimestampMs + int64(i)
3472 request.Timeseries = append(request.Timeseries, makeWriteRequestTimeseriesNHCB(
3473 []cortexpb.LabelAdapter{
3474 {Name: model.MetricNameLabel, Value: "foo"},
3475 {Name: "bar", Value: "baz"},
3476 {Name: "nhcb", Value: fmt.Sprintf("%d", i)},
3477 }, ts, int64(i)))
3478 }
3479
3480 for i := range metadata {
3481 m := &cortexpb.MetricMetadata{
3482 MetricFamilyName: fmt.Sprintf("metric_%d", i),
3483 Type: cortexpb.COUNTER,
3484 Help: fmt.Sprintf("a help for metric_%d", i),
3485 }
3486 request.Metadata = append(request.Metadata, m)
3487 }
3488
3489 return request
3490}
3491
3492func makeWriteRequestTimeseries(labels []cortexpb.LabelAdapter, ts, value int64, histogram bool) cortexpb.PreallocTimeseries {
3493 t := cortexpb.PreallocTimeseries{

Callers 2

TestDistributor_PushFunction · 0.85
makeWriteRequestFunction · 0.85

Calls 2

Tested by

no test coverage detected