forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pkg/otlp/model] Move code from contrib repository (DataDog#9239)
* [exporter/datadogexporter] Copy main branch contents * Decouple translator configuration from Collector configuration (open-telemetry/opentelemetry-collector-contrib#5270) * Use a `Consumer` interface for decoupling from zorkian's package (open-telemetry/opentelemetry-collector-contrib#5315) * Make tests pass
- Loading branch information
Showing
9 changed files
with
2,146 additions
and
1 deletion.
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
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,142 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package translator | ||
|
||
import "fmt" | ||
|
||
type translatorConfig struct { | ||
// metrics export behavior | ||
HistMode HistogramMode | ||
SendCountSum bool | ||
Quantiles bool | ||
SendMonotonic bool | ||
ResourceAttributesAsTags bool | ||
|
||
// cache configuration | ||
sweepInterval int64 | ||
deltaTTL int64 | ||
|
||
// hostname provider configuration | ||
fallbackHostnameProvider HostnameProvider | ||
} | ||
|
||
// Option is a translator creation option. | ||
type Option func(*translatorConfig) error | ||
|
||
// WithDeltaTTL sets the delta TTL for cumulative metrics datapoints. | ||
// By default, 3600 seconds are used. | ||
func WithDeltaTTL(deltaTTL int64) Option { | ||
return func(t *translatorConfig) error { | ||
if deltaTTL <= 0 { | ||
return fmt.Errorf("time to live must be positive: %d", deltaTTL) | ||
} | ||
t.deltaTTL = deltaTTL | ||
t.sweepInterval = 1 | ||
if t.deltaTTL > 1 { | ||
t.sweepInterval = t.deltaTTL / 2 | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithFallbackHostnameProvider sets the fallback hostname provider. | ||
// By default, an empty hostname is used as a fallback. | ||
func WithFallbackHostnameProvider(provider HostnameProvider) Option { | ||
return func(t *translatorConfig) error { | ||
t.fallbackHostnameProvider = provider | ||
return nil | ||
} | ||
} | ||
|
||
// WithQuantiles enables quantiles exporting for summary metrics. | ||
func WithQuantiles() Option { | ||
return func(t *translatorConfig) error { | ||
t.Quantiles = true | ||
return nil | ||
} | ||
} | ||
|
||
// WithResourceAttributesAsTags sets resource attributes as tags. | ||
func WithResourceAttributesAsTags() Option { | ||
return func(t *translatorConfig) error { | ||
t.ResourceAttributesAsTags = true | ||
return nil | ||
} | ||
} | ||
|
||
// HistogramMode is an export mode for OTLP Histogram metrics. | ||
type HistogramMode string | ||
|
||
const ( | ||
// HistogramModeNoBuckets disables bucket export. | ||
HistogramModeNoBuckets HistogramMode = "nobuckets" | ||
// HistogramModeCounters exports buckets as Datadog counts. | ||
HistogramModeCounters HistogramMode = "counters" | ||
// HistogramModeDistributions exports buckets as Datadog distributions. | ||
HistogramModeDistributions HistogramMode = "distributions" | ||
) | ||
|
||
// WithHistogramMode sets the histograms mode. | ||
// The default mode is HistogramModeOff. | ||
func WithHistogramMode(mode HistogramMode) Option { | ||
return func(t *translatorConfig) error { | ||
|
||
switch mode { | ||
case HistogramModeNoBuckets, HistogramModeCounters: | ||
t.HistMode = mode | ||
default: | ||
return fmt.Errorf("unknown histogram mode: %q", mode) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithCountSumMetrics exports .count and .sum histogram metrics. | ||
func WithCountSumMetrics() Option { | ||
return func(t *translatorConfig) error { | ||
t.SendCountSum = true | ||
return nil | ||
} | ||
} | ||
|
||
// NumberMode is an export mode for OTLP Number metrics. | ||
type NumberMode string | ||
|
||
const ( | ||
// NumberModeCumulativeToDelta calculates delta for | ||
// cumulative monotonic metrics in the client side and reports | ||
// them as Datadog counts. | ||
NumberModeCumulativeToDelta NumberMode = "cumulative_to_delta" | ||
|
||
// NumberModeRawValue reports the raw value for cumulative monotonic | ||
// metrics as a Datadog gauge. | ||
NumberModeRawValue NumberMode = "raw_value" | ||
) | ||
|
||
// WithNumberMode sets the number mode. | ||
// The default mode is NumberModeCumulativeToDelta. | ||
func WithNumberMode(mode NumberMode) Option { | ||
return func(t *translatorConfig) error { | ||
switch mode { | ||
case NumberModeCumulativeToDelta: | ||
t.SendMonotonic = true | ||
case NumberModeRawValue: | ||
t.SendMonotonic = false | ||
default: | ||
return fmt.Errorf("unknown number mode: %q", mode) | ||
} | ||
return nil | ||
} | ||
} |
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,71 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package translator | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/quantile" | ||
) | ||
|
||
// MetricDataType is a timeseries-style metric type. | ||
type MetricDataType int | ||
|
||
const ( | ||
// Gauge is the Datadog Gauge metric type. | ||
Gauge MetricDataType = iota | ||
// Count is the Datadog Count metric type. | ||
Count | ||
) | ||
|
||
// TimeSeriesConsumer is timeseries consumer. | ||
type TimeSeriesConsumer interface { | ||
// ConsumeTimeSeries consumes a timeseries-style metric. | ||
ConsumeTimeSeries( | ||
ctx context.Context, | ||
name string, | ||
typ MetricDataType, | ||
timestamp uint64, | ||
value float64, | ||
tags []string, | ||
host string, | ||
) | ||
} | ||
|
||
// SketchConsumer is a pkg/quantile sketch consumer. | ||
type SketchConsumer interface { | ||
// ConsumeSketch consumes a pkg/quantile-style sketch. | ||
ConsumeSketch( | ||
ctx context.Context, | ||
name string, | ||
timestamp uint64, | ||
sketch *quantile.Sketch, | ||
tags []string, | ||
host string, | ||
) | ||
} | ||
|
||
// Consumer is a metrics consumer. | ||
type Consumer interface { | ||
TimeSeriesConsumer | ||
SketchConsumer | ||
} | ||
|
||
// HostConsumer is a hostname consumer. | ||
// It is an optional interface that can be implemented by a Consumer. | ||
type HostConsumer interface { | ||
// ConsumeHost consumes a hostname. | ||
ConsumeHost(host string) | ||
} |
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,31 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package translator | ||
|
||
import "context" | ||
|
||
// HostnameProvider gets a hostname | ||
type HostnameProvider interface { | ||
// Hostname gets the hostname from the machine. | ||
Hostname(ctx context.Context) (string, error) | ||
} | ||
|
||
var _ HostnameProvider = (*noHostProvider)(nil) | ||
|
||
type noHostProvider struct{} | ||
|
||
func (*noHostProvider) Hostname(context.Context) (string, error) { | ||
return "", nil | ||
} |
Oops, something went wrong.