-
Notifications
You must be signed in to change notification settings - Fork 3k
[exporter/elasticsearch] report connection health via componentstatus #39562
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
Merged
andrzej-stencel
merged 14 commits into
open-telemetry:main
from
faec:elasticsearch-exporter-componentstatus
May 9, 2025
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a041a17
Report elasticsearch exporter health via componentstatus
faec b9eafef
Add a unit test for component status reporting
faec 3840af1
lint
faec 9cfd1a9
update componentstatus version
faec c76a944
add changelog
faec 8359fb6
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
faec 4e11529
go mod tidy
faec db37cec
fix linter errors, special case ES duplicate ingestion errors
faec 1d0dda0
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
faec 8a34da3
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
faec c1ca4b7
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
faec 0274bcc
Include 409 special case in unit test
faec 31e1957
Merge branch 'main' into elasticsearch-exporter-componentstatus
andrzej-stencel 91b631a
Merge remote-tracking branch 'origin' into elasticsearch-exporter-com…
andrzej-stencel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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: Report Elasticsearch request success / failure via componentstatus | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [39562] | ||
|
||
# (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] |
This file contains hidden or 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 hidden or 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,73 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package elasticsearchexporter | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/component/componentstatus" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestComponentStatus(t *testing.T) { | ||
statusChan := make(chan *componentstatus.Event, 1) | ||
reporter := &testStatusReporter{statusChan} | ||
esLogger := clientLogger{ | ||
Logger: zap.New(nil), | ||
logRequestBody: false, | ||
logResponseBody: false, | ||
componentHost: reporter, | ||
} | ||
|
||
// Pass in an error and make sure it's sent to the component status reporter | ||
_ = esLogger.LogRoundTrip(nil, nil, io.EOF, time.Now(), 0) | ||
select { | ||
case event := <-statusChan: | ||
assert.ErrorIs(t, event.Err(), io.EOF, "LogRoundTrip should report a component status error wrapping its error parameter") | ||
assert.Equal(t, componentstatus.StatusRecoverableError, event.Status(), "LogRoundTrip on an error parameter should report a recoverable error") | ||
default: | ||
require.Fail(t, "LogRoundTrip with an error should report a recoverable error status") | ||
} | ||
|
||
// Pass in an http error status and make sure it's sent to the component status reporter | ||
_ = esLogger.LogRoundTrip(&http.Request{URL: &url.URL{}}, &http.Response{StatusCode: 401, Status: "401 Unauthorized"}, nil, time.Now(), 0) | ||
atoulme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
select { | ||
case event := <-statusChan: | ||
err := event.Err() | ||
require.Error(t, err, "LogRoundTrip with an http error status should report a component status error") | ||
assert.Contains(t, err.Error(), "401 Unauthorized", "LogRoundTrip with an http error status should include the status in its error state") | ||
assert.Equal(t, componentstatus.StatusRecoverableError, event.Status(), "LogRoundTrip with an http error status should report a recoverable error") | ||
default: | ||
require.Fail(t, "LogRoundTrip with an http error code should report a recoverable error status") | ||
} | ||
|
||
// Pass in an http success status and make sure the component status returns to OK | ||
_ = esLogger.LogRoundTrip(&http.Request{URL: &url.URL{}}, &http.Response{StatusCode: 200}, nil, time.Now(), 0) | ||
atoulme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
select { | ||
case event := <-statusChan: | ||
assert.NoError(t, event.Err(), "LogRoundTrip with a success status shouldn't report a component status error") | ||
assert.Equal(t, componentstatus.StatusOK, event.Status(), "LogRoundTrip with a success status should report component status OK") | ||
default: | ||
require.Fail(t, "LogRoundTrip with an http success should report component status OK") | ||
} | ||
} | ||
|
||
type testStatusReporter struct { | ||
statusChan chan *componentstatus.Event | ||
} | ||
|
||
func (tsr *testStatusReporter) Report(event *componentstatus.Event) { | ||
tsr.statusChan <- event | ||
} | ||
|
||
func (tsr *testStatusReporter) GetExtensions() map[component.ID]component.Component { | ||
return make(map[component.ID]component.Component) | ||
} |
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of these recoverable? I would think a 401 would be non-recoverable without human intervention.
409s are not an error at all necessarily, when documents are truly duplicates. Is it worth special casing those? There should probably be an indicator they are happening but if someone explicitly is doing de-duplication via an _id in the document this will mark the exporter as degraded unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"non-recoverable" in the collector is very unforgiving, to the extent that almost nothing we could encounter truly satisfies its definition (which is that the component can never again return to a healthy state no matter what for the life of the process -- so its real meaning isn't "requires human intervention" it's "requires intervention and a restart of the process"). For example I've seen some setups where ingest credentials are synced to the ingest workers before they're actually activated upstream (I don't know why, but it shouldn't break us), or similarly a 401 can be a side effect of broken or unreliable proxy settings that can be resolved without restarting the client process.
Good point about 409s though, those should be telemetry numbers rather than a component error state, I will add a special case for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just special casing 409s makes sense to me then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good, probably worth a test case for 409s specifically since they are now meant not to trigger recovery from an error state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test!