-
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
Add format option for add_locale processor #4106
Conversation
Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run. |
1 similar comment
Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run. |
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.
Looks like you are off to a good start. Thanks for working on this!
} | ||
|
||
func (t TimezoneFormat) String() string { | ||
return timezoneFormats[t] |
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.
It seems like this could easily result in a panic with something like TimezoneFormat(-1).String()
. I think a more common approach is to store a map[TimezoneFormat]string
. But you can use an array like you did, but you just need to bounds checking on t
like (t > 0 && t < len(timezoneFormats)
).
return addLocale{}, nil | ||
config := struct { | ||
Format string `config:"format" validate:"required"` | ||
}{} |
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.
Looks like this is missing the default value initialization.
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.
That's what i asked. How do you think should that processor work
-add_locale:
with default abbrevation
or
-add_locale:
format: "abbrevation/offset"
make format as required.
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 think it should default to offset. IMO that would be easier to use and not require someone to have a lookup table of names to numbers and would account for DST changes.
}{} | ||
err := c.Unpack(&config) | ||
if err != nil { | ||
return nil, fmt.Errorf("fail to unpack the include_fields configuration: %s", err) |
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.
s/include_fields/add_locale/
case "offset": | ||
loc.TimezoneFormat = Offset | ||
default: | ||
return nil, errors.New("given format is not valid") |
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.
More details in the error would be better for users running -configcheck
. Things like: What is the invalid value that was given? What is the thing that caused the error (add_locale)? How should the error be fixed (provide the two allowed values)?
} | ||
|
||
func (l addLocale) Run(event common.MapStr) (common.MapStr, error) { | ||
zone, _ := time.Now().Zone() | ||
event.Put("beat.timezone", zone) | ||
format := l.Format() |
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.
How do the old benchmarks compare to the new benchmarks now that Format()
is called for each event? It would be good to test with both Abbreviation and Offset.
case Abbrevation: | ||
fmt, _ = tm.Zone() | ||
case Offset: | ||
//loc, _ := time.LoadLocation("America/Belize") |
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.
This should be removed.
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.
tests 😄
} | ||
|
||
fmt += strconv.Itoa(offset) | ||
fmt += ":00" |
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.
Timezone offsets do not all fall on one hour boundaries. See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Here's an example calculation: https://play.golang.org/p/iuiuSxMZ1Q
This will need some test cases.
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.
What is the correct form for positive and negative values to display.
11:45, 02:45
and -11:45, -01:45
or 11:45, 2:45
and -11:45, -1:45
. Its about the leading zero and the positive and negative sign.
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.
From the wiki page I linked above:
The UTC offsets (columns 5 and 6) are parsed from the "continent files" and accordingly ISO 6709 are in the format {+|-}hh:mm
So I'd say go with {+|-}hh:mm
.
jenkins, test it |
@maddin2016 One of the tests is failing: |
Hi @ruflin, that's right. There 2 questions which are unanswered. Then i can continue. How do you think this processor should work
with default
make format as required. What is the correct form for positive and negative values to display. |
@monicasarbu @andrewkroh Can one of you comment on the above? |
Hi @ruflin. @andrewkroh has answered my question. Can you start the integration tests again. Something went wrong with travis. Thanks. |
Nice, just restarted it. |
jenkins, test it |
TimezoneFormat TimezoneFormat | ||
} | ||
|
||
type TimezoneFormat int |
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.
[golint] reported by reviewdog 🐶
exported type TimezoneFormat should have comment or be unexported
type TimezoneFormat int | ||
|
||
const ( | ||
Abbrevation TimezoneFormat = iota |
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.
[golint] reported by reviewdog 🐶
exported const Abbrevation should have comment (or a comment on this block) or be unexported
@andrewkroh Shouldn't there be a doc change for this, too? |
I updated the docs in #4330 |
Like discussed in #3974, this PR add the option to format the timezoneoutput. I have decided to just use
abbrevation
andoffset
as options. Because is not so trivial to format time to a canonical_id. Here is a discussion about the topic. One thing which have to decide is should be format option required or should beabbrevation
the default option.