generated_config_test.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // Code generated by mdatagen. DO NOT EDIT.
  2. package metadata
  3. import (
  4. "path/filepath"
  5. "testing"
  6. "github.com/google/go-cmp/cmp"
  7. "github.com/google/go-cmp/cmp/cmpopts"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/confmap/confmaptest"
  11. )
  12. func TestMetricsBuilderConfig(t *testing.T) {
  13. tests := []struct {
  14. name string
  15. want MetricsBuilderConfig
  16. }{
  17. {
  18. name: "default",
  19. want: DefaultMetricsBuilderConfig(),
  20. },
  21. {
  22. name: "all_set",
  23. want: MetricsBuilderConfig{
  24. Metrics: MetricsConfig{
  25. HaproxyBytesInput: MetricConfig{Enabled: true},
  26. HaproxyBytesOutput: MetricConfig{Enabled: true},
  27. HaproxyClientsCanceled: MetricConfig{Enabled: true},
  28. HaproxyCompressionBypass: MetricConfig{Enabled: true},
  29. HaproxyCompressionCount: MetricConfig{Enabled: true},
  30. HaproxyCompressionInput: MetricConfig{Enabled: true},
  31. HaproxyCompressionOutput: MetricConfig{Enabled: true},
  32. HaproxyConnectionsErrors: MetricConfig{Enabled: true},
  33. HaproxyConnectionsRate: MetricConfig{Enabled: true},
  34. HaproxyConnectionsRetries: MetricConfig{Enabled: true},
  35. HaproxyConnectionsTotal: MetricConfig{Enabled: true},
  36. HaproxyDowntime: MetricConfig{Enabled: true},
  37. HaproxyFailedChecks: MetricConfig{Enabled: true},
  38. HaproxyRequestsDenied: MetricConfig{Enabled: true},
  39. HaproxyRequestsErrors: MetricConfig{Enabled: true},
  40. HaproxyRequestsQueued: MetricConfig{Enabled: true},
  41. HaproxyRequestsRate: MetricConfig{Enabled: true},
  42. HaproxyRequestsRedispatched: MetricConfig{Enabled: true},
  43. HaproxyRequestsTotal: MetricConfig{Enabled: true},
  44. HaproxyResponsesDenied: MetricConfig{Enabled: true},
  45. HaproxyResponsesErrors: MetricConfig{Enabled: true},
  46. HaproxyServerSelectedTotal: MetricConfig{Enabled: true},
  47. HaproxySessionsAverage: MetricConfig{Enabled: true},
  48. HaproxySessionsCount: MetricConfig{Enabled: true},
  49. HaproxySessionsRate: MetricConfig{Enabled: true},
  50. HaproxySessionsTotal: MetricConfig{Enabled: true},
  51. },
  52. ResourceAttributes: ResourceAttributesConfig{
  53. HaproxyAddr: ResourceAttributeConfig{Enabled: true},
  54. HaproxyProxyName: ResourceAttributeConfig{Enabled: true},
  55. HaproxyServiceName: ResourceAttributeConfig{Enabled: true},
  56. },
  57. },
  58. },
  59. {
  60. name: "none_set",
  61. want: MetricsBuilderConfig{
  62. Metrics: MetricsConfig{
  63. HaproxyBytesInput: MetricConfig{Enabled: false},
  64. HaproxyBytesOutput: MetricConfig{Enabled: false},
  65. HaproxyClientsCanceled: MetricConfig{Enabled: false},
  66. HaproxyCompressionBypass: MetricConfig{Enabled: false},
  67. HaproxyCompressionCount: MetricConfig{Enabled: false},
  68. HaproxyCompressionInput: MetricConfig{Enabled: false},
  69. HaproxyCompressionOutput: MetricConfig{Enabled: false},
  70. HaproxyConnectionsErrors: MetricConfig{Enabled: false},
  71. HaproxyConnectionsRate: MetricConfig{Enabled: false},
  72. HaproxyConnectionsRetries: MetricConfig{Enabled: false},
  73. HaproxyConnectionsTotal: MetricConfig{Enabled: false},
  74. HaproxyDowntime: MetricConfig{Enabled: false},
  75. HaproxyFailedChecks: MetricConfig{Enabled: false},
  76. HaproxyRequestsDenied: MetricConfig{Enabled: false},
  77. HaproxyRequestsErrors: MetricConfig{Enabled: false},
  78. HaproxyRequestsQueued: MetricConfig{Enabled: false},
  79. HaproxyRequestsRate: MetricConfig{Enabled: false},
  80. HaproxyRequestsRedispatched: MetricConfig{Enabled: false},
  81. HaproxyRequestsTotal: MetricConfig{Enabled: false},
  82. HaproxyResponsesDenied: MetricConfig{Enabled: false},
  83. HaproxyResponsesErrors: MetricConfig{Enabled: false},
  84. HaproxyServerSelectedTotal: MetricConfig{Enabled: false},
  85. HaproxySessionsAverage: MetricConfig{Enabled: false},
  86. HaproxySessionsCount: MetricConfig{Enabled: false},
  87. HaproxySessionsRate: MetricConfig{Enabled: false},
  88. HaproxySessionsTotal: MetricConfig{Enabled: false},
  89. },
  90. ResourceAttributes: ResourceAttributesConfig{
  91. HaproxyAddr: ResourceAttributeConfig{Enabled: false},
  92. HaproxyProxyName: ResourceAttributeConfig{Enabled: false},
  93. HaproxyServiceName: ResourceAttributeConfig{Enabled: false},
  94. },
  95. },
  96. },
  97. }
  98. for _, tt := range tests {
  99. t.Run(tt.name, func(t *testing.T) {
  100. cfg := loadMetricsBuilderConfig(t, tt.name)
  101. if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})); diff != "" {
  102. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  103. }
  104. })
  105. }
  106. }
  107. func loadMetricsBuilderConfig(t *testing.T, name string) MetricsBuilderConfig {
  108. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  109. require.NoError(t, err)
  110. sub, err := cm.Sub(name)
  111. require.NoError(t, err)
  112. cfg := DefaultMetricsBuilderConfig()
  113. require.NoError(t, component.UnmarshalConfig(sub, &cfg))
  114. return cfg
  115. }
  116. func TestResourceAttributesConfig(t *testing.T) {
  117. tests := []struct {
  118. name string
  119. want ResourceAttributesConfig
  120. }{
  121. {
  122. name: "default",
  123. want: DefaultResourceAttributesConfig(),
  124. },
  125. {
  126. name: "all_set",
  127. want: ResourceAttributesConfig{
  128. HaproxyAddr: ResourceAttributeConfig{Enabled: true},
  129. HaproxyProxyName: ResourceAttributeConfig{Enabled: true},
  130. HaproxyServiceName: ResourceAttributeConfig{Enabled: true},
  131. },
  132. },
  133. {
  134. name: "none_set",
  135. want: ResourceAttributesConfig{
  136. HaproxyAddr: ResourceAttributeConfig{Enabled: false},
  137. HaproxyProxyName: ResourceAttributeConfig{Enabled: false},
  138. HaproxyServiceName: ResourceAttributeConfig{Enabled: false},
  139. },
  140. },
  141. }
  142. for _, tt := range tests {
  143. t.Run(tt.name, func(t *testing.T) {
  144. cfg := loadResourceAttributesConfig(t, tt.name)
  145. if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" {
  146. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  147. }
  148. })
  149. }
  150. }
  151. func loadResourceAttributesConfig(t *testing.T, name string) ResourceAttributesConfig {
  152. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  153. require.NoError(t, err)
  154. sub, err := cm.Sub(name)
  155. require.NoError(t, err)
  156. sub, err = sub.Sub("resource_attributes")
  157. require.NoError(t, err)
  158. cfg := DefaultResourceAttributesConfig()
  159. require.NoError(t, component.UnmarshalConfig(sub, &cfg))
  160. return cfg
  161. }