Skip to content

Commit

Permalink
move validate code into its own method
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten committed Aug 15, 2023
1 parent 0a57365 commit 793ee53
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions service/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,19 @@ func (sp *SpanProcessor) Unmarshal(conf *confmap.Conf) error {
}

if sp.Batch != nil {
if sp.Batch.Exporter.Console == nil && sp.Batch.Exporter.Otlp == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
return sp.Batch.Exporter.Validate()
}
return fmt.Errorf("unsupported span processor type %s", conf.AllKeys())
}

// Validate checks for valid exporters to be configured for the SpanExporter
func (se *SpanExporter) Validate() error {
if se.Console == nil && se.Otlp == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
}

func (mr *MetricReader) Unmarshal(conf *confmap.Conf) error {
if !obsreportconfig.UseOtelWithSDKConfigurationForInternalTelemetryFeatureGate.IsEnabled() {
// only unmarshal if feature gate is enabled
Expand All @@ -173,17 +178,27 @@ func (mr *MetricReader) Unmarshal(conf *confmap.Conf) error {
}

if mr.Pull != nil {
if mr.Pull.Exporter.Prometheus == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
return mr.Pull.Validate()
}
if mr.Periodic != nil {
if mr.Periodic.Exporter.Otlp == nil && mr.Periodic.Exporter.Console == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
return mr.Periodic.Validate()
}

return fmt.Errorf("unsupported metric reader type %s", conf.AllKeys())
}

// Validate checks for valid exporters to be configured for the PullMetricReader
func (pmr *PullMetricReader) Validate() error {
if pmr.Exporter.Prometheus == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
}

// Validate checks for valid exporters to be configured for the PeriodicMetricReader
func (pmr *PeriodicMetricReader) Validate() error {
if pmr.Exporter.Otlp == nil && pmr.Exporter.Console == nil {
return fmt.Errorf("invalid exporter configuration")
}
return nil
}

0 comments on commit 793ee53

Please sign in to comment.