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

Support quoted attribute in traceql #3004

Merged
merged 11 commits into from
Oct 17, 2023

Conversation

kousikmitra
Copy link
Contributor

@kousikmitra kousikmitra commented Oct 11, 2023

What this PR does:
This PR extends the traceql lexer to lex quoted attribute names (ex: span."foo bar") this will help searching tempo with span attributes containing breaking characters like =, " etc.

Which issue(s) this PR fixes:
Fixes #2805

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Comment on lines 124 to 126
It's possible that attributes name can contain terminal characters, to search span attributes with terminal character you can use quoted attribute syntax. A quoted attirbute should be enclosed inside double quote and all characters between the quotes will be considered part of the attribute name.

For example, to find span with attribute name `attribute name with space` one can use the following query
Copy link
Contributor

@knylander-grafana knylander-grafana Oct 12, 2023

Choose a reason for hiding this comment

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

Thank you for adding documentation! These suggestions correct a few grammatical issues and separate run-on sentence. For more information, refer to the Writers' Toolkit.

Suggested change
It's possible that attributes name can contain terminal characters, to search span attributes with terminal character you can use quoted attribute syntax. A quoted attirbute should be enclosed inside double quote and all characters between the quotes will be considered part of the attribute name.
For example, to find span with attribute name `attribute name with space` one can use the following query
Attribute names can contain terminal characters, such as a period (`.`). To search span attributes with terminal characters, you can use quoted attribute syntax. A quoted attribute should be enclosed inside double quotes, for example, `"example one"`. All characters between the quotes are considered part of the attribute name.
For example, to find span with attribute name `attribute name with space`, you can use the following query:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot. 🙂 I have made the changes and will refer to the mentioned style guide going forward.

{ span.attribute."attribute name with space" = "value" }
```

Note: Only `\"` and `\\` escape sequence are supported as of now.
Copy link
Contributor

Choose a reason for hiding this comment

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

This change uses the shortcode for a Note admonition. Using shortcodes helps us separate content from presentation. To learn more about the shortcode, refer to the Writers' Toolkit.

Suggested change
Note: Only `\"` and `\\` escape sequence are supported as of now.
{{% admonition type="note" %}}
Currently, only `\"` and `\\` escape sequence are supported.
{{% /admonition %}}

CHANGELOG.md Outdated
@@ -1,4 +1,5 @@
## main / unreleased
* [ENHANCEMENT] Support quoted attribute name in traceql [#3004](https://github.com/grafana/tempo/pull/3004) (@kousikmitra)
Copy link
Contributor

Choose a reason for hiding this comment

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

Correcting capitalization for TraceQL.

Suggested change
* [ENHANCEMENT] Support quoted attribute name in traceql [#3004](https://github.com/grafana/tempo/pull/3004) (@kousikmitra)
* [ENHANCEMENT] Support quoted attribute name in TraceQL [#3004](https://github.com/grafana/tempo/pull/3004) (@kousikmitra)

Copy link
Contributor

@knylander-grafana knylander-grafana left a comment

Choose a reason for hiding this comment

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

Thank you for updating the doc! I've made some suggestions to help clarify the content you added. Please let me know if you have any questions.

Copy link
Member

@joe-elliott joe-elliott left a comment

Choose a reason for hiding this comment

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

nice work! had some thoughts and questions

pkg/traceql/parse_test.go Show resolved Hide resolved
pkg/traceql/parse_test.go Show resolved Hide resolved
pkg/traceql/parse_test.go Show resolved Hide resolved
pkg/traceql/lexer.go Outdated Show resolved Hide resolved
pkg/traceql/lexer.go Outdated Show resolved Hide resolved
Copy link
Member

@joe-elliott joe-elliott left a comment

Choose a reason for hiding this comment

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

Looks great! One last request. Can we get a test added at this level to really confirm everything is working as intended:

https://github.com/grafana/tempo/blob/main/tempodb/tempodb_search_test.go#L73

I linked the test that made the most sense to me, but if you want to put it in a different runner or add a new one you are welcome to.

pkg/traceql/parse_test.go Show resolved Hide resolved
return sb.String(), nil
}

func tryScopeAtribute(l *scanner.Scanner) (int, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func tryScopeAtribute(l *scanner.Scanner) (int, bool) {
func tryScopeAttribute(l *scanner.Scanner) (int, bool) {

Copy link
Member

@jdbaldry jdbaldry left a comment

Choose a reason for hiding this comment

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

@knylander-grafana We might want to expand on the explanation of escape sequences. WDYT?

I've proposed some adjustments to the docs to fix some typos and remove some extraneous words.

@@ -119,6 +119,26 @@ For example, to find traces with an attribute of `sla` set to `critical`:
{ .sla = "critical" }
```

### Quoted attribute names

Attribute names can contain terminal characters, such as a period (`.`). To search span attributes with terminal characters, you can use quoted attribute syntax. A quoted attribute should be enclosed inside double quotes, for example, `"example one"`. All characters between the quotes are considered part of the attribute name.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Semantic line breaks are better for future line based diffing in the GitHub UI and result in the same HTML output.

Suggested change
Attribute names can contain terminal characters, such as a period (`.`). To search span attributes with terminal characters, you can use quoted attribute syntax. A quoted attribute should be enclosed inside double quotes, for example, `"example one"`. All characters between the quotes are considered part of the attribute name.
Attribute names can contain terminal characters, such as a period (`.`).
To search span attributes with terminal characters, you can use quoted attribute syntax.
A quoted attribute should be enclosed inside double quotes, for example, `"example one"`.
All characters between the quotes are considered part of the attribute name.

Comment on lines 126 to 135
For example, to find span with attribute name `attribute name with space`, you can use the following query:
```
{ ."attribute name with space" = "value" }
```
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
For example, to find span with attribute name `attribute name with space`, you can use the following query:
```
{ ."attribute name with space" = "value" }
```
To find a span with the attribute name `attribute name with space`, use the following query:
```
{ ."attribute name with space" = "value" }
```

Comment on lines 131 to 141
You can use quoted attributes syntax with non-quoted attribute syntax.

For example, the syntax below is a valid TraceQL query.
```
{ span.attribute."attribute name with space" = "value" }
```
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can use quoted attributes syntax with non-quoted attribute syntax.
For example, the syntax below is a valid TraceQL query.
```
{ span.attribute."attribute name with space" = "value" }
```
You can use quoted attributes syntax with non-quoted attribute syntax, the following is a valid TraceQL query:
```
{ span.attribute."attribute name with space" = "value" }
```

```

{{% admonition type="note" %}}
Currently, only `\"` and `\\` escape sequence are supported.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Currently, only `\"` and `\\` escape sequence are supported.
Currently, only the `\"` and `\\` escape sequences are supported.

@kousikmitra
Copy link
Contributor Author

@joe-elliott @jdbaldry Made the requested changes. Let me know if this is ok.

Copy link
Member

@joe-elliott joe-elliott left a comment

Choose a reason for hiding this comment

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

Great work!

@joe-elliott joe-elliott merged commit bdac8e9 into grafana:main Oct 17, 2023
15 checks passed
@kousikmitra kousikmitra deleted the feature/quoted-attribute branch October 17, 2023 18:45
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.

[TraceQL Enhancement] Quoted attribute names
5 participants