Skip to content

Commit

Permalink
Use profiledefinition validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dplepage-dd committed Dec 19, 2024
1 parent 30ad6fb commit 68be192
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
5 changes: 2 additions & 3 deletions pkg/collector/corechecks/snmp/internal/checkconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/snmp/snmpintegration"
"github.com/DataDog/datadog-agent/pkg/snmp/utils"

"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/configvalidation"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/profile"
)

Expand Down Expand Up @@ -460,8 +459,8 @@ func NewCheckConfig(rawInstance integration.Data, rawInitConfig integration.Data
c.RequestedMetrics = append(c.RequestedMetrics, uptimeMetricConfig)
profiledefinition.NormalizeMetrics(c.RequestedMetrics)
c.RequestedMetricTags = instance.MetricTags
errors := configvalidation.ValidateEnrichMetrics(c.RequestedMetrics)
errors = append(errors, configvalidation.ValidateEnrichMetricTags(c.RequestedMetricTags)...)
errors := profiledefinition.ValidateEnrichMetrics(c.RequestedMetrics)
errors = append(errors, profiledefinition.ValidateEnrichMetricTags(c.RequestedMetricTags)...)
if len(errors) > 0 {
return nil, fmt.Errorf("validation errors: %s", strings.Join(errors, "\n"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/networkdevice/profile/profiledefinition"
"github.com/DataDog/datadog-agent/pkg/networkdevice/utils"
"github.com/DataDog/datadog-agent/pkg/util/log"

"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/configvalidation"
)

var (
Expand Down Expand Up @@ -46,9 +44,9 @@ func loadResolveProfiles(pConfig ProfileConfigMap, defaultProfiles ProfileConfig
continue
}
profiledefinition.NormalizeMetrics(newProfileConfig.Definition.Metrics)
errors := configvalidation.ValidateEnrichMetadata(newProfileConfig.Definition.Metadata)
errors = append(errors, configvalidation.ValidateEnrichMetrics(newProfileConfig.Definition.Metrics)...)
errors = append(errors, configvalidation.ValidateEnrichMetricTags(newProfileConfig.Definition.MetricTags)...)
errors := profiledefinition.ValidateEnrichMetadata(newProfileConfig.Definition.Metadata)
errors = append(errors, profiledefinition.ValidateEnrichMetrics(newProfileConfig.Definition.Metrics)...)
errors = append(errors, profiledefinition.ValidateEnrichMetricTags(newProfileConfig.Definition.MetricTags)...)
if len(errors) > 0 {
log.Warnf("validation errors in profile %q: %s", name, strings.Join(errors, "\n"))
profileExpVar.Set(name, expvar.Func(func() interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/DataDog/datadog-agent/pkg/networkdevice/profile/profiledefinition"

"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/configvalidation"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/valuestore"
)

Expand Down Expand Up @@ -646,7 +645,7 @@ func Test_metricSender_getCheckInstanceMetricTags(t *testing.T) {
mockSender := mocksender.NewMockSender("foo")
metricSender := MetricSender{sender: mockSender}

configvalidation.ValidateEnrichMetricTags(tt.metricsTags)
profiledefinition.ValidateEnrichMetricTags(tt.metricsTags)
tags := metricSender.GetCheckInstanceMetricTags(tt.metricsTags, tt.values)

assert.ElementsMatch(t, tt.expectedTags, tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/networkdevice/profile/profiledefinition"
"github.com/DataDog/datadog-agent/pkg/snmp/snmpintegration"

"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/configvalidation"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/snmp/internal/valuestore"
)

Expand Down Expand Up @@ -778,7 +777,7 @@ metric_tags:
m := profiledefinition.MetricsConfig{}
yaml.Unmarshal(tt.rawMetricConfig, &m)

configvalidation.ValidateEnrichMetrics([]profiledefinition.MetricsConfig{m})
profiledefinition.ValidateEnrichMetrics([]profiledefinition.MetricsConfig{m})
tags := getTagsFromMetricTagConfigList(m.MetricTags, tt.fullIndex, tt.values)

assert.ElementsMatch(t, tt.expectedTags, tags)
Expand Down

0 comments on commit 68be192

Please sign in to comment.