-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Default value for sprintf interpolation (Feature) #4416
Comments
I really like the idea of having a way to define a default value for a key in the string interpolation, this has come to my mind when I did the refactor and optimization of that part of the code. I am not sure if the Another common request is a way to access environment variables through string interpolation, lets take both cases into consideration to come up with a the best syntax. If i have an exported variable
What do you think? This would allow us to be flexible with new features and |
I don't have any preference for the syntax. Actually I used the pipe ( Regarding the environment variables have found #3944 which it self references logstash-plugins/logstash-filter-environment/pull/5. I think all the cases regarding environment variables, which could be addressed with the combined string interpolation syntax proposed by @ph, could also be solved by logstash-filter-environment. Therefore I suggest to not overload this pull request. |
@breml I am +1 to not overload the PR, just wanted to make sure we could grow from it :) |
As a workaround, you can usually do this:
|
I agree it would be nice to have more functionality in |
@jordansissel: Thanks for the workaround, we will try this one. Up until now we used the blacklist_values feature of https://github.com/logstash-plugins/logstash-filter-prune to remove fields with |
I agree with @jordansissel, to have a clean syntax for a possible extension of the I am not sure, if we have to invent the wheel again. There are similar string interpolation features implemented in other places/languages. |
My PR #4417 is closed, based on the discussion in this issue. My question is: How do we precede with this one? |
It looks like we haven't agreed on the syntax to define defaults based on above comments.
I personally liked what @ph proposed. Its more explicit - |
I just reread the issue: This comment from @jordansissel
Like type coercion? We could implement it that way:
not sure if it would be better if we support quoted text too, this would make the syntax more resilient to future changes.
|
@jordansissel @suyograo Any plans on adding this feature? Just wanted to get the idea as the issue hasn't been updated for a while now. |
I'm in favor of this feature, but we haven't worked on a design (and studied the possible negative impacts) beyond what you see in this issue. |
@jordansissel Thanks for the heads up. |
Is there any progress? This feature would be very useful. |
No progress to report. If there is, we will update this issue.
…On Wed, Dec 13, 2017 at 1:11 AM vbohata ***@***.***> wrote:
Is there any progress? This feature would be very useful.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4416 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIC6uz1UKZag9rqhj_v7AcC8fgNWtl4ks5s_5TUgaJpZM4G-tjB>
.
|
As a suggestion, curious to know if reasonable default that could be used here would be to simply interpolate the value of a missing field as an empty string. It is probably an improvement over placing the variable verbatim in the string in any case, but it's also similar to e.g. UNIX shell where accessing a variable that's not set returns an empty value. $ echo $NOSUCHVAR; echo $((2+2))
4 If this for some reason isn't desirable, maybe it would be possible to enable this behavior with a configuration setting? |
+1 for this. |
+1 |
In a lot places, Logstash allows to reference fields with the sprintf format(https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#sprintf). Unfortunately if the referenced field does not exist, sprintf defaults to leave the the reference untouched, which may lead to very unsatisfactory results. Therefore I suggest to allow a default value for the sprintf interpolation, e.g.
As delimiter between the field reference and the default value I suggest
:-
(taken from bash, unlikely to exist in a Logstash event field name).The text was updated successfully, but these errors were encountered: