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

Metricbeat index date timezone #3744

Closed
Exocomp opened this issue Mar 13, 2017 · 17 comments
Closed

Metricbeat index date timezone #3744

Exocomp opened this issue Mar 13, 2017 · 17 comments
Labels
discuss Issue needs further discussion. enhancement libbeat needs_team Indicates that the issue/PR needs a Team:* label Stalled

Comments

@Exocomp
Copy link

Exocomp commented Mar 13, 2017

Per https://discuss.elastic.co/t/metricbeat-index-date-timezone/78296.

How do you control the timezone metricbeat uses for the date part of the index name:

For ex:

metricbeat-2017.03.12

Is there a way I can tell metricbeat to use a particular timezone when generating the date part above. I'd like it to use UTC (which is what Filebeat and winlogbeat uses) but is using local.

The reason why this causes a problem is that filebeat and winlogbeat indices rollover to the next day (since it uses UTC) but metricbeat doesn't (since it uses local timezone) so they are not in sync and using 3rd party tools where you set the timezone for the index doesn't work because they are not all the same.

Thanks,
E

@Elufimov
Copy link
Contributor

I have the same problem and I think this is a bug.

@ruflin
Copy link
Member

ruflin commented Mar 15, 2017

I'm surprised that filebeat and metricbeat do not use the same indices as the same logic is used: https://github.com/elastic/beats/blob/master/libbeat/outputs/elasticsearch/client.go#L370. As the timestamp is used for the index name, somewhere in metricbeat the timestamp must be set differently. Which metricsets are you using? Can you share your config?

@ruflin ruflin added bug Metricbeat Metricbeat labels Mar 15, 2017
@Exocomp
Copy link
Author

Exocomp commented Mar 15, 2017

@ruflin

I found out the difference, where it is working with filebeat and winlogbeat I'm sending it to through logstash where I'm using the date filter and setting the timezone, I'm sending metricbeat to elasticsearch directly.

@ruflin
Copy link
Member

ruflin commented Mar 15, 2017

Thanks for the update. Does that mean all implementations do not report UTC?

@ruflin ruflin added discuss Issue needs further discussion. and removed bug labels Mar 15, 2017
@Exocomp
Copy link
Author

Exocomp commented Mar 15, 2017

@ruflin

It is just for the date part of the index, as you say they all share same logic so if you send the other beats to elasticsearch directly I bet those index dates would be local also. But I haven't tested the others going to elasticsearch directly just metricbeat.

@urso
Copy link

urso commented Mar 29, 2017

Checking the implementation, the '@timestamp' value is reported in UTC (timestamp is normalized before serializing), but when building the index or using the time format-string, the timestamp is still local time. This is true for all beats.

My proposal would be to always normalize the timestamp to UTC (so timestamps/events are comparable between different timezones) and report the locale in the event beat namespace. If required, one can use local and @timestamp to create the local timestamp in logstash or ES ingest node.

@ruflin
Copy link
Member

ruflin commented Apr 6, 2017

This processor is the first step to get the timezone into the event: #3902

@andig
Copy link

andig commented Dec 20, 2017

Not sure this is related but looking at https://discuss.elastic.co/t/metricbeat-timestamp-mapping-as-string-type-should-be-date/112521 I've noticed that metricbeat timestamp is not even a date but a string according to the index mapping- might this be part of the issue?

@andig
Copy link

andig commented Dec 20, 2017

Here's a comparison of the mapping definitions:

{
"metricbeat-6.1.1-2017.12.19": {
    "aliases": {},
    "mappings": {
    "doc": {
        "_meta": {
        "version": "6.1.1"
        },
        "dynamic_templates": ...
        "date_detection": false,
        "properties": {
        "@timestamp": {
            "type": "keyword",
            "ignore_above": 1024
        },


{
"filebeat-6.1.1-2017.12.19": {
    "aliases": {},
    "mappings": {
    "doc": {
        "_meta": {
        "version": "6.1.1"
        },
        "dynamic_templates": ...
        "date_detection": false,
        "properties": {
        "@timestamp": {
            "type": "date"
        },

@ruflin
Copy link
Member

ruflin commented Dec 27, 2017

@andig I think the "wrong" template is cause by not loading a template before starting the beat? I assume that is related to the your own arm build?

@andig
Copy link

andig commented Dec 27, 2017

I assume that is related to the your own arm build?

Yes. Very sorry if this idea was offtopic- can no longer reproduce with the official release.

@fjgal
Copy link
Contributor

fjgal commented Feb 27, 2018

@ruflin I faced the same issue as describe here.

It appears that the function libbeat/elasticsearch/client.go#getIndex is only converting the timestamp to UTC for index extension when the "index" metadata is available in the event. Otherwise it uses the default mechanism to format the index string (index.Select(event)) which doesn't convert the Timestamp to UTC.

I submitted a PR (#6485) that intends to solve the issue. I had to solve the issue in formatevents.go so it may affect several places and a couple of unit tests broke. So I am not sure sure whether this is an acceptable solution.

I modifed existing unit tests in libbeat/elasticsearch/client.go to expose and reproduce the issue.

We already have this fix deployed in our environment, which uses our own beat, and we have not observed any undesired side effects.

I'd like to hear your feedback on the PR.

fjgal added a commit to fjgal/beats that referenced this issue Feb 27, 2018
Solves issue elastic#3744

Now the when the timestamp is stored in the context passed to the formatter is to converted to UTC. Some unit test (formatevents_test.go and datetime_test.go) had to be adapted to this behavior.

Modified GetIndex unit tests (elasticsearch/client_test.go) to expose this bug, now they use a timezone and a time that falls in between localtime and UTC to make sure the date in the index name is based on UTC.
@ruflin
Copy link
Member

ruflin commented Mar 4, 2018

@fjgal Thanks, will continue the discussion on the PR.

@dariusj18
Copy link
Contributor

This has been sitting around for a while, is this issue ever going to be resolved?

My two cents, My server is TZ-5, I use Grafana to visualize my data, when I am viewing any chart using an index from Metricbeat from 8 to midnight I get no data, because Grafana specificly queries the index with the UTC date. But all the data is still going into the prior day's index.

@botelastic
Copy link

botelastic bot commented Jul 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@botelastic botelastic bot added Stalled needs_team Indicates that the issue/PR needs a Team:* label labels Jul 9, 2020
@botelastic
Copy link

botelastic bot commented Jul 9, 2020

This issue doesn't have a Team:<team> label.

@botelastic botelastic bot closed this as completed Aug 8, 2020
@florian-asche
Copy link

Still a problem in 7.X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Issue needs further discussion. enhancement libbeat needs_team Indicates that the issue/PR needs a Team:* label Stalled
Projects
None yet
Development

No branches or pull requests

8 participants