(t *testing.T)
| 132 | } |
| 133 | |
| 134 | func 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": { |
nothing calls this directly
no test coverage detected