TestMetricsRegistryMetrics tests the OpenTelemetry behavior with respect to registered metrics. It registers metrics in the metrics registry. It then creates an OpenTelemetry client and server stats handler This test then makes measurements on those instruments using one of the stats handlers, then
(t *testing.T)
| 61 | // the expected metrics emissions, which includes default metrics and optional |
| 62 | // label assertions. |
| 63 | func (s) TestMetricsRegistryMetrics(t *testing.T) { |
| 64 | cleanup := internal.SnapshotMetricRegistryForTesting() |
| 65 | defer cleanup() |
| 66 | |
| 67 | intCountHandle1 := estats.RegisterInt64Count(estats.MetricDescriptor{ |
| 68 | Name: "int-counter-1", |
| 69 | Description: "Sum of calls from test", |
| 70 | Unit: "int", |
| 71 | Labels: []string{"int counter 1 label key"}, |
| 72 | OptionalLabels: []string{"int counter 1 optional label key"}, |
| 73 | Default: true, |
| 74 | }) |
| 75 | // A non default metric. If not specified in OpenTelemetry constructor, this |
| 76 | // will become a no-op, so measurements recorded on it won't show up in |
| 77 | // emitted metrics. |
| 78 | intCountHandle2 := estats.RegisterInt64Count(estats.MetricDescriptor{ |
| 79 | Name: "int-counter-2", |
| 80 | Description: "Sum of calls from test", |
| 81 | Unit: "int", |
| 82 | Labels: []string{"int counter 2 label key"}, |
| 83 | OptionalLabels: []string{"int counter 2 optional label key"}, |
| 84 | Default: false, |
| 85 | }) |
| 86 | // Register another non default metric. This will get added to the default |
| 87 | // metrics set in the OpenTelemetry constructor options, so metrics recorded |
| 88 | // on this should show up in metrics emissions. |
| 89 | intCountHandle3 := estats.RegisterInt64Count(estats.MetricDescriptor{ |
| 90 | Name: "int-counter-3", |
| 91 | Description: "sum of calls from test", |
| 92 | Unit: "int", |
| 93 | Labels: []string{"int counter 3 label key"}, |
| 94 | OptionalLabels: []string{"int counter 3 optional label key"}, |
| 95 | Default: false, |
| 96 | }) |
| 97 | floatCountHandle := estats.RegisterFloat64Count(estats.MetricDescriptor{ |
| 98 | Name: "float-counter", |
| 99 | Description: "sum of calls from test", |
| 100 | Unit: "float", |
| 101 | Labels: []string{"float counter label key"}, |
| 102 | OptionalLabels: []string{"float counter optional label key"}, |
| 103 | Default: true, |
| 104 | }) |
| 105 | bounds := []float64{0, 5, 10} |
| 106 | intHistoHandle := estats.RegisterInt64Histo(estats.MetricDescriptor{ |
| 107 | Name: "int-histo", |
| 108 | Description: "histogram of call values from tests", |
| 109 | Unit: "int", |
| 110 | Labels: []string{"int histo label key"}, |
| 111 | OptionalLabels: []string{"int histo optional label key"}, |
| 112 | Default: true, |
| 113 | Bounds: bounds, |
| 114 | }) |
| 115 | floatHistoHandle := estats.RegisterFloat64Histo(estats.MetricDescriptor{ |
| 116 | Name: "float-histo", |
| 117 | Description: "histogram of call values from tests", |
| 118 | Unit: "float", |
| 119 | Labels: []string{"float histo label key"}, |
| 120 | OptionalLabels: []string{"float histo optional label key"}, |
nothing calls this directly
no test coverage detected