Skip to content

incorrect interpolating query with variable inside the reg exp #449

@frli4797

Description

@frli4797

Describe the bug

When using a query like _time:16h {host=~"(?i)$host",job="rsyslog",level=~"(error|warning|critical)"}
an error message is generated and nothing is returned by the query.

error from datasource: cannot parse query [_time:16h {host=~"(?i)"hostname"",job="rsyslog",level=~"(error|warning|critical)"} | sort by (_time) desc]: unexpected token "hostname" in _stream filter after "host=~\"(?i)\""; want 'or', 'and', '}' or ','; context: [_time:16h {host=~"(?i)"hostname]

Running the query in vm-ui works fine, given that the variable is replaced with a valid hostname.

To Reproduce

Create a dashboard widget for a query like _time:16h {host=~"(?i)$host",job="rsyslog",level=~"(error|warning|critical)"}

Error is thrown

Versions of VictoriaLogs datasource and VictoriaLogs backend

Version: victoria-logs-20251114-183126-tags-v1.38.0-0-g83b6b92169
Plugin version: 0.21.4
Grafana: v12.2.1

Link to dashboard in Victoria Metrics

No response

Please provide dashboard JSON if it is possible

{
  "id": 157,
  "type": "logs",
  "title": "Syslog errors",
  "gridPos": {
    "x": 0,
    "y": 5,
    "h": 5,
    "w": 21
  },
  "fieldConfig": {
    "defaults": {},
    "overrides": []
  },
  "pluginVersion": "12.2.1",
  "targets": [
    {
      "datasource": {
        "type": "victoriametrics-logs-datasource",
        "uid": "ce80jyaoi1tz4b"
      },
      "editorMode": "code",
      "expr": "_time:16h {host=~\"(?i)$host\",job=\"rsyslog\",level=~\"(error|warning|critical)\"} ",
      "hide": false,
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "victoriametrics-logs-datasource",
    "uid": "ce80jyaoi1tz4b"
  },
  "interval": "1m",
  "options": {
    "showTime": true,
    "showLabels": false,
    "showCommonLabels": false,
    "wrapLogMessage": true,
    "prettifyLogMessage": false,
    "enableLogDetails": true,
    "enableInfiniteScrolling": false,
    "dedupStrategy": "none",
    "sortOrder": "Descending"
  },
  "timeFrom": "16h",
  "hideTimeOverride": false,
  "links": [
    {
      "title": "Details",
      "url": "http://metrics.domain.com/d/ddqxdmho6msjke/log-details?orgId=1&var-host=$host&var-job=rsyslog&var-level=critical&var-level=error&var-level=warning"
    }
  ]
}

Additional information

No response

Metadata

Metadata

Labels

bugSomething isn't workingvl-datasourcewaiting for releaseThe pull request was merged to upstream but not released yet.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions