Skip to content

Explicit histograms with zero buckets results in an error log #44022

@lahsivjar

Description

@lahsivjar

Component(s)

exporter/elasticsearch

What happened?

Description

As per the histogram specs, buckets is optional, however, ES expoter results in an error invalid data point on an histogram with empty bucket.

Steps to Reproduce

func TestHistogramValue(t *testing.T) {
	for _, tc := range []struct {
		name        string
		histogramDP pmetric.HistogramDataPoint
		expected    func(t *testing.T) pcommon.Value
	}{
		{
			name: "required_fields_only",
			histogramDP: func() pmetric.HistogramDataPoint {
				now := time.Now()
				dp := pmetric.NewHistogramDataPoint()
				dp.SetStartTimestamp(pcommon.NewTimestampFromTime(now.Add(-1 * time.Hour)))
				dp.SetTimestamp(pcommon.NewTimestampFromTime(now))
				dp.SetCount(100)
				dp.SetSum(1000)
				return dp
			}(),
			expected: func(t *testing.T) pcommon.Value {
				t.Helper()
				v := pcommon.NewValueMap()
				require.NoError(t, v.FromRaw(map[string]any{
					"counts": []any{100},
					"values": []any{10.0},
				}))
				return v
			},
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			m := pmetric.NewMetric()
			m.SetName("test")
			tc.histogramDP.MoveTo(m.SetEmptyHistogram().DataPoints().AppendEmpty())

			esHist := NewHistogram(m, m.Histogram().DataPoints().At(0))
			actual, err := esHist.Value()
			require.NoError(t, err)
			assert.True(t, tc.expected(t).Equal(actual))
		})
	}
}

Expected Result

All histogram within specs should be handled without error.

Actual Result

Explicit bound histograms with no buckets defined results in an error.

Collector version

main

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

Log output

invalid number data point "..."

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions