Skip to content

Commit 16d65c8

Browse files
djaglowskisbylica-splunk
authored andcommitted
[receiver/windowseventlog] Propogate errors during parsing (open-telemetry#35461)
This PR contains some cleanup following open-telemetry#34720. This slightly changes some log messages. It also propagates errors encountered by sending to the next operator (which was done for other operators in open-telemetry#33847).
1 parent 4383b9a commit 16d65c8

File tree

2 files changed

+55
-30
lines changed

2 files changed

+55
-30
lines changed

.chloggen/wel-error-cleanup.yaml

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: receiver/windowseventlog
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Errors returned when passing data downstream will now be propagated correctly.
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: [35461]
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: []

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Input struct {
3939
remote RemoteConfig
4040
remoteSessionHandle windows.Handle
4141
startRemoteSession func() error
42-
processEvent func(context.Context, Event)
42+
processEvent func(context.Context, Event) error
4343
}
4444

4545
// newInput creates a new Input operator.
@@ -219,7 +219,9 @@ func (i *Input) read(ctx context.Context) {
219219
}
220220

221221
for n, event := range events {
222-
i.processEvent(ctx, event)
222+
if err := i.processEvent(ctx, event); err != nil {
223+
i.Logger().Error("process event", zap.Error(err))
224+
}
223225
if len(events) == n+1 {
224226
i.updateBookmarkOffset(ctx, event)
225227
}
@@ -240,70 +242,66 @@ func (i *Input) getPublisherName(event Event) (name string, excluded bool) {
240242
return providerName, false
241243
}
242244

243-
func (i *Input) renderSimpleAndSend(ctx context.Context, event Event) {
245+
func (i *Input) renderSimpleAndSend(ctx context.Context, event Event) error {
244246
simpleEvent, err := event.RenderSimple(i.buffer)
245247
if err != nil {
246-
i.Logger().Error("Failed to render simple event", zap.Error(err))
247-
return
248+
return fmt.Errorf("render simple event: %w", err)
248249
}
249-
i.sendEvent(ctx, simpleEvent)
250+
return i.sendEvent(ctx, simpleEvent)
250251
}
251252

252-
func (i *Input) renderDeepAndSend(ctx context.Context, event Event, publisher Publisher) {
253+
func (i *Input) renderDeepAndSend(ctx context.Context, event Event, publisher Publisher) error {
253254
deepEvent, err := event.RenderDeep(i.buffer, publisher)
254255
if err == nil {
255-
i.sendEvent(ctx, deepEvent)
256-
return
256+
return i.sendEvent(ctx, deepEvent)
257257
}
258-
i.Logger().Error("Failed to render formatted event", zap.Error(err))
259-
i.renderSimpleAndSend(ctx, event)
258+
return errors.Join(
259+
fmt.Errorf("render deep event: %w", err),
260+
i.renderSimpleAndSend(ctx, event),
261+
)
260262
}
261263

262264
// processEvent will process and send an event retrieved from windows event log.
263-
func (i *Input) processEventWithoutRenderingInfo(ctx context.Context, event Event) {
265+
func (i *Input) processEventWithoutRenderingInfo(ctx context.Context, event Event) error {
264266
if len(i.excludeProviders) == 0 {
265-
i.renderSimpleAndSend(ctx, event)
266-
return
267+
return i.renderSimpleAndSend(ctx, event)
267268
}
268269
if _, exclude := i.getPublisherName(event); exclude {
269-
return
270+
return nil
270271
}
271-
i.renderSimpleAndSend(ctx, event)
272+
return i.renderSimpleAndSend(ctx, event)
272273
}
273274

274-
func (i *Input) processEventWithRenderingInfo(ctx context.Context, event Event) {
275+
func (i *Input) processEventWithRenderingInfo(ctx context.Context, event Event) error {
275276
providerName, exclude := i.getPublisherName(event)
276277
if exclude {
277-
return
278+
return nil
278279
}
279280

280281
publisher, err := i.publisherCache.get(providerName)
281282
if err != nil {
282-
i.Logger().Warn(
283-
"Failed to open event source, respective log entries cannot be formatted",
284-
zap.String("provider", providerName), zap.Error(err))
285-
i.renderSimpleAndSend(ctx, event)
286-
return
283+
return errors.Join(
284+
fmt.Errorf("open event source for provider %q: %w", providerName, err),
285+
i.renderSimpleAndSend(ctx, event),
286+
)
287287
}
288288

289289
if publisher.Valid() {
290-
i.renderDeepAndSend(ctx, event, publisher)
291-
return
290+
return i.renderDeepAndSend(ctx, event, publisher)
292291
}
293-
i.renderSimpleAndSend(ctx, event)
292+
return i.renderSimpleAndSend(ctx, event)
294293
}
295294

296295
// sendEvent will send EventXML as an entry to the operator's output.
297-
func (i *Input) sendEvent(ctx context.Context, eventXML *EventXML) {
296+
func (i *Input) sendEvent(ctx context.Context, eventXML *EventXML) error {
298297
var body any = eventXML.Original
299298
if !i.raw {
300299
body = formattedBody(eventXML)
301300
}
302301

303302
e, err := i.NewEntry(body)
304303
if err != nil {
305-
i.Logger().Error("Failed to create entry", zap.Error(err))
306-
return
304+
return fmt.Errorf("create entry: %w", err)
307305
}
308306

309307
e.Timestamp = parseTimestamp(eventXML.TimeCreated.SystemTime)
@@ -313,7 +311,7 @@ func (i *Input) sendEvent(ctx context.Context, eventXML *EventXML) {
313311
e.Attributes["server.address"] = i.remote.Server
314312
}
315313

316-
_ = i.Write(ctx, e)
314+
return i.Write(ctx, e)
317315
}
318316

319317
// getBookmarkXML will get the bookmark xml from the offsets database.

0 commit comments

Comments
 (0)