(t *testing.T)
| 223 | } |
| 224 | |
| 225 | func TestValidateExemplars(t *testing.T) { |
| 226 | userID := "testUser" |
| 227 | reg := prometheus.NewRegistry() |
| 228 | validateMetrics := NewValidateMetrics(reg) |
| 229 | invalidExemplars := []cortexpb.Exemplar{ |
| 230 | { |
| 231 | // Missing labels |
| 232 | Labels: nil, |
| 233 | }, |
| 234 | { |
| 235 | // Invalid timestamp |
| 236 | Labels: []cortexpb.LabelAdapter{{Name: "foo", Value: "bar"}}, |
| 237 | }, |
| 238 | { |
| 239 | // Combined labelset too long |
| 240 | Labels: []cortexpb.LabelAdapter{{Name: "foo", Value: strings.Repeat("0", 126)}}, |
| 241 | TimestampMs: 1000, |
| 242 | }, |
| 243 | } |
| 244 | |
| 245 | for _, ie := range invalidExemplars { |
| 246 | err := ValidateExemplar(validateMetrics, userID, []cortexpb.LabelAdapter{}, ie) |
| 247 | assert.NotNil(t, err) |
| 248 | } |
| 249 | |
| 250 | validateMetrics.DiscardedExemplars.WithLabelValues("random reason", "different user").Inc() |
| 251 | |
| 252 | require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(` |
| 253 | # HELP cortex_discarded_exemplars_total The total number of exemplars that were discarded. |
| 254 | # TYPE cortex_discarded_exemplars_total counter |
| 255 | cortex_discarded_exemplars_total{reason="exemplar_labels_missing",user="testUser"} 1 |
| 256 | cortex_discarded_exemplars_total{reason="exemplar_labels_too_long",user="testUser"} 1 |
| 257 | cortex_discarded_exemplars_total{reason="exemplar_timestamp_invalid",user="testUser"} 1 |
| 258 | |
| 259 | cortex_discarded_exemplars_total{reason="random reason",user="different user"} 1 |
| 260 | `), "cortex_discarded_exemplars_total")) |
| 261 | |
| 262 | // Delete test user and verify only different remaining |
| 263 | DeletePerUserValidationMetrics(validateMetrics, userID, util_log.Logger) |
| 264 | require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(` |
| 265 | # HELP cortex_discarded_exemplars_total The total number of exemplars that were discarded. |
| 266 | # TYPE cortex_discarded_exemplars_total counter |
| 267 | cortex_discarded_exemplars_total{reason="random reason",user="different user"} 1 |
| 268 | `), "cortex_discarded_exemplars_total")) |
| 269 | } |
| 270 | |
| 271 | func TestValidateMetadata(t *testing.T) { |
| 272 | cfg := new(Limits) |
nothing calls this directly
no test coverage detected