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

Function TestBasicContentNegotiation

storage/remote/queue_manager_test.go:73–195  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestBasicContentNegotiation(t *testing.T) {
74 t.Parallel()
75
76 queueConfig := config.DefaultQueueConfig
77 queueConfig.BatchSendDeadline = model.Duration(100 * time.Millisecond)
78 queueConfig.MaxShards = 1
79
80 // We need to set URL's so that metric creation doesn't panic.
81 writeConfig := baseRemoteWriteConfig("http://test-storage.com")
82 writeConfig.QueueConfig = queueConfig
83
84 conf := &config.Config{
85 GlobalConfig: config.DefaultGlobalConfig,
86 RemoteWriteConfigs: []*config.RemoteWriteConfig{
87 writeConfig,
88 },
89 }
90
91 for _, tc := range []struct {
92 name string
93 senderProtoMsg remoteapi.WriteMessageType
94 receiverProtoMsg remoteapi.WriteMessageType
95 injectErrs []error
96 expectFail bool
97 }{
98 {
99 name: "v2 happy path",
100 senderProtoMsg: remoteapi.WriteV2MessageType, receiverProtoMsg: remoteapi.WriteV2MessageType,
101 injectErrs: []error{nil},
102 },
103 {
104 name: "v1 happy path",
105 senderProtoMsg: remoteapi.WriteV1MessageType, receiverProtoMsg: remoteapi.WriteV1MessageType,
106 injectErrs: []error{nil},
107 },
108 // Test a case where the v1 request has a temporary delay but goes through on retry.
109 {
110 name: "v1 happy path with one 5xx retry",
111 senderProtoMsg: remoteapi.WriteV1MessageType, receiverProtoMsg: remoteapi.WriteV1MessageType,
112 injectErrs: []error{RecoverableError{errors.New("pretend 500"), 1}, nil},
113 },
114 // Repeat the above test but with v2. The request has a temporary delay but goes through on retry.
115 {
116 name: "v2 happy path with one 5xx retry",
117 senderProtoMsg: remoteapi.WriteV2MessageType, receiverProtoMsg: remoteapi.WriteV2MessageType,
118 injectErrs: []error{RecoverableError{errors.New("pretend 500"), 1}, nil},
119 },
120 // A few error cases of v2 talking to v1.
121 {
122 name: "v2 talks to v1 that gives 400 or 415",
123 senderProtoMsg: remoteapi.WriteV2MessageType, receiverProtoMsg: remoteapi.WriteV1MessageType,
124 injectErrs: []error{errors.New("pretend unrecoverable err")},
125 expectFail: true,
126 },
127 {
128 name: "v2 talks to (broken) v1 that tries to unmarshal v2 payload with v1 proto",
129 senderProtoMsg: remoteapi.WriteV2MessageType, receiverProtoMsg: remoteapi.WriteV1MessageType,
130 injectErrs: []error{nil},

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ApplyConfigMethod · 0.95
injectErrorsMethod · 0.95
expectSamplesMethod · 0.95
waitForExpectedDataMethod · 0.95
GenerateRecordsFunction · 0.92
RetryFunction · 0.92
baseRemoteWriteConfigFunction · 0.85
NewStorageFunction · 0.85
toHashFunction · 0.85
NewTestWriteClientFunction · 0.85
DurationMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…