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

Backport PR #16906 to 8.x: Add %{{TIME_NOW}} pattern for sprintf #16908

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

github-actions[bot]
Copy link
Contributor

Backport PR #16906 to 8.x branch, original message:


Release notes

Add support of %{{TIME_NOW}} syntax to sprinf format to generate a new current timestamp

What does this PR do?

This commit added %{{TIME_NOW}} syntax to event.sprintf() to generate a fresh timestamp as string

Example

input {
    heartbeat {
      add_field => { "heartbeat_time" => "%{{TIME_NOW}}" }
    }
}
filter {
    mutate {
      add_field => { "mutate_time" => "%{{TIME_NOW}}" }
    }
}

It gives two different timestamps.

Why is it important/What is the impact to the user?

When the incoming event has value in @timestamp, eg. event from agent, Logstash use the provided value instead of generating a new timestamp. Prior to the change, there is no way to force a new timestamp to generate during the execution of input plugins.

Previously, users often generate timestamp with ruby-filter code => "event.set('ruby_time', Time.now());", but this approach requires events to pass through PQ before the timestamp was assigned. It is not a good indicator of when the event actually arrived in Logstash.

With this change, all input and filter plugins can generate new timestamps

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

* Add a new pattern %{{TIME_NOW}} to `event.sprintf` to generate a fresh timestamp.
The timestamp is represented as a string in the default ISO 8601 format

For example,
```
input {
    heartbeat {
    add_field => { "heartbeat_time" => "%{{TIME_NOW}}" }
    }
}
```

(cherry picked from commit cd729b7)
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

@kaisecheng kaisecheng merged commit 2410483 into 8.x Jan 17, 2025
5 checks passed
@kaisecheng kaisecheng deleted the backport_16906_8.x branch January 17, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants