generated_config_test.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. OracledbConsistentGets: MetricConfig{Enabled: true},
  26. OracledbCPUTime: MetricConfig{Enabled: true},
  27. OracledbDbBlockGets: MetricConfig{Enabled: true},
  28. OracledbDmlLocksLimit: MetricConfig{Enabled: true},
  29. OracledbDmlLocksUsage: MetricConfig{Enabled: true},
  30. OracledbEnqueueDeadlocks: MetricConfig{Enabled: true},
  31. OracledbEnqueueLocksLimit: MetricConfig{Enabled: true},
  32. OracledbEnqueueLocksUsage: MetricConfig{Enabled: true},
  33. OracledbEnqueueResourcesLimit: MetricConfig{Enabled: true},
  34. OracledbEnqueueResourcesUsage: MetricConfig{Enabled: true},
  35. OracledbExchangeDeadlocks: MetricConfig{Enabled: true},
  36. OracledbExecutions: MetricConfig{Enabled: true},
  37. OracledbHardParses: MetricConfig{Enabled: true},
  38. OracledbLogicalReads: MetricConfig{Enabled: true},
  39. OracledbParseCalls: MetricConfig{Enabled: true},
  40. OracledbPgaMemory: MetricConfig{Enabled: true},
  41. OracledbPhysicalReads: MetricConfig{Enabled: true},
  42. OracledbProcessesLimit: MetricConfig{Enabled: true},
  43. OracledbProcessesUsage: MetricConfig{Enabled: true},
  44. OracledbSessionsLimit: MetricConfig{Enabled: true},
  45. OracledbSessionsUsage: MetricConfig{Enabled: true},
  46. OracledbTablespaceSizeLimit: MetricConfig{Enabled: true},
  47. OracledbTablespaceSizeUsage: MetricConfig{Enabled: true},
  48. OracledbTransactionsLimit: MetricConfig{Enabled: true},
  49. OracledbTransactionsUsage: MetricConfig{Enabled: true},
  50. OracledbUserCommits: MetricConfig{Enabled: true},
  51. OracledbUserRollbacks: MetricConfig{Enabled: true},
  52. },
  53. ResourceAttributes: ResourceAttributesConfig{
  54. OracledbInstanceName: ResourceAttributeConfig{Enabled: true},
  55. },
  56. },
  57. },
  58. {
  59. name: "none_set",
  60. want: MetricsBuilderConfig{
  61. Metrics: MetricsConfig{
  62. OracledbConsistentGets: MetricConfig{Enabled: false},
  63. OracledbCPUTime: MetricConfig{Enabled: false},
  64. OracledbDbBlockGets: MetricConfig{Enabled: false},
  65. OracledbDmlLocksLimit: MetricConfig{Enabled: false},
  66. OracledbDmlLocksUsage: MetricConfig{Enabled: false},
  67. OracledbEnqueueDeadlocks: MetricConfig{Enabled: false},
  68. OracledbEnqueueLocksLimit: MetricConfig{Enabled: false},
  69. OracledbEnqueueLocksUsage: MetricConfig{Enabled: false},
  70. OracledbEnqueueResourcesLimit: MetricConfig{Enabled: false},
  71. OracledbEnqueueResourcesUsage: MetricConfig{Enabled: false},
  72. OracledbExchangeDeadlocks: MetricConfig{Enabled: false},
  73. OracledbExecutions: MetricConfig{Enabled: false},
  74. OracledbHardParses: MetricConfig{Enabled: false},
  75. OracledbLogicalReads: MetricConfig{Enabled: false},
  76. OracledbParseCalls: MetricConfig{Enabled: false},
  77. OracledbPgaMemory: MetricConfig{Enabled: false},
  78. OracledbPhysicalReads: MetricConfig{Enabled: false},
  79. OracledbProcessesLimit: MetricConfig{Enabled: false},
  80. OracledbProcessesUsage: MetricConfig{Enabled: false},
  81. OracledbSessionsLimit: MetricConfig{Enabled: false},
  82. OracledbSessionsUsage: MetricConfig{Enabled: false},
  83. OracledbTablespaceSizeLimit: MetricConfig{Enabled: false},
  84. OracledbTablespaceSizeUsage: MetricConfig{Enabled: false},
  85. OracledbTransactionsLimit: MetricConfig{Enabled: false},
  86. OracledbTransactionsUsage: MetricConfig{Enabled: false},
  87. OracledbUserCommits: MetricConfig{Enabled: false},
  88. OracledbUserRollbacks: MetricConfig{Enabled: false},
  89. },
  90. ResourceAttributes: ResourceAttributesConfig{
  91. OracledbInstanceName: ResourceAttributeConfig{Enabled: false},
  92. },
  93. },
  94. },
  95. }
  96. for _, tt := range tests {
  97. t.Run(tt.name, func(t *testing.T) {
  98. cfg := loadMetricsBuilderConfig(t, tt.name)
  99. if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(MetricConfig{}, ResourceAttributeConfig{})); diff != "" {
  100. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  101. }
  102. })
  103. }
  104. }
  105. func loadMetricsBuilderConfig(t *testing.T, name string) MetricsBuilderConfig {
  106. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  107. require.NoError(t, err)
  108. sub, err := cm.Sub(name)
  109. require.NoError(t, err)
  110. cfg := DefaultMetricsBuilderConfig()
  111. require.NoError(t, component.UnmarshalConfig(sub, &cfg))
  112. return cfg
  113. }
  114. func TestResourceAttributesConfig(t *testing.T) {
  115. tests := []struct {
  116. name string
  117. want ResourceAttributesConfig
  118. }{
  119. {
  120. name: "default",
  121. want: DefaultResourceAttributesConfig(),
  122. },
  123. {
  124. name: "all_set",
  125. want: ResourceAttributesConfig{
  126. OracledbInstanceName: ResourceAttributeConfig{Enabled: true},
  127. },
  128. },
  129. {
  130. name: "none_set",
  131. want: ResourceAttributesConfig{
  132. OracledbInstanceName: ResourceAttributeConfig{Enabled: false},
  133. },
  134. },
  135. }
  136. for _, tt := range tests {
  137. t.Run(tt.name, func(t *testing.T) {
  138. cfg := loadResourceAttributesConfig(t, tt.name)
  139. if diff := cmp.Diff(tt.want, cfg, cmpopts.IgnoreUnexported(ResourceAttributeConfig{})); diff != "" {
  140. t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
  141. }
  142. })
  143. }
  144. }
  145. func loadResourceAttributesConfig(t *testing.T, name string) ResourceAttributesConfig {
  146. cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
  147. require.NoError(t, err)
  148. sub, err := cm.Sub(name)
  149. require.NoError(t, err)
  150. sub, err = sub.Sub("resource_attributes")
  151. require.NoError(t, err)
  152. cfg := DefaultResourceAttributesConfig()
  153. require.NoError(t, component.UnmarshalConfig(sub, &cfg))
  154. return cfg
  155. }