@@ -66,6 +66,7 @@ func TestLoadTargetAllocatorConfig(t *testing.T) {
66
66
sub , err := cm .Sub (component .NewIDWithName (metadata .Type , "" ).String ())
67
67
require .NoError (t , err )
68
68
require .NoError (t , component .UnmarshalConfig (sub , cfg ))
69
+ require .NoError (t , component .ValidateConfig (cfg ))
69
70
70
71
r0 := cfg .(* Config )
71
72
assert .NotNil (t , r0 .PrometheusConfig )
@@ -77,6 +78,7 @@ func TestLoadTargetAllocatorConfig(t *testing.T) {
77
78
require .NoError (t , err )
78
79
cfg = factory .CreateDefaultConfig ()
79
80
require .NoError (t , component .UnmarshalConfig (sub , cfg ))
81
+ require .NoError (t , component .ValidateConfig (cfg ))
80
82
81
83
r1 := cfg .(* Config )
82
84
assert .NotNil (t , r0 .PrometheusConfig )
@@ -92,6 +94,7 @@ func TestLoadTargetAllocatorConfig(t *testing.T) {
92
94
require .NoError (t , err )
93
95
cfg = factory .CreateDefaultConfig ()
94
96
require .NoError (t , component .UnmarshalConfig (sub , cfg ))
97
+ require .NoError (t , component .ValidateConfig (cfg ))
95
98
96
99
r2 := cfg .(* Config )
97
100
assert .Equal (t , 1 , len (r2 .PrometheusConfig .ScrapeConfigs ))
@@ -110,6 +113,36 @@ func TestLoadConfigFailsOnUnknownSection(t *testing.T) {
110
113
require .Error (t , component .UnmarshalConfig (sub , cfg ))
111
114
}
112
115
116
+ func TestLoadConfigFailsOnNoPrometheusOrTAConfig (t * testing.T ) {
117
+ cm , err := confmaptest .LoadConf (filepath .Join ("testdata" , "invalid-config-prometheus-non-existent-scrape-config.yaml" ))
118
+ require .NoError (t , err )
119
+ factory := NewFactory ()
120
+
121
+ cfg := factory .CreateDefaultConfig ()
122
+ sub , err := cm .Sub (component .NewIDWithName (metadata .Type , "" ).String ())
123
+ require .NoError (t , err )
124
+ require .NoError (t , component .UnmarshalConfig (sub , cfg ))
125
+ require .ErrorContains (t , component .ValidateConfig (cfg ), "no Prometheus scrape_configs or target_allocator set" )
126
+
127
+ cfg = factory .CreateDefaultConfig ()
128
+ sub , err = cm .Sub (component .NewIDWithName (metadata .Type , "withConfigAndTA" ).String ())
129
+ require .NoError (t , err )
130
+ require .NoError (t , component .UnmarshalConfig (sub , cfg ))
131
+ require .NoError (t , component .ValidateConfig (cfg ))
132
+
133
+ cfg = factory .CreateDefaultConfig ()
134
+ sub , err = cm .Sub (component .NewIDWithName (metadata .Type , "withOnlyTA" ).String ())
135
+ require .NoError (t , err )
136
+ require .NoError (t , component .UnmarshalConfig (sub , cfg ))
137
+ require .NoError (t , component .ValidateConfig (cfg ))
138
+
139
+ cfg = factory .CreateDefaultConfig ()
140
+ sub , err = cm .Sub (component .NewIDWithName (metadata .Type , "withOnlyScrape" ).String ())
141
+ require .NoError (t , err )
142
+ require .NoError (t , component .UnmarshalConfig (sub , cfg ))
143
+ require .NoError (t , component .ValidateConfig (cfg ))
144
+ }
145
+
113
146
// As one of the config parameters is consuming prometheus
114
147
// configuration as a subkey, ensure that invalid configuration
115
148
// within the subkey will also raise an error.
0 commit comments