MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestHandler_remoteWrite

Function TestHandler_remoteWrite

pkg/util/push/push_test.go:720–855  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

718}
719
720func TestHandler_remoteWrite(t *testing.T) {
721 var limits validation.Limits
722 flagext.DefaultValues(&limits)
723 overrides := validation.NewOverrides(limits, nil)
724
725 tests := []struct {
726 name string
727 createBody func() ([]byte, bool) // returns (bodyBytes, isV2)
728 expectedStatus int
729 expectedBody string
730 verifyResponse func(resp *httptest.ResponseRecorder)
731 }{
732 {
733 name: "remote write v1",
734 createBody: func() ([]byte, bool) {
735 return createPrometheusRemoteWriteProtobuf(t), false
736 },
737 expectedStatus: http.StatusOK,
738 },
739 {
740 name: "remote write v2",
741 createBody: func() ([]byte, bool) {
742 return createPrometheusRemoteWriteV2Protobuf(t), true
743 },
744 expectedStatus: http.StatusNoContent,
745 verifyResponse: func(resp *httptest.ResponseRecorder) {
746 respHeader := resp.Header()
747 assert.Equal(t, "1", respHeader[rw20WrittenSamplesHeader][0])
748 assert.Equal(t, "1", respHeader[rw20WrittenHistogramsHeader][0])
749 assert.Equal(t, "1", respHeader[rw20WrittenExemplarsHeader][0])
750 },
751 },
752 {
753 name: "remote write v2 with empty samples and histograms should return 400",
754 createBody: func() ([]byte, bool) {
755 // Create a request with a TimeSeries that has no samples and no histograms
756 reqProto := writev2.Request{
757 Symbols: []string{"", "__name__", "foo"},
758 Timeseries: []writev2.TimeSeries{
759 {
760 LabelsRefs: []uint32{1, 2},
761 Exemplars: []writev2.Exemplar{
762 {
763 LabelsRefs: []uint32{},
764 Value: 1.0,
765 Timestamp: time.Now().UnixMilli(),
766 },
767 },
768 },
769 },
770 }
771 reqBytes, err := reqProto.Marshal()
772 require.NoError(t, err)
773 return reqBytes, true
774 },
775 expectedStatus: http.StatusBadRequest,
776 expectedBody: "TimeSeries must contain at least one sample or histogram for series {__name__=\"foo\"}",
777 },

Callers

nothing calls this directly

Calls 14

MarshalMethod · 0.95
DefaultValuesFunction · 0.92
NewOverridesFunction · 0.92
HandlerFunction · 0.70
createRequestFunction · 0.70
EqualMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected