-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[exporter/elasticsearch] Add explicit bounds histogram support to metrics #34045
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
Changes from all commits
9841f48
58179c2
43f2c5b
244d96b
9567252
646c7a0
2701d4c
074a406
c5e2f78
9840648
d438897
2c29f47
1a9d0ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: elasticsearchexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add explicit bounds histogram support to metrics | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [34045] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"math" | ||
"net/http" | ||
"runtime" | ||
"sync" | ||
|
@@ -495,6 +496,7 @@ func TestExporterMetrics(t *testing.T) { | |
}, | ||
) | ||
metrics.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetName("my.metric") | ||
metrics.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetEmptySum().DataPoints().AppendEmpty().SetIntValue(0) | ||
mustSendMetrics(t, exporter, metrics) | ||
|
||
rec.WaitItems(1) | ||
|
@@ -633,6 +635,103 @@ func TestExporterMetrics(t *testing.T) { | |
|
||
assertItemsEqual(t, expected, rec.Items(), false) | ||
}) | ||
|
||
t.Run("publish histogram", func(t *testing.T) { | ||
rec := newBulkRecorder() | ||
server := newESTestServer(t, func(docs []itemRequest) ([]itemResponse, error) { | ||
rec.Record(docs) | ||
return itemsAllOK(docs) | ||
}) | ||
|
||
exporter := newTestMetricsExporter(t, server.URL, func(cfg *Config) { | ||
cfg.Mapping.Mode = "ecs" | ||
}) | ||
|
||
metrics := pmetric.NewMetrics() | ||
resourceMetrics := metrics.ResourceMetrics().AppendEmpty() | ||
scopeA := resourceMetrics.ScopeMetrics().AppendEmpty() | ||
metricSlice := scopeA.Metrics() | ||
fooMetric := metricSlice.AppendEmpty() | ||
fooMetric.SetName("metric.foo") | ||
fooDps := fooMetric.SetEmptyHistogram().DataPoints() | ||
fooDp := fooDps.AppendEmpty() | ||
fooDp.ExplicitBounds().FromRaw([]float64{1.0, 2.0, 3.0}) | ||
fooDp.BucketCounts().FromRaw([]uint64{1, 2, 3, 4}) | ||
fooOtherDp := fooDps.AppendEmpty() | ||
fooOtherDp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(3600, 0))) | ||
fooOtherDp.ExplicitBounds().FromRaw([]float64{4.0, 5.0, 6.0}) | ||
fooOtherDp.BucketCounts().FromRaw([]uint64{4, 5, 6, 7}) | ||
|
||
mustSendMetrics(t, exporter, metrics) | ||
|
||
rec.WaitItems(2) | ||
|
||
expected := []itemRequest{ | ||
{ | ||
Action: []byte(`{"create":{"_index":"metrics-generic-default"}}`), | ||
Document: []byte(`{"@timestamp":"1970-01-01T00:00:00.000000000Z","data_stream":{"dataset":"generic","namespace":"default","type":"metrics"},"metric":{"foo":{"counts":[1,2,3,4],"values":[0.5,1.5,2.5,3]}}}`), | ||
}, | ||
{ | ||
Action: []byte(`{"create":{"_index":"metrics-generic-default"}}`), | ||
Document: []byte(`{"@timestamp":"1970-01-01T01:00:00.000000000Z","data_stream":{"dataset":"generic","namespace":"default","type":"metrics"},"metric":{"foo":{"counts":[4,5,6,7],"values":[2,4.5,5.5,6]}}}`), | ||
}, | ||
} | ||
|
||
assertItemsEqual(t, expected, rec.Items(), false) | ||
}) | ||
|
||
t.Run("publish only valid data points", func(t *testing.T) { | ||
rec := newBulkRecorder() | ||
server := newESTestServer(t, func(docs []itemRequest) ([]itemResponse, error) { | ||
rec.Record(docs) | ||
return itemsAllOK(docs) | ||
}) | ||
|
||
exporter := newTestMetricsExporter(t, server.URL, func(cfg *Config) { | ||
cfg.Mapping.Mode = "ecs" | ||
}) | ||
|
||
metrics := pmetric.NewMetrics() | ||
resourceMetrics := metrics.ResourceMetrics().AppendEmpty() | ||
scopeA := resourceMetrics.ScopeMetrics().AppendEmpty() | ||
metricSlice := scopeA.Metrics() | ||
fooMetric := metricSlice.AppendEmpty() | ||
fooMetric.SetName("metric.foo") | ||
fooDps := fooMetric.SetEmptyHistogram().DataPoints() | ||
fooDp := fooDps.AppendEmpty() | ||
fooDp.ExplicitBounds().FromRaw([]float64{1.0, 2.0, 3.0}) | ||
fooDp.BucketCounts().FromRaw([]uint64{}) | ||
fooOtherDp := fooDps.AppendEmpty() | ||
fooOtherDp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(3600, 0))) | ||
fooOtherDp.ExplicitBounds().FromRaw([]float64{4.0, 5.0, 6.0}) | ||
fooOtherDp.BucketCounts().FromRaw([]uint64{4, 5, 6, 7}) | ||
barMetric := metricSlice.AppendEmpty() | ||
barMetric.SetName("metric.bar") | ||
barDps := barMetric.SetEmptySum().DataPoints() | ||
barDp := barDps.AppendEmpty() | ||
barDp.SetDoubleValue(math.Inf(1)) | ||
barOtherDp := barDps.AppendEmpty() | ||
barOtherDp.SetDoubleValue(1.0) | ||
|
||
err := exporter.ConsumeMetrics(context.Background(), metrics) | ||
require.ErrorContains(t, err, "invalid histogram data point") | ||
require.ErrorContains(t, err, "invalid number data point") | ||
Comment on lines
+716
to
+718
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [to reviewer] ConsumeMetrics will return an error, I don't think we can return a partial error here. The valid metric data points will be published, and invalid ones will be dropped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if you can elaborate on this. Is there a reason why you cannot use a PartialSuccess and indicate the number of points rejected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it handles errors the same for histograms as it does for other metric types, so, this is probably irrelevant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pushMetrics returns an error, but PartialSuccess is not an error. I am not aware of a way to meaningfully return to caller to indicate a partial success in an exporter. Even in otelarrowexporter it returns a nil error if partial success happens. The handling in this PR takes a different route. If it drops any data points, it returns an explicit error. We may revisit in the future whether this is desirable. |
||
|
||
rec.WaitItems(2) | ||
|
||
expected := []itemRequest{ | ||
{ | ||
Action: []byte(`{"create":{"_index":"metrics-generic-default"}}`), | ||
Document: []byte(`{"@timestamp":"1970-01-01T00:00:00.000000000Z","data_stream":{"dataset":"generic","namespace":"default","type":"metrics"},"metric":{"bar":1}}`), | ||
}, | ||
{ | ||
Action: []byte(`{"create":{"_index":"metrics-generic-default"}}`), | ||
Document: []byte(`{"@timestamp":"1970-01-01T01:00:00.000000000Z","data_stream":{"dataset":"generic","namespace":"default","type":"metrics"},"metric":{"foo":{"counts":[4,5,6,7],"values":[2,4.5,5.5,6]}}}`), | ||
}, | ||
} | ||
|
||
assertItemsEqual(t, expected, rec.Items(), false) | ||
}) | ||
} | ||
|
||
func TestExporterTraces(t *testing.T) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.