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

Logcli field regex does not return results #3436

Closed
caleb15 opened this issue Mar 4, 2021 · 8 comments · Fixed by #3437
Closed

Logcli field regex does not return results #3436

caleb15 opened this issue Mar 4, 2021 · 8 comments · Fixed by #3437

Comments

@caleb15
Copy link
Contributor

caleb15 commented Mar 4, 2021

Describe the bug
Logcli field regex behaves in very strange ways contrary to expectation

To Reproduce
Steps to reproduce the behavior:

  1. Started Loki (helm chart version 2.3.0, which was latest last time I checked)
  2. Started Promtail (helm chart version 3.0.5, which was latest last time I checked) to tail '...'
  3. Query: logcli query '{app="nginx",job="fifteen5/nginx"} | json | log=~".*"'

Expected behavior
All nginx logs to be returned.

Environment:

  • Infrastructure: kubernetes
  • Deployment tool: helm

Screenshots, Promtail config, or terminal output
If applicable, add any output to help explain your problem.

The same query on a different field worked:
logcli query '{app="nginx",job="fifteen5/nginx"} | json | stream=~".*"'

Using an exact match works:
{app="nginx",job="fifteen5/nginx"} | json | log="10.51.82.226 - - [04/Mar/2021:01:33:52 +0000] \"GET / HTTP/1.1\" 404 118 \"-\" \"ELB-HealthChecker/2.0\"\n"

Here's an example of the log line that should be showing up:
{"log":"10.51.82.226 - - [04/Mar/2021:01:33:52 +0000] \"GET / HTTP/1.1\" 404 118 \"-\" \"ELB-HealthChecker/2.0\"\n","stream":"stdout","time":"2021-03-04T01:33:52.615363491Z"}

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

ohhhh wait maybe this is it:

https://prometheus.io/docs/prometheus/latest/querying/basics/

Vector selectors must either specify a name or at least one label matcher that does not match the empty string. The following expression is illegal:

{job=~".*"} # Bad!

That's reallly weird..... .* is a valid regex. :|

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

I had other problems with it too, I'll have to go back and test this again.

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

ah {app="nginx"} | json | log=~".+" still fails (as in returns no logs when it should)

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

What's also weird is if .* is invalid why would it work for stream but not log? I feel like there's either a bug or I'm missing something major here 🤔

@paaacman
Copy link
Contributor

paaacman commented Mar 4, 2021

Workaround : use line_format to access Line filter:
{app="nginx",job="fifteen5/nginx"} | json | line_format "{{.log}}" |= "is not found"

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

I found the reason - the newline in the log is messing things up.
{app="nginx"} | json | log=~".+\n" works!

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

and here's the other part of the puzzle - the prometheus docs say Regex-matches are fully anchored. This explains why partial matches were not working, I have to match the entire string.

@caleb15
Copy link
Contributor Author

caleb15 commented Mar 4, 2021

and the last thing I found is if I want . to match newline I can enable the single line flag, like so:
{app="nginx"} | json | log =~ "(?s).*is not found.*"

@caleb15 caleb15 closed this as completed Mar 4, 2021
@caleb15 caleb15 changed the title Logcli field regex does not work with "log" field specifically Logcli field regex does not return results Mar 4, 2021
caleb15 added a commit to caleb15/loki that referenced this issue Mar 4, 2021
to prevent people from running into grafana#3436
owen-d pushed a commit that referenced this issue Mar 8, 2021
to prevent people from running into #3436
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

Successfully merging a pull request may close this issue.

2 participants