grafana-zabbix icon indicating copy to clipboard operation
grafana-zabbix copied to clipboard

Perl regex syntax no longer accepted in any filter (plugin 4.2.1, Grafana 8.1.1)

Open eithor opened this issue 3 years ago • 30 comments

Describe the bug After update to 4.2.1 plugin (and grafana 8.1.1) any panel with an item/application/host/group filter that uses Perl regex syntax will show no-data. Using simpler regex syntax shows data as normal. Tried to switch from old "Graph" viz to the new "Time series" without any change in behaviour.

Expected behavior Time-series graph shown also for Perl regex syntax filters as the same syntax worked previously (grafana 7.x/8.0 and plugin 4.1.5). Edit: it also works with grafana 8.1.2+plugin 4.1.5 (but that has other issues)

Network data

{"queries":[{"application":{"filter":"CPU"},"countTriggers":true,"functions":[],"group":{"filter":"/^Linux servers$/"},"host":{"filter":"/^mgc01$/"},"item":{"filter":"/^CPU (?!idle|usage|ready)/"},"minSeverity":3,"options":{"disableDataAlignment":false,"showDisabledItems":false,"skipEmptyValues":false,"useZabbixValueMapping":false},"proxy":{"filter":""},"queryType":"0","refId":"A","resultFormat":"time_series","table":{"skipEmptyValues":false},"tags":{"filter":""},"trigger":{"filter":""},"triggers":{"acknowledged":2,"count":true,"minSeverity":3},"itemTag":{"filter":"Application: CPU"},"datasource":"Zabbix","datasourceId":1,"intervalMs":10000,"maxDataPoints":931}],"range":{"from":"2021-08-12T05:34:20.111Z","to":"2021-08-12T08:34:20.111Z","raw":{"from":"now-3h","to":"now"}},"from":"1628746460111","to":"1628757260111"}

{"results":{"A":{"error":"error parsing regexp: invalid or unsupported Perl syntax: (?!","frames":[]}}}

Software versions

Grafana Zabbix Grafana-Zabbix Plugin
8.1.1 5.2.7 4.2.1

eithor avatar Aug 12 '21 08:08 eithor

@eithor as a workaround, try to scape the forward slash with a double one, something like: "//" instead a single one "/"

@alexanderzobnin I can confirm the bug, linux partitions in item name like "Used Space on /var/log" suffer from this too, I needed to double type "//var//log" in grafana field to make it work.

Looking at the error it seems to be something in golang backend.

isaqueprofeta avatar Aug 18 '21 19:08 isaqueprofeta

I confirm this issue. Using regex in host field as /^(?!.*somehostname)/ doesn't render any data. But replacing it with /.*/ is working.

So, the current workaround is downgrade to 4.1.5.

Waiting for the resolution.

mrh666 avatar Aug 23 '21 09:08 mrh666

If I can put my 2 cents here, seems like the regex processing has moved from react frontend to golang backend, since there's a lot of lookahead/lookbehind errors with Perl like errors.

If anyone can test (I'm in a pinch right now) try this documentation for creating the regex (it's the golang flavor): https://github.com/google/re2/wiki/Syntax

isaqueprofeta avatar Aug 23 '21 14:08 isaqueprofeta

@eithor please, can you change your issue title? I'd say: "Perl related error when parsing Regex"

The truth is: "Javascript regex syntax no longer accepted in any filter" because the original flavor that we use is Javascript Regex. And the error is that there's a Javascript expression when the software says that it wanted a Perl like expression.

isaqueprofeta avatar Aug 23 '21 15:08 isaqueprofeta

Same for me in Grafana 8.1.2 and plugin version 4.2.x

vryzhevsky avatar Aug 24 '21 10:08 vryzhevsky

@eithor please, can you change your issue title? I'd say: "Perl related error when parsing Regex"

The truth is: "Javascript regex syntax no longer accepted in any filter" because the original flavor that we use is Javascript Regex. And the error is that there's a Javascript expression when the software says that it wanted a Perl like expression.

Well, as I understand it, it is more that Javascript regex support Perl-style regex syntax and golang does not (according to your link to re2). Still, end result is that plugin 4.2.x no longer supports Perl-style regex syntax - and changing all the dashboards to not use Perl-style regex is a huge undertaking (if possible).

eithor avatar Aug 24 '21 11:08 eithor

Yes, that's true. Since all data processing now moved to the bakend, regexps evaluated in Go. Go has a bit different engine (RE2) than JS, so some of existing patterns no longer supported. The syntax accepted by Golang described at https://golang.org/s/re2syntax.

Unfortunately, I do not see any straightforward solution for this problem right now. I'll leave this issue opened and wait for more feedback. Maybe someone can suggest a workaround/fix.

alexanderzobnin avatar Aug 25 '21 11:08 alexanderzobnin

