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

7703 metricsql support metric names in quotes as alternative to name metric pattern #40

Conversation

possibull
Copy link
Contributor

Enhance MetricsQL to support quoted UTF8 label names

@possibull possibull marked this pull request as ready for review January 14, 2025 23:20
@possibull possibull marked this pull request as draft January 14, 2025 23:34
Fixed bug with error not reporting because of isPossibleMetric being when a label name was not quoted
@possibull possibull marked this pull request as ready for review January 15, 2025 21:10
parser.go Outdated Show resolved Hide resolved
parser.go Outdated Show resolved Hide resolved
parser_example_test.go Outdated Show resolved Hide resolved
Added tests to ensure setting two metric names threw errors
@possibull possibull requested a review from hagen1778 January 21, 2025 00:19
parser.go Show resolved Hide resolved
parser.go Show resolved Hide resolved
parser_test.go Show resolved Hide resolved
parser.go Outdated Show resolved Hide resolved
@hagen1778 hagen1778 requested a review from valyala January 22, 2025 12:03
parser.go Show resolved Hide resolved
Refactored code checking for quoted strings into isQuoteString
Added some additional tests
@possibull possibull requested a review from hagen1778 January 22, 2025 17:07
parser_test.go Outdated Show resolved Hide resolved
@possibull possibull requested a review from hagen1778 January 23, 2025 10:53
@possibull
Copy link
Contributor Author

possibull commented Jan 23, 2025

It would seem prettifier.go does not use the same WITH expand (which is where all the code to generate metricName is) as Parse(). It first uses parseInternal() and then does its own parsing via appendPrettifiedExpr(). This would need to be changed to get prettify to work properly. This was not caught originally because the case {"foo"} was not an accepted case before.
The good news is this only affects the construction of metricName and adding it to be parsed by getMetricName()

case *MetricExpr:
		// Split:
		//
		//   metric{filters1 or ... or filtersN}
		//
		// into:
		//
		//   metric{
		//     filters1
		//       or
		//     ...
		//       or
		//     filtersN
		//   }
		lfss := t.labelFilterss
		offset := 0
		metricName := getMetricNameFromLabelFilterss(lfss)
		if metricName != "" {
			offset = 1
		}
		dst = appendIndent(dst, indent)
		dst = appendEscapedIdent(dst, metricName)
		if !isOnlyMetricNameInLabelFilterss(lfss) {
			dst = append(dst, "{\n"...)
			for i, lfs := range lfss {
				lfs = lfs[offset:]
				if len(lfs) == 0 {
					continue
				}
				dst = appendPrettifiedLabelFilters(dst, indent+1, lfs)
				dst = append(dst, '\n')
				if i+1 < len(lfss) && len(lfss[i+1]) > offset {
					dst = appendIndent(dst, indent+2)
					dst = append(dst, "or\n"...)
				}
			}
			dst = appendIndent(dst, indent)
			dst = append(dst, '}')
		}
		```

Copy link
Contributor

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
A few minor comments

parser_example_test.go Outdated Show resolved Hide resolved
parser_test.go Outdated Show resolved Hide resolved
possibull and others added 3 commits January 23, 2025 04:15
…ic filters

Co-authored-by: Roman Khavronenko <roman@victoriametrics.com>
…names - this case will now throw an error and is tested in expected Fail cases
@hagen1778 hagen1778 merged commit 72b650d into master Jan 24, 2025
2 checks passed
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 this pull request may close these issues.

metricsql: support metric names in quotes as alternative to __name__="<metric>" pattern
2 participants