Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/datadog] Replace HistogramMode defined as string with enum #9589

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### 🛑 Breaking changes 🛑

- `datadogexporter`: Replace HistogramMode defined as string with enum.

### 🚩 Deprecations 🚩

- `exporter/azuremonitor`: Deprecate use of LogRecord.Name as the log envelope category name. There is no replacement.
Expand Down
37 changes: 27 additions & 10 deletions exporter/datadogexporter/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ var (
errNoMetadata = errors.New("only_metadata can't be enabled when host_metadata::enabled = false or host_metadata::hostname_source != first_resource")
)

// TODO: Import these from translator when we eliminate cyclic dependency.
const (
histogramModeNoBuckets = "nobuckets"
histogramModeCounters = "counters"
histogramModeDistributions = "distributions"
)

const (
// DefaultSite is the default site of the Datadog intake to send data to
DefaultSite = "datadoghq.com"
Expand Down Expand Up @@ -93,6 +86,30 @@ type MetricsConfig struct {
SummaryConfig SummaryConfig `mapstructure:"summaries"`
}

type HistogramMode string

const (
// HistogramModeNoBuckets reports no bucket histogram metrics. .sum and .count metrics will still be sent
// if `send_count_sum_metrics` is enabled.
HistogramModeNoBuckets HistogramMode = "nobuckets"
// HistogramModeCounters reports histograms as Datadog counts, one metric per bucket.
HistogramModeCounters HistogramMode = "counters"
// HistogramModeDistributions reports histograms as Datadog distributions (recommended).
HistogramModeDistributions HistogramMode = "distributions"
)

var _ encoding.TextUnmarshaler = (*HistogramMode)(nil)

func (hm *HistogramMode) UnmarshalText(in []byte) error {
switch mode := HistogramMode(in); mode {
case HistogramModeCounters, HistogramModeDistributions, HistogramModeNoBuckets:
*hm = mode
return nil
default:
return fmt.Errorf("invalid histogram mode %q", mode)
}
}

// HistogramConfig customizes export of OTLP Histograms.
type HistogramConfig struct {
// Mode for exporting histograms. Valid values are 'distributions', 'counters' or 'nobuckets'.
Expand All @@ -102,15 +119,15 @@ type HistogramConfig struct {
// if `send_count_sum_metrics` is enabled.
//
// The current default is 'distributions'.
Mode string `mapstructure:"mode"`
Mode HistogramMode `mapstructure:"mode"`

// SendCountSum states if the export should send .sum and .count metrics for histograms.
// The current default is false.
SendCountSum bool `mapstructure:"send_count_sum_metrics"`
}

func (c *HistogramConfig) validate() error {
if c.Mode == histogramModeNoBuckets && !c.SendCountSum {
if c.Mode == HistogramModeNoBuckets && !c.SendCountSum {
return fmt.Errorf("'nobuckets' mode and `send_count_sum_metrics` set to false will send no histogram metrics")
}
return nil
Expand Down Expand Up @@ -499,7 +516,7 @@ func (c *Config) Unmarshal(configMap *config.Map) error {
c.warnings = append(c.warnings, renamingWarnings...)

switch c.Metrics.HistConfig.Mode {
case histogramModeCounters, histogramModeNoBuckets, histogramModeDistributions:
case HistogramModeCounters, HistogramModeNoBuckets, HistogramModeDistributions:
keisku marked this conversation as resolved.
Show resolved Hide resolved
// Do nothing
default:
return fmt.Errorf("invalid `mode` %s", c.Metrics.HistConfig.Mode)
Expand Down
3 changes: 1 addition & 2 deletions exporter/datadogexporter/metrics_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/model/translator"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/testutils"
)

Expand All @@ -44,7 +43,7 @@ func TestNewExporter(t *testing.T) {
},
DeltaTTL: 3600,
HistConfig: config.HistogramConfig{
Mode: string(translator.HistogramModeDistributions),
Mode: config.HistogramModeDistributions,
SendCountSum: false,
},
SumConfig: config.SumConfig{
Expand Down