(t testing.TB)
| 698 | } |
| 699 | |
| 700 | func genAgentMetric(t testing.TB) *agentproto.Stats_Metric { |
| 701 | t.Helper() |
| 702 | |
| 703 | var metricType agentproto.Stats_Metric_Type |
| 704 | if must(cryptorand.Float64()) >= 0.5 { |
| 705 | metricType = agentproto.Stats_Metric_COUNTER |
| 706 | } else { |
| 707 | metricType = agentproto.Stats_Metric_GAUGE |
| 708 | } |
| 709 | |
| 710 | // Ensure that metric name does not start or end with underscore, as it is not allowed by Prometheus. |
| 711 | metricName := "metric_" + must(cryptorand.StringCharset(cryptorand.Alpha, 80)) + "_gen" |
| 712 | // Generate random metric value between 0 and 1000. |
| 713 | metricValue := must(cryptorand.Float64()) * float64(must(cryptorand.Intn(1000))) |
| 714 | |
| 715 | return &agentproto.Stats_Metric{ |
| 716 | Name: metricName, Type: metricType, Value: metricValue, Labels: []*agentproto.Stats_Metric_Label{}, |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | func must[T any](t T, err error) T { |
| 721 | if err != nil { |
no test coverage detected