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

Function TestDistributor_Push

pkg/distributor/distributor_test.go:134–431  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestDistributor_Push(t *testing.T) {
135 t.Parallel()
136 // Metrics to assert on.
137 lastSeenTimestamp := "cortex_distributor_latest_seen_sample_timestamp_seconds"
138 distributorAppend := "cortex_distributor_ingester_appends_total"
139 distributorAppendFailure := "cortex_distributor_ingester_append_failures_total"
140 distributorReceivedSamples := "cortex_distributor_received_samples_total"
141 ctx := user.InjectOrgID(context.Background(), "userDistributorPush")
142
143 type samplesIn struct {
144 num int
145 startTimestampMs int64
146 }
147 for name, tc := range map[string]struct {
148 metricNames []string
149 numIngesters int
150 happyIngesters int
151 samples samplesIn
152 histogramSamples bool
153 nhcbSamples int
154 metadata int
155 expectedResponse *cortexpb.WriteResponse
156 expectedError error
157 expectedMetrics string
158 ingesterError error
159 }{
160 "A push of no samples shouldn't block or return error, even if ingesters are sad": {
161 numIngesters: 3,
162 happyIngesters: 0,
163 expectedResponse: emptyResponse,
164 },
165 "A push to 3 happy ingesters should succeed": {
166 numIngesters: 3,
167 happyIngesters: 3,
168 samples: samplesIn{num: 5, startTimestampMs: 123456789000},
169 metadata: 5,
170 expectedResponse: emptyResponse,
171 metricNames: []string{lastSeenTimestamp},
172 expectedMetrics: `
173 # HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
174 # TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
175 cortex_distributor_latest_seen_sample_timestamp_seconds{user="userDistributorPush"} 123456789.004
176 `,
177 },
178 "A push to 2 happy ingesters should succeed": {
179 numIngesters: 3,
180 happyIngesters: 2,
181 samples: samplesIn{num: 5, startTimestampMs: 123456789000},
182 metadata: 5,
183 expectedResponse: emptyResponse,
184 metricNames: []string{lastSeenTimestamp},
185 expectedMetrics: `
186 # HELP cortex_distributor_latest_seen_sample_timestamp_seconds Unix timestamp of latest received sample per user.
187 # TYPE cortex_distributor_latest_seen_sample_timestamp_seconds gauge
188 cortex_distributor_latest_seen_sample_timestamp_seconds{user="userDistributorPush"} 123456789.004
189 `,
190 },
191 "A push to 1 happy ingesters should fail": {

Callers

nothing calls this directly

Calls 8

DefaultValuesFunction · 0.92
PollFunction · 0.92
makeWriteRequestWithNHCBFunction · 0.85
makeWriteRequestFunction · 0.85
prepareFunction · 0.70
RunMethod · 0.65
PushMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected