-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
support for Timestamp in file outputter path #38029
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
Pinging @elastic/elastic-agent (Team:Elastic-Agent) |
Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform) |
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.
I wasn't sure if this should be documented or left as an undocumented feature.
Please document it, I see no reason to not document it and other users might find it useful.
Could you also add a test to ensure this new feature works?
@belimawr added unit tests and update documentation |
@belimawr thanks for approving! |
@andrewkroh |
It is interesting to me that the code:
Seems to assume a unix path separator. Not sure if that would cause problems in windows, but it seems curious that the failures all seem to be windows |
It seems like the fmtstr code is doing something unexpected with the backslashes. {
"@timestamp": "2024-02-22T03:27:42.475Z",
"ecs.version": "1.6.0",
"log.level": "info",
"log.logger": "file",
"log.origin": {
"file.line": 104,
"file.name": "fileout/file.go",
"function": "github.com/elastic/beats/v7/libbeat/outputs/fileout.(*fileOutput).init"
},
"message": "Initialized file output. path=C:UsersjenkinsworkspacePR-38029-8-20a152a8-baa5-4ccc-9622-ac59a245009csrcgithub.comelasticbeatsx-packmetricbeatbuildsystem-testsruntest_airflow.Test.test_server507\\output\\metricbeat max_size_bytes=1024000 max_backups=7 permissions=-rw-------",
"service.name": "metricbeat"
} # metricbeat.yml
output.file:
path: C:\Users\jenkins\workspace\PR-38029-8-20a152a8-baa5-4ccc-9622-ac59a245009c\src\github.com\elastic\beats\x-pack\metricbeat\build\system-tests\run\test_airflow.Test.test_server507/output |
@andrewkroh good find. beats/libbeat/common/fmtstr/formatstring.go Line 377 in f634386
So the path separator in this case gets swallowed. 1] Write our own More I think about it, the more I favor option 1 Can you see any alternatives? |
Nice! Let me try and adopt that - lets see if all the tests pass Thanks so much for all your help!! |
well, that wont work for the following example:
I did a variation of option 3: https://github.com/elastic/beats/pull/38029/files#diff-7b5b4e797d2a07c4776c672a714e5fc98f390ddc4fa855b8d6dfc2f876f473daR1 If that works, and seems ok enough, I can add unit tests there |
💚 Build Succeeded
History
cc @yspotts |
💔 Build Failed
Failed CI StepsHistory
cc @yspotts |
💚 Build Succeeded
History
cc @yspotts |
💚 Build Succeeded
History
cc @yspotts |
💚 Build Succeeded
History
cc @yspotts |
💚 Build Succeeded
History
cc @yspotts |
@yspotts it seems that we are good to go with this one. Could you take care of merging it please? |
* support for TIME_NOW var * fix import ordering * add documentation * add unit tests * fix linting error * path is a date time formatter * fmt * remove unneeded * update docs * add UTC * improve message * change link * create new Unpacker * fmt * description of the use case * unit tests (cherry picked from commit e067577)
* support for TIME_NOW var * fix import ordering * add documentation * add unit tests * fix linting error * path is a date time formatter * fmt * remove unneeded * update docs * add UTC * improve message * change link * create new Unpacker * fmt * description of the use case * unit tests (cherry picked from commit e067577) Co-authored-by: Yoel Spotts <yspotts@users.noreply.github.com> Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>
Proposed commit message
Add support for timestamp substitution variable in the file outputter path configuration. The format for the timestamp variable is is described in https://www.elastic.co/guide/en/beats/libbeat/8.12/config-file-format-type.html#_format_string_sprintf and is the same as for the elasticsearch index specification: https://www.elastic.co/guide/en/beats/filebeat/master/elasticsearch-output.html#index-option-es.
Full set of supported variables:
beats/libbeat/common/dtfmt/doc.go
Lines 18 to 54 in e7e6dac
An example configuration:
This is accomplished by changing the config type of
path
to befmtstr.TimestampFormatString
which willUnpack
the variable using theUnpack
method specific for that type which handles substitution for timestamps. The current time in UTC is used for the actual substitution.Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
In one of the fields used by the file outputter, add a time
+FORMAT
variable to be substituted.Related issues
Use cases
We will be using Packetbeat for the COGS network metering project. The use case and necessity for this feature is as follows:
If the Packetbeat instance crashes for some reason and restarts, due to the way packetbeat names files, this could likely cause duplicate filenames. The Archive CSI Driver would then upload the new file which would replace the file with the same name in s3, thus causing data loss of COGS metering information.
In order to avoid this, we have identified an easy “fix” to packetbeat: introduce a unique subdirectory path in the output path configuration. This can be accomplished with the current timestamp.