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

More flexible Json_Date_Format #848

Open
restyler opened this issue Oct 13, 2018 · 4 comments
Open

More flexible Json_Date_Format #848

restyler opened this issue Oct 13, 2018 · 4 comments
Assignees

Comments

@restyler
Copy link

Clickhouse is pretty strict on data formats and fails to parse "2018-10-13T17:46:23.000000Z" which is generated by json_date_format iso8601. So, as far as I understand, the only way to fix this is to create a proxy server which will convert this format to Clickhouse supported "2016-06-15 00:11:21". It would be helpful to do it on the fluentbit output plugin level.

@edsiper
Copy link
Member

edsiper commented Nov 7, 2018

@restyler

this is a good enhancement, it make sense. It will be implemented shortly.

@edsiper edsiper self-assigned this Nov 7, 2018
@jamesgoodhouse
Copy link
Contributor

jamesgoodhouse commented Feb 25, 2019

@restyler: Until this enhancement is complete, you may have luck using a Lua script in a filter to create your own custom timestamp. I had to do something similar to get a different time format. Here's an example of how I did it:

local function extract_timestamp(log)	
  local month,day,hour,min,sec = log:match('^(%u%l%l)%s(%s?%d?%d)%s(%d%d):(%d%d):(%d%d) [%a-_]+%[%d+%]:%s')	
  local MON={Jan=1,Feb=2,Mar=3,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9,Oct=10,Nov=11,Dec=12}	
  local timestamp = os.time({year = os.date("*t").year, month = MON[month], day = day, hour = hour, min = min, sec = sec})	

  return timestamp	
end

As far as how this could be implemented in fluent bit, would it work for you if there was possibly an additional field where you could specify the timestamp format? Maybe something like how it's done for the regex parser? Perhaps something like:

[OUTPUT]
    Name                     http
    Host                     192.168.2.3
    Port                     80
    URI                      /something
    json_date_format         custom
    json_date_custom_format  %Y-%m-%d %H:%M:%S

@jamesgoodhouse
Copy link
Contributor

jamesgoodhouse commented Feb 25, 2019

@edsiper: I worked on #1111, and after reviewing flb_strptime.c, I'm wondering if it'd make sense to maybe ditch the json_date_format predefined values and move to having a default value that can be overridden with whatever format one wants. Something like below where the json_date_format doesn't take a string anymore of either double or iso8601, but instead a value that can be used to dictate the desired structure of the timestamp.

[OUTPUT]
    Name              http
    Host              192.168.2.3
    Port              80
    URI               /something
    json_date_format  %Y-%m-%d %H:%M:%S

This would be a breaking change unfortunately, so not sure how that would be handled.

@marcosdiez
Copy link
Contributor

@restyler my PR #4811 happens to add exactly the format you need. It's not a generic custom format, but should solve your specific problem.

rawahars pushed a commit to rawahars/fluent-bit that referenced this issue Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants