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

conditional labels #33

Closed
axinojolais opened this issue Apr 16, 2018 · 6 comments
Closed

conditional labels #33

axinojolais opened this issue Apr 16, 2018 · 6 comments

Comments

@axinojolais
Copy link

Hi,

Is it possible to have "conditional" labels ? For example, consider the following patterns :

FOO foo
BAR bar
FOOBAR %{FOO:foo}%{BAR:bar}?

If I match on %{FOOBAR} in my metrics, I can use {{.foo}} in the labels, because it will always be present. However, as soon as I want to use {{.bar}}, I run into problems because a line can match only %{FOO} and not %{BAR}, so sometimes bar isn't in the template context, so grok_exporter becomes unhappy : Warning : Skipping log line: foobar: unexpected result when calling onig_name_to_group_numbers()

I tried to work around it by using {{if .bar}}{{.bar}}{{end}} to no avail.

How could I achieve what I want there ? Is there a way to check that a template variable exists without making grok_exporter bail on onig_name_to_group_numbers() ?

Thanks

@fstab
Copy link
Owner

fstab commented Apr 16, 2018

This is a bug, I will fix it in the next release and make {{.bar}} an empty string in that case. As a workaround, you can use this:

FOO foo
BAR bar
OPTIONAL_BAR %{BAR}?
FOOBAR %{FOO:foo}%{OPTIONAL_BAR:bar}

@Nitro-N
Copy link

Nitro-N commented May 8, 2018

ERRORDATE %{YEAR}/%{MONTHNUM}/%{MONTHDAY} %{TIME}
METHOD (OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT)
REQUEST_START %{METHOD:method} %{DATA:path} HTTP/%{DATA:http_version}
ADDITIONAL_INFO client: %{URIHOST:client}|server: %{URIHOST:server}|request: "%{REQUEST_START:request}"|upstream: "%{URI:upstream}"|host: "%{URIHOST:host}"|referrer: "%{URI:referrer}"
NGINX_ERROR ^%{ERRORDATE:time_local} \[%{LOGLEVEL:level}\] %{INT:process_id}#%{INT:thread_id}: \*(%{INT:connection_id})? %{DATA:errormessage}(, %{ADDITIONAL_INFO})*$

Please include this or the same case into tests. Labels in ADDITIONAL_INFO match are optional.

fstab added a commit that referenced this issue May 29, 2018
@fstab
Copy link
Owner

fstab commented May 29, 2018

@Nitro-N sorry for the late reply. I pushed a test for the FOOBAR example above. Could you provide an example log line for the NGINX_ERROR pattern? Then I will add it to the test cases.

@Nitro-N
Copy link

Nitro-N commented May 29, 2018

@fstab

2018/05/29 15:33:58 [error] 50#50: *5338007 no live upstreams while connecting to upstream, client: 5.128.43.14, server: example.com, request: "GET /backend/api/event/events?_limit=0&startTime=2018-05-29T04:00:00%2B07:00 HTTP/2.0", upstream: "http://example.com/backend/api/event/events?_limit=0&startTime=2018-05-29T04:00:00%2B07:00", host: "example.com", referrer: "https://example.com/platform"
2018/05/29 15:35:33 [error] 50#50: *5340036 upstream prematurely closed connection while sending to client, client: 188.162.213.93, server: example.com, request: "GET /backend/api/ HTTP/2.0", upstream: "http://172.19.0.8:80/backend/api", host: "example.com", referrer: "https://example.com/event"
2018/05/29 18:54:03 [crit] 50#50: *5411664 SSL_do_handshake() failed (SSL: error:1417D18C:SSL routines:tls_process_client_hello:version too low) while SSL handshaking, client: 208.93.213.176, server: 0.0.0.0:443

fstab added a commit that referenced this issue May 30, 2018
@fstab
Copy link
Owner

fstab commented May 30, 2018

Thanks for the examples. I pushed a test, it should work now.

@fstab fstab closed this as completed May 30, 2018
@fstab
Copy link
Owner

fstab commented May 31, 2018

Released v0.2.5 including the fix for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants