MCPcopy Index your code
hub / github.com/coder/coder / genAgentMetric

Function genAgentMetric

coderd/prometheusmetrics/aggregator_test.go:700–718  ·  view source on GitHub ↗
(t testing.TB)

Source from the content-addressed store, hash-verified

698}
699
700func 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
720func must[T any](t T, err error) T {
721 if err != nil {

Callers 1

benchmarkRunnerFunction · 0.85

Calls 5

Float64Function · 0.92
StringCharsetFunction · 0.92
IntnFunction · 0.92
mustFunction · 0.70
HelperMethod · 0.65

Tested by

no test coverage detected