MCPcopy
hub / github.com/grafana/tempo / TestParseRewrites

Function TestParseRewrites

pkg/traceql/parse_test.go:1961–2006  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1959}
1960
1961func TestParseRewrites(t *testing.T) {
1962 tests := []struct {
1963 name string
1964 query string
1965 want string
1966 }{
1967 {
1968 name: "no rewrites",
1969 query: "{ .attr = `foo` }",
1970 want: "{ .attr = `foo` }",
1971 },
1972 {
1973 name: "query with rewrite OR",
1974 query: "{ .attr = `foo` || .attr = `bar` } | rate()",
1975 want: "{ .attr IN [`foo`, `bar`] } | rate()",
1976 },
1977 {
1978 name: "query with rewrite AND",
1979 query: "{ .attr != `foo` && .attr != `bar` }",
1980 want: "{ .attr NOT IN [`foo`, `bar`] }",
1981 },
1982 {
1983 name: "query with rewrite OR regex",
1984 query: "{ .attr =~ `foo` || .attr =~ `bar` }",
1985 want: "{ .attr MATCH ANY [`foo`, `bar`] }",
1986 },
1987 {
1988 name: "query with rewrite AND regex",
1989 query: "{ .attr !~ `foo` && .attr !~ `bar` }",
1990 want: "{ .attr MATCH NONE [`foo`, `bar`] }",
1991 },
1992 {
1993 name: "skip rewrites via unsafe hint",
1994 query: "{ .attr = `foo` || .attr = `bar` } | rate() with(skip_ast_transformations=`or_to_in`)",
1995 want: "{ (.attr = `foo`) || (.attr = `bar`) } | rate() with(skip_ast_transformations=`or_to_in`)",
1996 },
1997 }
1998
1999 for _, tc := range tests {
2000 t.Run(tc.name, func(t *testing.T) {
2001 actual, err := Parse(tc.query, WithUnsafeHints(true))
2002 require.NoError(t, err)
2003 require.Equal(t, tc.want, actual.String())
2004 })
2005 }
2006}
2007
2008func TestMetricsFilter(t *testing.T) {
2009 tests := []struct {

Callers

nothing calls this directly

Calls 5

ParseFunction · 0.85
WithUnsafeHintsFunction · 0.85
RunMethod · 0.45
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected