Skip to content

Commit

Permalink
remove IntHistogram (#4276)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Jul 20, 2021
1 parent ecd28ed commit c7d94c3
Show file tree
Hide file tree
Showing 30 changed files with 27 additions and 899 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,54 +202,6 @@ func doubleMetricsToLogs(name string, data pdata.DoubleDataPointSlice, defaultLa
return logs
}

func intHistogramMetricsToLogs(name string, data pdata.IntHistogramDataPointSlice, defaultLabels KeyValues) (logs []*sls.Log) {
for i := 0; i < data.Len(); i++ {
dataPoint := data.At(i)
labelsMap := dataPoint.LabelsMap()
labels := defaultLabels.Clone()
labelsMap.Range(func(k string, v string) bool {
labels.Append(k, v)
return true
})
logs = append(logs, newMetricLogFromRaw(name+"_sum",
labels,
int64(dataPoint.Timestamp()),
float64(dataPoint.Sum())))
logs = append(logs, newMetricLogFromRaw(name+"_count",
labels,
int64(dataPoint.Timestamp()),
float64(dataPoint.Count())))

bounds := dataPoint.ExplicitBounds()
boundsStr := make([]string, len(bounds)+1)
for i := 0; i < len(bounds); i++ {
boundsStr[i] = strconv.FormatFloat(bounds[i], 'g', -1, 64)
}
boundsStr[len(boundsStr)-1] = infinityBoundValue

bucketCount := min(len(boundsStr), len(dataPoint.BucketCounts()))

bucketLabels := labels.Clone()
bucketLabels.Append(bucketLabelKey, "")
bucketLabels.Sort()
for i := 0; i < bucketCount; i++ {
bucket := dataPoint.BucketCounts()[i]
bucketLabels.Replace(bucketLabelKey, boundsStr[i])

logs = append(
logs,
newMetricLogFromRaw(
name+"_bucket",
bucketLabels,
int64(dataPoint.Timestamp()),
float64(bucket),
))
}

}
return logs
}

func doubleHistogramMetricsToLogs(name string, data pdata.HistogramDataPointSlice, defaultLabels KeyValues) (logs []*sls.Log) {
for i := 0; i < data.Len(); i++ {
dataPoint := data.At(i)
Expand Down Expand Up @@ -346,8 +298,6 @@ func metricDataToLogServiceData(md pdata.Metric, defaultLabels KeyValues) (logs
return intMetricsToLogs(md.Name(), md.IntSum().DataPoints(), defaultLabels)
case pdata.MetricDataTypeSum:
return doubleMetricsToLogs(md.Name(), md.Sum().DataPoints(), defaultLabels)
case pdata.MetricDataTypeIntHistogram:
return intHistogramMetricsToLogs(md.Name(), md.IntHistogram().DataPoints(), defaultLabels)
case pdata.MetricDataTypeHistogram:
return doubleHistogramMetricsToLogs(md.Name(), md.Histogram().DataPoints(), defaultLabels)
case pdata.MetricDataTypeSummary:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ func TestMetricDataToLogService(t *testing.T) {
doubleSumDataPoint.SetValue(10.1)
doubleSumDataPoint.SetTimestamp(pdata.Timestamp(100_000_000))

intHistogramMetric := metrics.AppendEmpty()
intHistogramMetric.SetDataType(pdata.MetricDataTypeIntHistogram)
intHistogramMetric.SetName("double_histogram")
intHistogram := intHistogramMetric.IntHistogram()
intHistogramDataPoints := intHistogram.DataPoints()
intHistogramDataPoint := intHistogramDataPoints.AppendEmpty()
intHistogramDataPoint.LabelsMap().Insert("innerLabel", "innerValue")
intHistogramDataPoint.SetCount(2)
intHistogramDataPoint.SetSum(19)
intHistogramDataPoint.SetTimestamp(pdata.Timestamp(100_000_000))
intHistogramDataPoint.SetBucketCounts([]uint64{1, 2, 3})
intHistogramDataPoint.SetExplicitBounds([]float64{1, 2})

doubleHistogramMetric := metrics.AppendEmpty()
doubleHistogramMetric.SetDataType(pdata.MetricDataTypeHistogram)
doubleHistogramMetric.SetName("double_$histogram")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,96 +71,6 @@
"Value": "10.1"
}
],
[
{
"Key": "__name__",
"Value": "double_histogram_sum"
},
{
"Key": "__labels__",
"Value": "a#$#b|innerLabel#$#innerValue|labelA#$#valueA|labelB#$#valueB"
},
{
"Key": "__time_nano__",
"Value": "100000000"
},
{
"Key": "__value__",
"Value": "19"
}
],
[
{
"Key": "__name__",
"Value": "double_histogram_count"
},
{
"Key": "__labels__",
"Value": "a#$#b|innerLabel#$#innerValue|labelA#$#valueA|labelB#$#valueB"
},
{
"Key": "__time_nano__",
"Value": "100000000"
},
{
"Key": "__value__",
"Value": "2"
}
],
[
{
"Key": "__name__",
"Value": "double_histogram_bucket"
},
{
"Key": "__labels__",
"Value": "a#$#b|innerLabel#$#innerValue|labelA#$#valueA|labelB#$#valueB|le#$#1"
},
{
"Key": "__time_nano__",
"Value": "100000000"
},
{
"Key": "__value__",
"Value": "1"
}
],
[
{
"Key": "__name__",
"Value": "double_histogram_bucket"
},
{
"Key": "__labels__",
"Value": "a#$#b|innerLabel#$#innerValue|labelA#$#valueA|labelB#$#valueB|le#$#2"
},
{
"Key": "__time_nano__",
"Value": "100000000"
},
{
"Key": "__value__",
"Value": "2"
}
],
[
{
"Key": "__name__",
"Value": "double_histogram_bucket"
},
{
"Key": "__labels__",
"Value": "a#$#b|innerLabel#$#innerValue|labelA#$#valueA|labelB#$#valueB|le#$#+Inf"
},
{
"Key": "__time_nano__",
"Value": "100000000"
},
{
"Key": "__value__",
"Value": "3"
}
],
[
{
"Key": "__name__",
Expand Down
1 change: 0 additions & 1 deletion exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type dataPoint struct {
// dataPoints is a wrapper interface for:
// - pdata.intDataPointSlice
// - pdata.doubleDataPointSlice
// - pdata.IntHistogramDataPointSlice
// - pdata.histogramDataPointSlice
// - pdata.summaryDataPointSlice
type dataPoints interface {
Expand Down
4 changes: 2 additions & 2 deletions exporter/awsemfexporter/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func TestGetDataPoints(t *testing.T) {
metric := pdata.NewMetric()
metric.SetName("foo")
metric.SetUnit("Count")
metric.SetDataType(pdata.MetricDataTypeIntHistogram)
metric.SetDataType(pdata.MetricDataTypeNone)

obs, logs := observer.New(zap.WarnLevel)
logger := zap.New(obs)
Expand All @@ -712,7 +712,7 @@ func TestGetDataPoints(t *testing.T) {
{
Entry: zapcore.Entry{Level: zap.WarnLevel, Message: "Unhandled metric data type."},
Context: []zapcore.Field{
zap.String("DataType", "IntHistogram"),
zap.String("DataType", "None"),
zap.String("Name", "foo"),
zap.String("Unit", "Count"),
},
Expand Down
4 changes: 2 additions & 2 deletions exporter/awsemfexporter/grouped_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func TestAddToGroupedMetric(t *testing.T) {
metric := rms.AppendEmpty().InstrumentationLibraryMetrics().AppendEmpty().Metrics().AppendEmpty()
metric.SetName("foo")
metric.SetUnit("Count")
metric.SetDataType(pdata.MetricDataTypeIntHistogram)
metric.SetDataType(pdata.MetricDataTypeNone)

obs, logs := observer.New(zap.WarnLevel)
obsLogger := zap.New(obs)
Expand All @@ -415,7 +415,7 @@ func TestAddToGroupedMetric(t *testing.T) {
{
Entry: zapcore.Entry{Level: zap.WarnLevel, Message: "Unhandled metric data type."},
Context: []zapcore.Field{
zap.String("DataType", "IntHistogram"),
zap.String("DataType", "None"),
zap.String("Name", "foo"),
zap.String("Unit", "Count"),
},
Expand Down
15 changes: 7 additions & 8 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ const (
)

var fieldPrometheusTypes = map[pdata.MetricDataType]string{
pdata.MetricDataTypeNone: "",
pdata.MetricDataTypeIntGauge: "gauge",
pdata.MetricDataTypeGauge: "gauge",
pdata.MetricDataTypeIntSum: "counter",
pdata.MetricDataTypeSum: "counter",
pdata.MetricDataTypeIntHistogram: "histogram",
pdata.MetricDataTypeHistogram: "histogram",
pdata.MetricDataTypeSummary: "summary",
pdata.MetricDataTypeNone: "",
pdata.MetricDataTypeIntGauge: "gauge",
pdata.MetricDataTypeGauge: "gauge",
pdata.MetricDataTypeIntSum: "counter",
pdata.MetricDataTypeSum: "counter",
pdata.MetricDataTypeHistogram: "histogram",
pdata.MetricDataTypeSummary: "summary",
}

type cWMetrics struct {
Expand Down
36 changes: 1 addition & 35 deletions exporter/datadogexporter/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func mapDoubleMonotonicMetrics(name string, prevPts *ttlmap.TTLMap, slice pdata.
return ms
}

// mapIntHistogramMetrics maps histogram metrics slices to Datadog metrics
// mapHistogramMetrics maps double histogram metrics slices to Datadog metrics
//
// A Histogram metric has:
// - The count of values in the population
Expand All @@ -191,38 +191,6 @@ func mapDoubleMonotonicMetrics(name string, prevPts *ttlmap.TTLMap, slice pdata.
// We follow a similar approach to our OpenCensus exporter:
// we report sum and count by default; buckets count can also
// be reported (opt-in), but bounds are ignored.
func mapIntHistogramMetrics(name string, slice pdata.IntHistogramDataPointSlice, buckets bool, attrTags []string) []datadog.Metric {
// Allocate assuming none are nil and no buckets
ms := make([]datadog.Metric, 0, 2*slice.Len())
for i := 0; i < slice.Len(); i++ {
p := slice.At(i)
ts := uint64(p.Timestamp())
tags := getTags(p.LabelsMap())
tags = append(tags, attrTags...)

ms = append(ms,
metrics.NewGauge(fmt.Sprintf("%s.count", name), ts, float64(p.Count()), tags),
metrics.NewGauge(fmt.Sprintf("%s.sum", name), ts, float64(p.Sum()), tags),
)

if buckets {
// We have a single metric, 'count_per_bucket', which is tagged with the bucket id. See:
// https://github.com/DataDog/opencensus-go-exporter-datadog/blob/c3b47f1c6dcf1c47b59c32e8dbb7df5f78162daa/stats.go#L99-L104
fullName := fmt.Sprintf("%s.count_per_bucket", name)
for idx, count := range p.BucketCounts() {
bucketTags := append(tags, fmt.Sprintf("bucket_idx:%d", idx))
ms = append(ms,
metrics.NewGauge(fullName, ts, float64(count), bucketTags),
)
}
}
}
return ms
}

// mapIntHistogramMetrics maps double histogram metrics slices to Datadog metrics
//
// see mapIntHistogramMetrics docs for further details.
func mapHistogramMetrics(name string, slice pdata.HistogramDataPointSlice, buckets bool, attrTags []string) []datadog.Metric {
// Allocate assuming none are nil and no buckets
ms := make([]datadog.Metric, 0, 2*slice.Len())
Expand Down Expand Up @@ -344,8 +312,6 @@ func mapMetrics(logger *zap.Logger, cfg config.MetricsConfig, prevPts *ttlmap.TT
} else {
datapoints = mapDoubleMetrics(md.Name(), md.Sum().DataPoints(), attributeTags)
}
case pdata.MetricDataTypeIntHistogram:
datapoints = mapIntHistogramMetrics(md.Name(), md.IntHistogram().DataPoints(), cfg.Buckets, attributeTags)
case pdata.MetricDataTypeHistogram:
datapoints = mapHistogramMetrics(md.Name(), md.Histogram().DataPoints(), cfg.Buckets, attributeTags)
case pdata.MetricDataTypeSummary:
Expand Down
64 changes: 0 additions & 64 deletions exporter/datadogexporter/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,57 +415,6 @@ func TestMapDoubleMonotonicOutOfOrder(t *testing.T) {
)
}

func TestMapIntHistogramMetrics(t *testing.T) {
ts := pdata.TimestampFromTime(time.Now())
slice := pdata.NewIntHistogramDataPointSlice()
point := slice.AppendEmpty()
point.SetCount(20)
point.SetSum(200)
point.SetBucketCounts([]uint64{2, 18})
point.SetTimestamp(ts)

noBuckets := []datadog.Metric{
metrics.NewGauge("intHist.test.count", uint64(ts), 20, []string{}),
metrics.NewGauge("intHist.test.sum", uint64(ts), 200, []string{}),
}

buckets := []datadog.Metric{
metrics.NewGauge("intHist.test.count_per_bucket", uint64(ts), 2, []string{"bucket_idx:0"}),
metrics.NewGauge("intHist.test.count_per_bucket", uint64(ts), 18, []string{"bucket_idx:1"}),
}

assert.ElementsMatch(t,
mapIntHistogramMetrics("intHist.test", slice, false, []string{}), // No buckets
noBuckets,
)

assert.ElementsMatch(t,
mapIntHistogramMetrics("intHist.test", slice, true, []string{}), // buckets
append(noBuckets, buckets...),
)

// With attribute tags
noBucketsAttributeTags := []datadog.Metric{
metrics.NewGauge("intHist.test.count", uint64(ts), 20, []string{"attribute_tag:attribute_value"}),
metrics.NewGauge("intHist.test.sum", uint64(ts), 200, []string{"attribute_tag:attribute_value"}),
}

bucketsAttributeTags := []datadog.Metric{
metrics.NewGauge("intHist.test.count_per_bucket", uint64(ts), 2, []string{"attribute_tag:attribute_value", "bucket_idx:0"}),
metrics.NewGauge("intHist.test.count_per_bucket", uint64(ts), 18, []string{"attribute_tag:attribute_value", "bucket_idx:1"}),
}

assert.ElementsMatch(t,
mapIntHistogramMetrics("intHist.test", slice, false, []string{"attribute_tag:attribute_value"}), // No buckets
noBucketsAttributeTags,
)

assert.ElementsMatch(t,
mapIntHistogramMetrics("intHist.test", slice, true, []string{"attribute_tag:attribute_value"}), // buckets
append(noBucketsAttributeTags, bucketsAttributeTags...),
)
}

func TestMapHistogramMetrics(t *testing.T) {
ts := pdata.TimestampFromTime(time.Now())
slice := pdata.NewHistogramDataPointSlice()
Expand Down Expand Up @@ -702,17 +651,6 @@ func createTestMetrics() pdata.Metrics {
dpDouble.SetTimestamp(seconds(0))
dpDouble.SetValue(math.E)

// IntHistogram
met = metricsArray.AppendEmpty()
met.SetName("int.histogram")
met.SetDataType(pdata.MetricDataTypeIntHistogram)
dpsIntHist := met.IntHistogram().DataPoints()
dpIntHist := dpsIntHist.AppendEmpty()
dpIntHist.SetCount(20)
dpIntHist.SetSum(100)
dpIntHist.SetBucketCounts([]uint64{2, 18})
dpIntHist.SetTimestamp(seconds(0))

// Histogram
met = metricsArray.AppendEmpty()
met.SetName("double.histogram")
Expand Down Expand Up @@ -803,8 +741,6 @@ func TestMapMetrics(t *testing.T) {
testGauge("double.gauge", math.Pi),
testGauge("int.sum", 2),
testGauge("double.sum", math.E),
testGauge("int.histogram.sum", 100),
testGauge("int.histogram.count", 20),
testGauge("double.histogram.sum", math.Phi),
testGauge("double.histogram.count", 20),
testGauge("summary.sum", 10_000),
Expand Down
2 changes: 0 additions & 2 deletions exporter/dynatraceexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func (e *exporter) serializeMetrics(md pdata.Metrics) ([]string, int) {
l = serialization.SerializeIntDataPoints(name, metric.IntSum().DataPoints(), e.cfg.Tags)
case pdata.MetricDataTypeSum:
l = serialization.SerializeDoubleDataPoints(name, metric.Sum().DataPoints(), e.cfg.Tags)
case pdata.MetricDataTypeIntHistogram:
l = serialization.SerializeIntHistogramMetrics(name, metric.IntHistogram().DataPoints(), e.cfg.Tags)
case pdata.MetricDataTypeHistogram:
l = serialization.SerializeHistogramMetrics(name, metric.Histogram().DataPoints(), e.cfg.Tags)
}
Expand Down
Loading

0 comments on commit c7d94c3

Please sign in to comment.