Skip to content

Commit 650ffc5

Browse files
kuiperdajriguera
authored andcommitted
[pkg/stanza] Windows input operator should resubscribe when remote host restarts (open-telemetry#35175)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> While collecting Windows Event Logs from a remote host, if that host restarts or shuts off, the collector begins logging errors and stops collecting WE logs, even after the remote host is back up. Restarting the collector fixes this. To fix this without restarting the collector, the stanza input operator needs to resubscribe if the remote host restarts. Error log: ``` "Failed to read events from subscription","error":"The handle is invalid." ``` **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> Manually tested with a build of the collector, and confirmed logs continue being collected after the remote host restarts. **Documentation:** <Describe the documentation added.> N/A, this change is expected behavior
1 parent 6d112d0 commit 650ffc5

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: "bug_fix"
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: windowseventlogreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: If collecting from a remote host, the receiver will stop collecting if the host restarts. This change resubscribes when the host restarts.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35175]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

pkg/stanza/operator/input/windows/input.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ func (i *Input) read(ctx context.Context) int {
216216
events, err := i.subscription.Read(i.maxReads)
217217
if err != nil {
218218
i.Logger().Error("Failed to read events from subscription", zap.Error(err))
219+
if i.isRemote() && (errors.Is(err, windows.ERROR_INVALID_HANDLE) || errors.Is(err, errSubscriptionHandleNotOpen)) {
220+
i.Logger().Info("Resubscribing, closing remote subscription")
221+
closeErr := i.subscription.Close()
222+
if closeErr != nil {
223+
i.Logger().Error("Failed to close remote subscription", zap.Error(closeErr))
224+
return 0
225+
}
226+
i.Logger().Info("Resubscribing, creating remote subscription")
227+
i.subscription = NewRemoteSubscription(i.remote.Server)
228+
}
219229
return 0
220230
}
221231

pkg/stanza/operator/input/windows/subscription.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ func (s *Subscription) Close() error {
6464
return nil
6565
}
6666

67+
var errSubscriptionHandleNotOpen = errors.New("subscription handle is not open")
68+
6769
// Read will read events from the subscription.
6870
func (s *Subscription) Read(maxReads int) ([]Event, error) {
6971
if s.handle == 0 {
70-
return nil, fmt.Errorf("subscription handle is not open")
72+
return nil, errSubscriptionHandleNotOpen
7173
}
7274

7375
if maxReads < 1 {

0 commit comments

Comments
 (0)