What about the need to double type literal forward slashes? It'll be a new default? Better doc it at least IMHO.

isaqueprofeta avatar Aug 25 '21 13:08 isaqueprofeta

@isaqueprofeta I have to investigate it a little bit more. But I agree, docs should be improved.

alexanderzobnin avatar Aug 25 '21 13:08 alexanderzobnin

@alexanderzobnin Since it works with Grafana 8.1.x and plugin 4.1.5, does this mean that you have changed your plugin to use backend instead of frontend regex parsing? What I'm asking perhaps is this: is this a forced choice by a Grafana API change, or a (needed) change that is introduced only in the grafana-zabbix plugin?

eithor avatar Aug 25 '21 13:08 eithor

@eithor It's a change introduced by plugin. In order to make alerting working with queries that contain functions, data processing should be on the backend. But it does not make sense to keep functions both on the frontend (non-alerting queries) and backend because it's tricky to support 2 different implementations. So now queries are fully handled on the backend. It's also better from the performance perspective.

alexanderzobnin avatar Aug 25 '21 14:08 alexanderzobnin

@alexanderzobnin I understand it complicates things, though not being able to say "give me all matches except those with the word XXX in them" will make the filtering very limited. I'm not sure how we could workaround this. Even your own plugin documentation example uses negative matching (perl regex syntax).

eithor avatar Aug 25 '21 14:08 eithor

It should be possible to use PCRE library either directly or via existing Golang wrappers.

i-ky avatar Aug 25 '21 14:08 i-ky

i-ky: Good call, a quick google gave me this example that uses golang pcre lib/wrapper: https://golangbyexample.com/golang-regex-backreferences/

eithor avatar Aug 25 '21 15:08 eithor

Nice! I'll take a look. if glenn-brown/golang-pkg-pcre does not have any external dependencies, it looks like it definitely worth to use instead of built-in go regex engine.

alexanderzobnin avatar Aug 31 '21 15:08 alexanderzobnin

+1

cisco82 avatar Sep 09 '21 12:09 cisco82

I confirm this issue. Using regex in host field as /^(?!.*somehostname)/ doesn't render any data. But replacing it with /.*/ is working.

So, the current workaround is downgrade to 4.1.5.

Waiting for the resolution.

emmmmm, why /.*/ is not working in my Grafana. (Grafana version: 8.1.2, Plugin version: 4.2.2)

image

I think the regex of grafana-zabbix has something wrong because the same panel in Grafana7.5.3 and plugin 4.1.5 is working.

white3 avatar Sep 12 '21 03:09 white3

in addition to white3: regex is working on Group and Host level, but not in "Item Tag" or "Item"

grafik

jeff42 avatar Sep 14 '21 13:09 jeff42

Unfortunately, glenn-brown/golang-pkg-pcre is not supported on Windows since it's wrapper around a C library for the Linux. So I don's see any easy way to fix it now. :disappointed:

alexanderzobnin avatar Sep 15 '21 14:09 alexanderzobnin

I do not get, why regex is working in Group and host field (green) but not on item tag or item (red). even a simple /.*/ is not working

maybe these are two different issues

jeff42 avatar Sep 15 '21 16:09 jeff42

@jeff42, yes, looks like this is another issue.

alexanderzobnin avatar Sep 16 '21 06:09 alexanderzobnin

@jeff42 it should be fixed with #1275, so just wait for the next patch release.

alexanderzobnin avatar Sep 16 '21 06:09 alexanderzobnin

@alexanderzobnin What about this one: https://github.com/dlclark/regexp2 as an alternative that should work on Windows.

eithor avatar Sep 16 '21 19:09 eithor

@alexanderzobnin Or... this blog shows how to use libpcre also on Windows: https://xrstf.de/2018/04/go-regexp-vs-pcre/

eithor avatar Sep 16 '21 19:09 eithor

@eithor dlclark/regexp2 looks promising. I will try to use it. I don't want to introduce any external dependencies because it's a pain for end users. I believe plugin usage should be as simple as possible.

alexanderzobnin avatar Sep 21 '21 10:09 alexanderzobnin

@alexanderzobnin May I ask for an update on this issue?

eithor avatar Jan 06 '22 14:01 eithor

Any update in this? It is really critical. Regular expressions are widely beeing used in Grafana. So if you broke regexp, you broke many things!

vryzhevsky avatar Jan 24 '22 07:01 vryzhevsky

image Any updates on this issue? It is broken for more than half a year(!)

vldbel avatar Apr 20 '22 12:04 vldbel

Is there still no solution for this?

datacosmos1 avatar Jul 05 '22 13:07 datacosmos1

@alexanderzobnin Please, please have a look at PR #1472 to close this issue. I cannot upgrade Zabbix past 6.0 without this fix (since I would need the 4.2.9 fix for 6.2+).

eithor avatar Jul 21 '22 13:07 eithor