Skip to content
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

Windows events #3246

Merged
merged 28 commits into from
Feb 2, 2021
Merged

Windows events #3246

merged 28 commits into from
Feb 2, 2021

Conversation

cyriltovena
Copy link
Contributor

@cyriltovena cyriltovena commented Jan 27, 2021

What this PR does / why we need it:

This PR introduces support for reading windows event logs with Promtail and send them to Loki.

It support saving the position of which events has been sent to avoid skipping logs during rollout or service interuption.

Which issue(s) this PR fixes:
Fixes #1395

Special notes for your reviewer:

I have forked telegraf windows event library in our repo to make it fit our scrape/push model. I'm using mostly syscall and event definition there. see https://github.com/influxdata/telegraf/tree/master/plugins/inputs/win_eventlog

Checklist

  • Documentation added
  • Tests updated

@codecov-io
Copy link

codecov-io commented Jan 27, 2021

Codecov Report

Merging #3246 (5062184) into master (8716e24) will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3246      +/-   ##
==========================================
+ Coverage   63.06%   63.08%   +0.02%     
==========================================
  Files         198      198              
  Lines       16796    16796              
==========================================
+ Hits        10592    10596       +4     
+ Misses       5239     5236       -3     
+ Partials      965      964       -1     
Impacted Files Coverage Δ
pkg/promtail/scrapeconfig/scrapeconfig.go 12.00% <ø> (ø)
pkg/promtail/targets/file/tailer.go 75.00% <0.00%> (+1.78%) ⬆️
pkg/querier/queryrange/downstreamer.go 97.64% <0.00%> (+2.35%) ⬆️

Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exciting! 🎉

pkg/promtail/targets/windows/targetmanager_windows.go Outdated Show resolved Hide resolved
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started review, left a few nits

docs/sources/clients/promtail/configuration.md Outdated Show resolved Hide resolved
docs/sources/clients/promtail/configuration.md Outdated Show resolved Hide resolved
docs/sources/clients/promtail/configuration.md Outdated Show resolved Hide resolved
docs/sources/clients/promtail/configuration.md Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
pkg/promtail/targets/windows/bookmark.go Outdated Show resolved Hide resolved
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished review, there's a few nits and one []byte mis-instantiation, then I'll approve.

Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
@cyriltovena
Copy link
Contributor Author

Started review, left a few nits

Will check it out.

cyriltovena and others added 10 commits February 1, 2021 16:44
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@cyriltovena cyriltovena merged commit 72b3acb into master Feb 2, 2021
@cyriltovena cyriltovena deleted the windows_events branch February 2, 2021 12:37
// The bookmark will be saved at the given path. Use save to save the current position for a given event.
func newBookMark(path string) (*bookMark, error) {
// 4kb buffer for rendering bookmark
buf := make([]byte, 4<<10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4kb will not be enough for complex event filters

Copy link
Contributor Author

@cyriltovena cyriltovena Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have an example ? what would be a good value ? Thanks for the feedback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By hitting some filters in Custom View of Windows Event Viewer and exporting resulting filter XML, I am easily getting a 8kb file. Bookmark with that filter takes a little bit more space.

Telegraf uses a 16kb buffer, and it's a better default value, enough for most cases.

The best way would be going full winapi: calling _EvtRender with zero as buf pointer value. It will return error, but also put the required length into bufferUsed. So then we can make buffer of required length and call _EvtRender again, this time with the newly created buffer pointer. It is a less performant way, and there can be a headache of memory allocating and freeing, but it is bulletproof.

Thank you very much for this PR btw! I made like 75% of porting Telegraf code to Loki, but got stuck at the polling loop, didn't find the satisfying method to do polls and got carried away by other duties. I like Loki, but extending it is such nontrivial work comparing to Telegraf, so many core files to change with custom targets, it is very unfriendly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like Loki, but extending it is such nontrivial work comparing to Telegraf, so many core files to change with custom targets, it is very unfriendly.

Sorry about that ! We'll try to get better at this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll increase the buffer :) before we cut a new release

rfratto added a commit to rfratto/agent that referenced this pull request Feb 3, 2021
@rfratto rfratto mentioned this pull request Feb 3, 2021
3 tasks
rfratto added a commit to grafana/agent that referenced this pull request Feb 3, 2021
cyriltovena added a commit to cyriltovena/loki that referenced this pull request Feb 8, 2021
See this discussion grafana#3246 (comment)

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
cyriltovena added a commit that referenced this pull request Feb 9, 2021
See this discussion #3246 (comment)

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
cyriltovena added a commit to cyriltovena/loki that referenced this pull request Feb 15, 2021
See this discussion grafana#3246 (comment)

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
mattdurham pushed a commit to grafana/agent that referenced this pull request Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows EventLog support
5 participants