generated_metrics_test.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // Code generated by mdatagen. DO NOT EDIT.
  2. package metadata
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "go.opentelemetry.io/collector/pdata/pcommon"
  7. "go.opentelemetry.io/collector/pdata/pmetric"
  8. "go.opentelemetry.io/collector/receiver/receivertest"
  9. "go.uber.org/zap"
  10. "go.uber.org/zap/zaptest/observer"
  11. )
  12. type testConfigCollection int
  13. const (
  14. testSetDefault testConfigCollection = iota
  15. testSetAll
  16. testSetNone
  17. )
  18. func TestMetricsBuilder(t *testing.T) {
  19. tests := []struct {
  20. name string
  21. configSet testConfigCollection
  22. }{
  23. {
  24. name: "default",
  25. configSet: testSetDefault,
  26. },
  27. {
  28. name: "all_set",
  29. configSet: testSetAll,
  30. },
  31. {
  32. name: "none_set",
  33. configSet: testSetNone,
  34. },
  35. }
  36. for _, test := range tests {
  37. t.Run(test.name, func(t *testing.T) {
  38. start := pcommon.Timestamp(1_000_000_000)
  39. ts := pcommon.Timestamp(1_000_001_000)
  40. observedZapCore, observedLogs := observer.New(zap.WarnLevel)
  41. settings := receivertest.NewNopCreateSettings()
  42. settings.Logger = zap.New(observedZapCore)
  43. mb := NewMetricsBuilder(loadMetricsBuilderConfig(t, test.name), settings, WithStartTime(start))
  44. expectedWarnings := 0
  45. assert.Equal(t, expectedWarnings, observedLogs.Len())
  46. defaultMetricsCount := 0
  47. allMetricsCount := 0
  48. defaultMetricsCount++
  49. allMetricsCount++
  50. mb.RecordRiakMemoryLimitDataPoint(ts, 1)
  51. defaultMetricsCount++
  52. allMetricsCount++
  53. mb.RecordRiakNodeOperationCountDataPoint(ts, 1, AttributeRequestPut)
  54. defaultMetricsCount++
  55. allMetricsCount++
  56. mb.RecordRiakNodeOperationTimeMeanDataPoint(ts, 1, AttributeRequestPut)
  57. defaultMetricsCount++
  58. allMetricsCount++
  59. mb.RecordRiakNodeReadRepairCountDataPoint(ts, 1)
  60. defaultMetricsCount++
  61. allMetricsCount++
  62. mb.RecordRiakVnodeIndexOperationCountDataPoint(ts, 1, AttributeOperationRead)
  63. defaultMetricsCount++
  64. allMetricsCount++
  65. mb.RecordRiakVnodeOperationCountDataPoint(ts, 1, AttributeRequestPut)
  66. rb := mb.NewResourceBuilder()
  67. rb.SetRiakNodeName("riak.node.name-val")
  68. res := rb.Emit()
  69. metrics := mb.Emit(WithResource(res))
  70. if test.configSet == testSetNone {
  71. assert.Equal(t, 0, metrics.ResourceMetrics().Len())
  72. return
  73. }
  74. assert.Equal(t, 1, metrics.ResourceMetrics().Len())
  75. rm := metrics.ResourceMetrics().At(0)
  76. assert.Equal(t, res, rm.Resource())
  77. assert.Equal(t, 1, rm.ScopeMetrics().Len())
  78. ms := rm.ScopeMetrics().At(0).Metrics()
  79. if test.configSet == testSetDefault {
  80. assert.Equal(t, defaultMetricsCount, ms.Len())
  81. }
  82. if test.configSet == testSetAll {
  83. assert.Equal(t, allMetricsCount, ms.Len())
  84. }
  85. validatedMetrics := make(map[string]bool)
  86. for i := 0; i < ms.Len(); i++ {
  87. switch ms.At(i).Name() {
  88. case "riak.memory.limit":
  89. assert.False(t, validatedMetrics["riak.memory.limit"], "Found a duplicate in the metrics slice: riak.memory.limit")
  90. validatedMetrics["riak.memory.limit"] = true
  91. assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type())
  92. assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len())
  93. assert.Equal(t, "The amount of memory allocated to the node.", ms.At(i).Description())
  94. assert.Equal(t, "By", ms.At(i).Unit())
  95. assert.Equal(t, false, ms.At(i).Sum().IsMonotonic())
  96. assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality())
  97. dp := ms.At(i).Sum().DataPoints().At(0)
  98. assert.Equal(t, start, dp.StartTimestamp())
  99. assert.Equal(t, ts, dp.Timestamp())
  100. assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
  101. assert.Equal(t, int64(1), dp.IntValue())
  102. case "riak.node.operation.count":
  103. assert.False(t, validatedMetrics["riak.node.operation.count"], "Found a duplicate in the metrics slice: riak.node.operation.count")
  104. validatedMetrics["riak.node.operation.count"] = true
  105. assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type())
  106. assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len())
  107. assert.Equal(t, "The number of operations performed by the node.", ms.At(i).Description())
  108. assert.Equal(t, "{operation}", ms.At(i).Unit())
  109. assert.Equal(t, true, ms.At(i).Sum().IsMonotonic())
  110. assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality())
  111. dp := ms.At(i).Sum().DataPoints().At(0)
  112. assert.Equal(t, start, dp.StartTimestamp())
  113. assert.Equal(t, ts, dp.Timestamp())
  114. assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
  115. assert.Equal(t, int64(1), dp.IntValue())
  116. attrVal, ok := dp.Attributes().Get("request")
  117. assert.True(t, ok)
  118. assert.EqualValues(t, "put", attrVal.Str())
  119. case "riak.node.operation.time.mean":
  120. assert.False(t, validatedMetrics["riak.node.operation.time.mean"], "Found a duplicate in the metrics slice: riak.node.operation.time.mean")
  121. validatedMetrics["riak.node.operation.time.mean"] = true
  122. assert.Equal(t, pmetric.MetricTypeGauge, ms.At(i).Type())
  123. assert.Equal(t, 1, ms.At(i).Gauge().DataPoints().Len())
  124. assert.Equal(t, "The mean time between request and response for operations performed by the node over the last minute.", ms.At(i).Description())
  125. assert.Equal(t, "us", ms.At(i).Unit())
  126. dp := ms.At(i).Gauge().DataPoints().At(0)
  127. assert.Equal(t, start, dp.StartTimestamp())
  128. assert.Equal(t, ts, dp.Timestamp())
  129. assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
  130. assert.Equal(t, int64(1), dp.IntValue())
  131. attrVal, ok := dp.Attributes().Get("request")
  132. assert.True(t, ok)
  133. assert.EqualValues(t, "put", attrVal.Str())
  134. case "riak.node.read_repair.count":
  135. assert.False(t, validatedMetrics["riak.node.read_repair.count"], "Found a duplicate in the metrics slice: riak.node.read_repair.count")
  136. validatedMetrics["riak.node.read_repair.count"] = true
  137. assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type())
  138. assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len())
  139. assert.Equal(t, "The number of read repairs performed by the node.", ms.At(i).Description())
  140. assert.Equal(t, "{read_repair}", ms.At(i).Unit())
  141. assert.Equal(t, true, ms.At(i).Sum().IsMonotonic())
  142. assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality())
  143. dp := ms.At(i).Sum().DataPoints().At(0)
  144. assert.Equal(t, start, dp.StartTimestamp())
  145. assert.Equal(t, ts, dp.Timestamp())
  146. assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
  147. assert.Equal(t, int64(1), dp.IntValue())
  148. case "riak.vnode.index.operation.count":
  149. assert.False(t, validatedMetrics["riak.vnode.index.operation.count"], "Found a duplicate in the metrics slice: riak.vnode.index.operation.count")
  150. validatedMetrics["riak.vnode.index.operation.count"] = true
  151. assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type())
  152. assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len())
  153. assert.Equal(t, "The number of index operations performed by vnodes on the node.", ms.At(i).Description())
  154. assert.Equal(t, "{operation}", ms.At(i).Unit())
  155. assert.Equal(t, false, ms.At(i).Sum().IsMonotonic())
  156. assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality())
  157. dp := ms.At(i).Sum().DataPoints().At(0)
  158. assert.Equal(t, start, dp.StartTimestamp())
  159. assert.Equal(t, ts, dp.Timestamp())
  160. assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
  161. assert.Equal(t, int64(1), dp.IntValue())
  162. attrVal, ok := dp.Attributes().Get("operation")
  163. assert.True(t, ok)
  164. assert.EqualValues(t, "read", attrVal.Str())
  165. case "riak.vnode.operation.count":
  166. assert.False(t, validatedMetrics["riak.vnode.operation.count"], "Found a duplicate in the metrics slice: riak.vnode.operation.count")
  167. validatedMetrics["riak.vnode.operation.count"] = true
  168. assert.Equal(t, pmetric.MetricTypeSum, ms.At(i).Type())
  169. assert.Equal(t, 1, ms.At(i).Sum().DataPoints().Len())
  170. assert.Equal(t, "The number of operations performed by vnodes on the node.", ms.At(i).Description())
  171. assert.Equal(t, "{operation}", ms.At(i).Unit())
  172. assert.Equal(t, true, ms.At(i).Sum().IsMonotonic())
  173. assert.Equal(t, pmetric.AggregationTemporalityCumulative, ms.At(i).Sum().AggregationTemporality())
  174. dp := ms.At(i).Sum().DataPoints().At(0)
  175. assert.Equal(t, start, dp.StartTimestamp())
  176. assert.Equal(t, ts, dp.Timestamp())
  177. assert.Equal(t, pmetric.NumberDataPointValueTypeInt, dp.ValueType())
  178. assert.Equal(t, int64(1), dp.IntValue())
  179. attrVal, ok := dp.Attributes().Get("request")
  180. assert.True(t, ok)
  181. assert.EqualValues(t, "put", attrVal.Str())
  182. }
  183. }
  184. })
  185. }
  186. }