MCPcopy Index your code
hub / github.com/prometheus/prometheus / BenchmarkRemoteWriteHandler

Function BenchmarkRemoteWriteHandler

storage/remote/write_handler_test.go:1054–1108  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1052}
1053
1054func BenchmarkRemoteWriteHandler(b *testing.B) {
1055 labelStrings := []string{
1056 "__name__", "test_metric",
1057 "test_label_name", "abcdefg'hijlmn234!@#$%^&*()_+~`\"{}[],./<>?hello0123hiOlá你好Dzieńdobry9Zd8ra765v4stvuyte",
1058 }
1059 v1Labels := prompb.FromLabels(labels.FromStrings(labelStrings...), nil)
1060
1061 testCases := []struct {
1062 name string
1063 payloadFunc func() ([]byte, error)
1064 protoFormat remoteapi.WriteMessageType
1065 }{
1066 {
1067 name: "V1 Write",
1068 payloadFunc: func() ([]byte, error) {
1069 buf, _, _, err := buildWriteRequest(nil, []prompb.TimeSeries{{
1070 Labels: v1Labels,
1071 Histograms: []prompb.Histogram{prompb.FromIntHistogram(0, &testHistogram)},
1072 }}, nil, nil, nil, nil, "snappy")
1073 return buf, err
1074 },
1075 protoFormat: remoteapi.WriteV1MessageType,
1076 },
1077 {
1078 name: "V2 Write",
1079 payloadFunc: func() ([]byte, error) {
1080 buf, _, _, err := buildV2WriteRequest(promslog.NewNopLogger(), []writev2.TimeSeries{{
1081 LabelsRefs: []uint32{0, 1, 2, 3},
1082 Histograms: []writev2.Histogram{writev2.FromIntHistogram(0, &testHistogram)},
1083 }}, labelStrings,
1084 nil, nil, nil, "snappy")
1085 return buf, err
1086 },
1087 protoFormat: remoteapi.WriteV2MessageType,
1088 },
1089 }
1090 for _, tc := range testCases {
1091 b.Run(tc.name, func(b *testing.B) {
1092 appendable := &mockAppendable{}
1093 handler := NewWriteHandler(promslog.NewNopLogger(), nil, appendable, []remoteapi.WriteMessageType{tc.protoFormat}, false, false, false)
1094 b.ResetTimer()
1095 for b.Loop() {
1096 b.StopTimer()
1097 buf, err := tc.payloadFunc()
1098 require.NoError(b, err)
1099 req, err := http.NewRequest(http.MethodPost, "", bytes.NewReader(buf))
1100 require.NoError(b, err)
1101 b.StartTimer()
1102
1103 recorder := httptest.NewRecorder()
1104 handler.ServeHTTP(recorder, req)
1105 }
1106 })
1107 }
1108}
1109
1110func TestCommitErr_V1Message(t *testing.T) {
1111 payload, _, _, err := buildWriteRequest(nil, writeRequestFixture.Timeseries, nil, nil, nil, nil, "snappy")

Callers

nothing calls this directly

Calls 8

FromLabelsFunction · 0.92
FromStringsFunction · 0.92
FromIntHistogramFunction · 0.92
buildWriteRequestFunction · 0.85
buildV2WriteRequestFunction · 0.85
NewWriteHandlerFunction · 0.85
RunMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…