Skip to content

Commit 98fd75f

Browse files
authored
Apply the right Validate() func to emfexporter and k8sobserver so config.Validate from core can get compiled (#3020)
As we're adding `validatable` interface to `config.processor | extension | exporter` in core package. `Contrib` package is failed to be built due to the following errors. This PR is to fix the ambiguous Config.Validate errors. ``` exporter/awsemfexporter/factory.go:40:9: cannot use &Config literal (type *Config) as type config.Exporter in return argument: *Config does not implement config.Exporter (wrong type for Validate method) have Validate() want Validate() error extension/observer/k8sobserver/factory.go:64:15: Config.Validate is ambiguous ``` **Link to tracking Issue:** open-telemetry/opentelemetry-collector#2898
1 parent 7bc3c71 commit 98fd75f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

exporter/awsemfexporter/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type MetricDescriptor struct {
9797
}
9898

9999
// Validate filters out invalid metricDeclarations and metricDescriptors
100-
func (config *Config) Validate() {
100+
func (config *Config) Validate() error {
101101
validDeclarations := []*MetricDeclaration{}
102102
for _, declaration := range config.MetricDeclarations {
103103
err := declaration.Init(config.logger)
@@ -121,6 +121,7 @@ func (config *Config) Validate() {
121121
}
122122
}
123123
config.MetricDescriptors = validDescriptors
124+
return nil
124125
}
125126

126127
func newEMFSupportedUnits() map[string]interface{} {

extension/observer/k8sobserver/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ type Config struct {
3737
// Then set this value to ${K8S_NODE_NAME} in the configuration.
3838
Node string `mapstructure:"node"`
3939
}
40+
41+
// Validate checks if the extension configuration is valid
42+
func (cfg *Config) Validate() error {
43+
return cfg.APIConfig.Validate()
44+
}

extension/observer/k8sobserver/config_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,21 @@ func TestLoadConfig(t *testing.T) {
5555
},
5656
ext1)
5757
}
58+
59+
func TestValidate(t *testing.T) {
60+
cfg := &Config{
61+
ExtensionSettings: &config.ExtensionSettings{
62+
TypeVal: "k8s_observer",
63+
NameVal: "k8s_observer/1",
64+
},
65+
Node: "node-1",
66+
APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeKubeConfig},
67+
}
68+
69+
err := cfg.Validate()
70+
require.Nil(t, err)
71+
72+
cfg.APIConfig.AuthType = "invalid"
73+
err = cfg.Validate()
74+
require.NotNil(t, err)
75+
}

0 commit comments

Comments
 (0)