-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Boten <[email protected]>
- Loading branch information
Alex Boten
committed
Aug 21, 2023
1 parent
9ac039a
commit d25025f
Showing
6 changed files
with
1,016 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package config // import "go.opentelemetry.io/contrib/config" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/confmap" | ||
) | ||
|
||
func (sp *SpanProcessor) Unmarshal(conf *confmap.Conf) error { | ||
if conf == nil { | ||
return nil | ||
} | ||
|
||
if err := conf.Unmarshal(sp); err != nil { | ||
return fmt.Errorf("invalid span processor configuration: %w", err) | ||
} | ||
|
||
if sp.Batch != 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 conf == nil { | ||
return nil | ||
} | ||
|
||
if err := conf.Unmarshal(mr); err != nil { | ||
return fmt.Errorf("invalid metric reader configuration: %w", err) | ||
} | ||
|
||
if mr.Pull != nil { | ||
return mr.Pull.Validate() | ||
} | ||
if mr.Periodic != 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 | ||
} | ||
|
||
func (v *View) Unmarshal(conf *confmap.Conf) error { | ||
if conf == nil { | ||
return nil | ||
} | ||
|
||
if err := conf.Unmarshal(v); err != nil { | ||
return fmt.Errorf("invalid view configuration: %w", err) | ||
} | ||
|
||
return v.Validate() | ||
} | ||
|
||
func (v *View) Validate() error { | ||
if v.Selector == nil || v.Stream == nil { | ||
return fmt.Errorf("invalid view configuration") | ||
} | ||
return nil | ||
} | ||
|
||
func (s *ViewSelector) InstrumentNameStr() string { | ||
if s.InstrumentName == nil { | ||
return "" | ||
} | ||
return *s.InstrumentName | ||
} | ||
|
||
func (s *ViewSelector) InstrumentTypeStr() string { | ||
if s.InstrumentType == nil { | ||
return "" | ||
} | ||
return *s.InstrumentType | ||
} | ||
|
||
func (s *ViewSelector) MeterNameStr() string { | ||
if s.MeterName == nil { | ||
return "" | ||
} | ||
return *s.MeterName | ||
} | ||
|
||
func (s *ViewSelector) MeterVersionStr() string { | ||
if s.MeterVersion == nil { | ||
return "" | ||
} | ||
return *s.MeterVersion | ||
} | ||
|
||
func (s *ViewSelector) MeterSchemaUrlStr() string { | ||
if s.MeterSchemaUrl == nil { | ||
return "" | ||
} | ||
return *s.MeterSchemaUrl | ||
} | ||
|
||
func (s *ViewStream) NameStr() string { | ||
if s.Name == nil { | ||
return "" | ||
} | ||
return *s.Name | ||
} | ||
|
||
func (s *ViewStream) DescriptionStr() string { | ||
if s.Description == nil { | ||
return "" | ||
} | ||
return *s.Description | ||
} | ||
|
||
func (e *ViewStreamAggregationExplicitBucketHistogram) RecordMinMaxBool() bool { | ||
if e.RecordMinMax == nil { | ||
return false | ||
} | ||
return *e.RecordMinMax | ||
} |
Oops, something went wrong.