(t *testing.T)
| 378 | } |
| 379 | |
| 380 | func TestSendSumOfSummariesPerUser(t *testing.T) { |
| 381 | objectives := map[float64]float64{0.25: 25, 0.5: 50, 0.75: 75} |
| 382 | user1Metric := prometheus.NewSummary(prometheus.SummaryOpts{Name: "test_metric", Objectives: objectives}) |
| 383 | user2Metric := prometheus.NewSummary(prometheus.SummaryOpts{Name: "test_metric", Objectives: objectives}) |
| 384 | user1Metric.Observe(25) |
| 385 | user1Metric.Observe(50) |
| 386 | user1Metric.Observe(75) |
| 387 | user2Metric.Observe(25) |
| 388 | user2Metric.Observe(50) |
| 389 | user2Metric.Observe(76) |
| 390 | |
| 391 | user1Reg := prometheus.NewRegistry() |
| 392 | user2Reg := prometheus.NewRegistry() |
| 393 | user1Reg.MustRegister(user1Metric) |
| 394 | user2Reg.MustRegister(user2Metric) |
| 395 | |
| 396 | regs := NewUserRegistries() |
| 397 | regs.AddUserRegistry("user-1", user1Reg) |
| 398 | regs.AddUserRegistry("user-2", user2Reg) |
| 399 | mf := regs.BuildMetricFamiliesPerUser() |
| 400 | |
| 401 | { |
| 402 | desc := prometheus.NewDesc("test_metric", "", []string{"user"}, nil) |
| 403 | actual := collectMetrics(t, func(out chan prometheus.Metric) { |
| 404 | mf.SendSumOfSummariesPerUser(out, desc, "test_metric") |
| 405 | }) |
| 406 | expected := []*dto.Metric{ |
| 407 | { |
| 408 | Label: makeLabels("user", "user-1"), |
| 409 | Summary: &dto.Summary{ |
| 410 | SampleCount: uint64p(3), |
| 411 | SampleSum: float64p(150), |
| 412 | Quantile: []*dto.Quantile{ |
| 413 | { |
| 414 | Quantile: proto.Float64(.25), |
| 415 | Value: proto.Float64(25), |
| 416 | }, |
| 417 | { |
| 418 | Quantile: proto.Float64(.5), |
| 419 | Value: proto.Float64(50), |
| 420 | }, |
| 421 | { |
| 422 | Quantile: proto.Float64(.75), |
| 423 | Value: proto.Float64(75), |
| 424 | }, |
| 425 | }, |
| 426 | }, |
| 427 | }, |
| 428 | { |
| 429 | Label: makeLabels("user", "user-2"), |
| 430 | Summary: &dto.Summary{ |
| 431 | SampleCount: uint64p(3), |
| 432 | SampleSum: float64p(151), |
| 433 | Quantile: []*dto.Quantile{ |
| 434 | { |
| 435 | Quantile: proto.Float64(.25), |
| 436 | Value: proto.Float64(25), |
| 437 | }, |
nothing calls this directly
no test coverage detected