| 1 |
|
| 2 |
|
| 3 |
package metadatatest |
| 4 |
|
| 5 |
import ( |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/stretchr/testify/require" |
| 9 |
"go.opentelemetry.io/otel/sdk/metric/metricdata" |
| 10 |
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" |
| 11 |
|
| 12 |
"go.opentelemetry.io/collector/component/componenttest" |
| 13 |
) |
| 14 |
|
| 15 |
func AssertEqualConnectorConsumedItems(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 16 |
want := metricdata.Metrics{ |
| 17 |
Name: "otelcol.connector.consumed.items", |
| 18 |
Description: "Number of items passed to the connector. [Development]", |
| 19 |
Unit: "{item}", |
| 20 |
Data: metricdata.Sum[int64]{ |
| 21 |
Temporality: metricdata.CumulativeTemporality, |
| 22 |
IsMonotonic: true, |
| 23 |
DataPoints: dps, |
| 24 |
}, |
| 25 |
} |
| 26 |
got, err := tt.GetMetric("otelcol.connector.consumed.items") |
| 27 |
require.NoError(t, err) |
| 28 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 29 |
} |
| 30 |
|
| 31 |
func AssertEqualConnectorConsumedSize(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 32 |
want := metricdata.Metrics{ |
| 33 |
Name: "otelcol.connector.consumed.size", |
| 34 |
Description: "Size of items passed to the connector, based on ProtoMarshaler.Sizer. [Development]", |
| 35 |
Unit: "{item}", |
| 36 |
Data: metricdata.Sum[int64]{ |
| 37 |
Temporality: metricdata.CumulativeTemporality, |
| 38 |
IsMonotonic: true, |
| 39 |
DataPoints: dps, |
| 40 |
}, |
| 41 |
} |
| 42 |
got, err := tt.GetMetric("otelcol.connector.consumed.size") |
| 43 |
require.NoError(t, err) |
| 44 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 45 |
} |
| 46 |
|
| 47 |
func AssertEqualConnectorProducedItems(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 48 |
want := metricdata.Metrics{ |
| 49 |
Name: "otelcol.connector.produced.items", |
| 50 |
Description: "Number of items emitted from the connector. [Development]", |
| 51 |
Unit: "{item}", |
| 52 |
Data: metricdata.Sum[int64]{ |
| 53 |
Temporality: metricdata.CumulativeTemporality, |
| 54 |
IsMonotonic: true, |
| 55 |
DataPoints: dps, |
| 56 |
}, |
| 57 |
} |
| 58 |
got, err := tt.GetMetric("otelcol.connector.produced.items") |
| 59 |
require.NoError(t, err) |
| 60 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 61 |
} |
| 62 |
|
| 63 |
func AssertEqualConnectorProducedSize(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 64 |
want := metricdata.Metrics{ |
| 65 |
Name: "otelcol.connector.produced.size", |
| 66 |
Description: "Size of items emitted from the connector, based on ProtoMarshaler.Sizer. [Development]", |
| 67 |
Unit: "{item}", |
| 68 |
Data: metricdata.Sum[int64]{ |
| 69 |
Temporality: metricdata.CumulativeTemporality, |
| 70 |
IsMonotonic: true, |
| 71 |
DataPoints: dps, |
| 72 |
}, |
| 73 |
} |
| 74 |
got, err := tt.GetMetric("otelcol.connector.produced.size") |
| 75 |
require.NoError(t, err) |
| 76 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 77 |
} |
| 78 |
|
| 79 |
func AssertEqualExporterConsumedItems(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 80 |
want := metricdata.Metrics{ |
| 81 |
Name: "otelcol.exporter.consumed.items", |
| 82 |
Description: "Number of items passed to the exporter. [Development]", |
| 83 |
Unit: "{item}", |
| 84 |
Data: metricdata.Sum[int64]{ |
| 85 |
Temporality: metricdata.CumulativeTemporality, |
| 86 |
IsMonotonic: true, |
| 87 |
DataPoints: dps, |
| 88 |
}, |
| 89 |
} |
| 90 |
got, err := tt.GetMetric("otelcol.exporter.consumed.items") |
| 91 |
require.NoError(t, err) |
| 92 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 93 |
} |
| 94 |
|
| 95 |
func AssertEqualExporterConsumedSize(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 96 |
want := metricdata.Metrics{ |
| 97 |
Name: "otelcol.exporter.consumed.size", |
| 98 |
Description: "Size of items passed to the exporter, based on ProtoMarshaler.Sizer. [Development]", |
| 99 |
Unit: "{item}", |
| 100 |
Data: metricdata.Sum[int64]{ |
| 101 |
Temporality: metricdata.CumulativeTemporality, |
| 102 |
IsMonotonic: true, |
| 103 |
DataPoints: dps, |
| 104 |
}, |
| 105 |
} |
| 106 |
got, err := tt.GetMetric("otelcol.exporter.consumed.size") |
| 107 |
require.NoError(t, err) |
| 108 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 109 |
} |
| 110 |
|
| 111 |
func AssertEqualProcessCPUSeconds(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[float64], opts ...metricdatatest.Option) { |
| 112 |
want := metricdata.Metrics{ |
| 113 |
Name: "otelcol_process_cpu_seconds", |
| 114 |
Description: "Total CPU user and system time in seconds [Alpha]", |
| 115 |
Unit: "s", |
| 116 |
Data: metricdata.Sum[float64]{ |
| 117 |
Temporality: metricdata.CumulativeTemporality, |
| 118 |
IsMonotonic: true, |
| 119 |
DataPoints: dps, |
| 120 |
}, |
| 121 |
} |
| 122 |
got, err := tt.GetMetric("otelcol_process_cpu_seconds") |
| 123 |
require.NoError(t, err) |
| 124 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 125 |
} |
| 126 |
|
| 127 |
func AssertEqualProcessMemoryRss(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 128 |
want := metricdata.Metrics{ |
| 129 |
Name: "otelcol_process_memory_rss", |
| 130 |
Description: "Total physical memory (resident set size) [Alpha]", |
| 131 |
Unit: "By", |
| 132 |
Data: metricdata.Gauge[int64]{ |
| 133 |
DataPoints: dps, |
| 134 |
}, |
| 135 |
} |
| 136 |
got, err := tt.GetMetric("otelcol_process_memory_rss") |
| 137 |
require.NoError(t, err) |
| 138 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 139 |
} |
| 140 |
|
| 141 |
func AssertEqualProcessRuntimeHeapAllocBytes(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 142 |
want := metricdata.Metrics{ |
| 143 |
Name: "otelcol_process_runtime_heap_alloc_bytes", |
| 144 |
Description: "Bytes of allocated heap objects (see 'go doc runtime.MemStats.HeapAlloc') [Alpha]", |
| 145 |
Unit: "By", |
| 146 |
Data: metricdata.Gauge[int64]{ |
| 147 |
DataPoints: dps, |
| 148 |
}, |
| 149 |
} |
| 150 |
got, err := tt.GetMetric("otelcol_process_runtime_heap_alloc_bytes") |
| 151 |
require.NoError(t, err) |
| 152 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 153 |
} |
| 154 |
|
| 155 |
func AssertEqualProcessRuntimeTotalAllocBytes(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 156 |
want := metricdata.Metrics{ |
| 157 |
Name: "otelcol_process_runtime_total_alloc_bytes", |
| 158 |
Description: "Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalAlloc') [Alpha]", |
| 159 |
Unit: "By", |
| 160 |
Data: metricdata.Sum[int64]{ |
| 161 |
Temporality: metricdata.CumulativeTemporality, |
| 162 |
IsMonotonic: true, |
| 163 |
DataPoints: dps, |
| 164 |
}, |
| 165 |
} |
| 166 |
got, err := tt.GetMetric("otelcol_process_runtime_total_alloc_bytes") |
| 167 |
require.NoError(t, err) |
| 168 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 169 |
} |
| 170 |
|
| 171 |
func AssertEqualProcessRuntimeTotalSysMemoryBytes(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 172 |
want := metricdata.Metrics{ |
| 173 |
Name: "otelcol_process_runtime_total_sys_memory_bytes", |
| 174 |
Description: "Total bytes of memory obtained from the OS (see 'go doc runtime.MemStats.Sys') [Alpha]", |
| 175 |
Unit: "By", |
| 176 |
Data: metricdata.Gauge[int64]{ |
| 177 |
DataPoints: dps, |
| 178 |
}, |
| 179 |
} |
| 180 |
got, err := tt.GetMetric("otelcol_process_runtime_total_sys_memory_bytes") |
| 181 |
require.NoError(t, err) |
| 182 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 183 |
} |
| 184 |
|
| 185 |
func AssertEqualProcessUptime(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[float64], opts ...metricdatatest.Option) { |
| 186 |
want := metricdata.Metrics{ |
| 187 |
Name: "otelcol_process_uptime", |
| 188 |
Description: "Uptime of the process [Alpha]", |
| 189 |
Unit: "s", |
| 190 |
Data: metricdata.Sum[float64]{ |
| 191 |
Temporality: metricdata.CumulativeTemporality, |
| 192 |
IsMonotonic: true, |
| 193 |
DataPoints: dps, |
| 194 |
}, |
| 195 |
} |
| 196 |
got, err := tt.GetMetric("otelcol_process_uptime") |
| 197 |
require.NoError(t, err) |
| 198 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 199 |
} |
| 200 |
|
| 201 |
func AssertEqualProcessorConsumedItems(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 202 |
want := metricdata.Metrics{ |
| 203 |
Name: "otelcol.processor.consumed.items", |
| 204 |
Description: "Number of items passed to the processor. [Development]", |
| 205 |
Unit: "{item}", |
| 206 |
Data: metricdata.Sum[int64]{ |
| 207 |
Temporality: metricdata.CumulativeTemporality, |
| 208 |
IsMonotonic: true, |
| 209 |
DataPoints: dps, |
| 210 |
}, |
| 211 |
} |
| 212 |
got, err := tt.GetMetric("otelcol.processor.consumed.items") |
| 213 |
require.NoError(t, err) |
| 214 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 215 |
} |
| 216 |
|
| 217 |
func AssertEqualProcessorConsumedSize(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 218 |
want := metricdata.Metrics{ |
| 219 |
Name: "otelcol.processor.consumed.size", |
| 220 |
Description: "Size of items passed to the processor, based on ProtoMarshaler.Sizer. [Development]", |
| 221 |
Unit: "{item}", |
| 222 |
Data: metricdata.Sum[int64]{ |
| 223 |
Temporality: metricdata.CumulativeTemporality, |
| 224 |
IsMonotonic: true, |
| 225 |
DataPoints: dps, |
| 226 |
}, |
| 227 |
} |
| 228 |
got, err := tt.GetMetric("otelcol.processor.consumed.size") |
| 229 |
require.NoError(t, err) |
| 230 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 231 |
} |
| 232 |
|
| 233 |
func AssertEqualProcessorProducedItems(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 234 |
want := metricdata.Metrics{ |
| 235 |
Name: "otelcol.processor.produced.items", |
| 236 |
Description: "Number of items emitted from the processor. [Development]", |
| 237 |
Unit: "{item}", |
| 238 |
Data: metricdata.Sum[int64]{ |
| 239 |
Temporality: metricdata.CumulativeTemporality, |
| 240 |
IsMonotonic: true, |
| 241 |
DataPoints: dps, |
| 242 |
}, |
| 243 |
} |
| 244 |
got, err := tt.GetMetric("otelcol.processor.produced.items") |
| 245 |
require.NoError(t, err) |
| 246 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 247 |
} |
| 248 |
|
| 249 |
func AssertEqualProcessorProducedSize(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 250 |
want := metricdata.Metrics{ |
| 251 |
Name: "otelcol.processor.produced.size", |
| 252 |
Description: "Size of items emitted from the processor, based on ProtoMarshaler.Sizer. [Development]", |
| 253 |
Unit: "{item}", |
| 254 |
Data: metricdata.Sum[int64]{ |
| 255 |
Temporality: metricdata.CumulativeTemporality, |
| 256 |
IsMonotonic: true, |
| 257 |
DataPoints: dps, |
| 258 |
}, |
| 259 |
} |
| 260 |
got, err := tt.GetMetric("otelcol.processor.produced.size") |
| 261 |
require.NoError(t, err) |
| 262 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 263 |
} |
| 264 |
|
| 265 |
func AssertEqualReceiverProducedItems(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 266 |
want := metricdata.Metrics{ |
| 267 |
Name: "otelcol.receiver.produced.items", |
| 268 |
Description: "Number of items emitted from the receiver. [Development]", |
| 269 |
Unit: "{item}", |
| 270 |
Data: metricdata.Sum[int64]{ |
| 271 |
Temporality: metricdata.CumulativeTemporality, |
| 272 |
IsMonotonic: true, |
| 273 |
DataPoints: dps, |
| 274 |
}, |
| 275 |
} |
| 276 |
got, err := tt.GetMetric("otelcol.receiver.produced.items") |
| 277 |
require.NoError(t, err) |
| 278 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 279 |
} |
| 280 |
|
| 281 |
func AssertEqualReceiverProducedSize(t *testing.T, tt *componenttest.Telemetry, dps []metricdata.DataPoint[int64], opts ...metricdatatest.Option) { |
| 282 |
want := metricdata.Metrics{ |
| 283 |
Name: "otelcol.receiver.produced.size", |
| 284 |
Description: "Size of items emitted from the receiver, based on ProtoMarshaler.Sizer. [Development]", |
| 285 |
Unit: "{item}", |
| 286 |
Data: metricdata.Sum[int64]{ |
| 287 |
Temporality: metricdata.CumulativeTemporality, |
| 288 |
IsMonotonic: true, |
| 289 |
DataPoints: dps, |
| 290 |
}, |
| 291 |
} |
| 292 |
got, err := tt.GetMetric("otelcol.receiver.produced.size") |
| 293 |
require.NoError(t, err) |
| 294 |
metricdatatest.AssertEqual(t, want, got, opts...) |
| 295 |
} |