Repository navigation
docs(kv-ir): Explain support for auto-generated KV pairs. #888
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
Changes from 3 commits
c4694a5
158a9c2
b123477
f11f740
d039768
1f7ff57
5ceb79c
86b9ea7
b5abf07
3f404b4
b5f964a
dcf7775
a0af1aa
9a24dd9
9a29ddd
3b839e6
8d9d556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||||||||||||||||||||||||||||
| # Auto-generated KV pairs | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| One of the key differences between KV-IR streams and a format like [JSON lines][json-lines] is that | ||||||||||||||||||||||||||||||||
| KV-IR streams support storing KV pairs generated by the logging framework separately from those | ||||||||||||||||||||||||||||||||
| generated by the user. For instance, consider the structured [Zap] log printing statement (LPS) in | ||||||||||||||||||||||||||||||||
| [Figure 1](#figure-1) and its output, as JSON, in [Figure 2](#figure-2). Comparing the user-defined | ||||||||||||||||||||||||||||||||
| KV pairs in [Figure 1](#figure-1) and the output in [Figure 2](#figure-2), we can see that the | ||||||||||||||||||||||||||||||||
| logging library added the timestamp and level KV pairs automatically. (The key for the message, | ||||||||||||||||||||||||||||||||
| timestamp, and log level are Zap configuration options.) Storing these two categories of KV pairs in | ||||||||||||||||||||||||||||||||
| a format like JSON has the disadvantage that both categories share the same key namespace; so a user | ||||||||||||||||||||||||||||||||
| needs to pick keys that don't conflict with the logging library's keys, and the logging library | ||||||||||||||||||||||||||||||||
| needs to pick keys that are unlikely to conflict with a user's keys. | ||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean "A user"?
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| (figure-1)= | ||||||||||||||||||||||||||||||||
| :::{card} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ```go | ||||||||||||||||||||||||||||||||
| logger.Info("Task completed successfully.", | ||||||||||||||||||||||||||||||||
| zap.String("task", task_id), | ||||||||||||||||||||||||||||||||
| zap.Int("pending_tasks", 2), | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| +++ | ||||||||||||||||||||||||||||||||
| **Figure 1**: An example structured LPS. | ||||||||||||||||||||||||||||||||
| ::: | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| (figure-2)= | ||||||||||||||||||||||||||||||||
| :::{card} | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ```json | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| "ts":1708161000.123456, | ||||||||||||||||||||||||||||||||
| "level": "info", | ||||||||||||||||||||||||||||||||
| "message": "Task completed successfully.", | ||||||||||||||||||||||||||||||||
| "task": "task_1", | ||||||||||||||||||||||||||||||||
| "pending_tasks": 2 | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| +++ | ||||||||||||||||||||||||||||||||
| **Figure 2**: The JSON output of the LPS in [Figure 1](#figure-1). | ||||||||||||||||||||||||||||||||
| ::: | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| We define the two categories of KV pairs as follows: | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| 1. *auto-generated* KV pairs: those inserted automatically by a logging framework. | ||||||||||||||||||||||||||||||||
| 2. *user-generated* KV pairs: user-defined KV pairs inserted explicitly by the user. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| In [Figure 2](#figure-2), we categorize the timestamp and level KV pairs as auto-generated. (Even | ||||||||||||||||||||||||||||||||
| though the user's logging statement determines the value of the log-level kv-pair, the user doesn't | ||||||||||||||||||||||||||||||||
| explicitly insert it into the log event as a kv-pair.) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| As we'll see below, storing auto-generated and user-generated KV pairs requires a more advanced | ||||||||||||||||||||||||||||||||
| query syntax, but also has a few additional benefits. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ## Querying auto-generated KV pairs | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Since KV-IR streams store auto-generated KV pairs and user-generated KV pairs in different | ||||||||||||||||||||||||||||||||
| namespaces, we differentiate which namespace to query using special query syntax. For instance, if a | ||||||||||||||||||||||||||||||||
| log event has both an auto-generated KV pair and user-generated KV pair with the key `timestamp`, we | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Missing Article:
🧰 Tools🪛 LanguageTool[uncategorized] ~61-~61: You might be missing the article “a” here. (AI_EN_LECTOR_MISSING_DETERMINER_A) |
||||||||||||||||||||||||||||||||
| need some way to allow the user to query one of the two. We could use two different queries, one to | ||||||||||||||||||||||||||||||||
| query each namespace, but this wouldn't allow users to join filters from both namespaces. Instead, | ||||||||||||||||||||||||||||||||
| we use the key-prefix `@` to denote a filter on an auto-generated KV pair---e.g., `@timestamp: 0` | ||||||||||||||||||||||||||||||||
| denotes a filter for an auto-generated KV pair with the key `timestamp` and value `0`. Accordingly, | ||||||||||||||||||||||||||||||||
| filters on user-generated KV pairs whose keys start with the character `@` will need to escape the | ||||||||||||||||||||||||||||||||
| `@` symbol. | ||||||||||||||||||||||||||||||||
|
kirkrodrigues marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| ## Additional benefits | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Heading Case Consistency -## Additional benefits
+## Additional Benefits📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| One benefit of supporting auto-generated KV pairs is that our CLP logging libraries or plugins can | ||||||||||||||||||||||||||||||||
| use a consistent set of keys for auto-generated KV pairs, making it easier for users to filter for | ||||||||||||||||||||||||||||||||
| those keys. For instance, if a user is logging in both Java and Python, and they use CLP logging | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Reduce Redundancy in Phrase -One benefit of supporting auto-generated KV pairs is that our CLP logging libraries or plugins can use a consistent set of keys for auto-generated KV pairs, making it easier for users to filter for those keys.
+One benefit is that our CLP logging libraries or plugins can standardize keys for auto-generated pairs, making it easier for users to filter them.📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
| plugins to generate KV-IR streams, the streams generated should both use the same key for log | ||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Should sound more natural? |
||||||||||||||||||||||||||||||||
| levels---e.g., `level`. In turn, this would allow users to query log levels across both their Java | ||||||||||||||||||||||||||||||||
| and Python logs using the query syntax `@level: <value>`. In addition, it would allow users to use | ||||||||||||||||||||||||||||||||
| the same key to filter their logs by level when viewing them in the [log viewer][log-viewer]. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Another benefit of supporting auto-generated KV pairs is that we can potentially leverage | ||||||||||||||||||||||||||||||||
| the query syntax for more advanced queries on unstructured text KV pairs. For instance, we could | ||||||||||||||||||||||||||||||||
| support a syntax like `@message` to query the KV pair, `mesage`, and the syntax `@message.#vars[0]` | ||||||||||||||||||||||||||||||||
| to query the first variable parsed from the KV pair. We'll explore this further once the feature has | ||||||||||||||||||||||||||||||||
| been implemented. | ||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| :::{note} | ||||||||||||||||||||||||||||||||
| The reason we categorize unstructured text KV pairs as auto-generated is because we see them as a | ||||||||||||||||||||||||||||||||
| set of key-less auto-generated and user-generated values, formatted into a single string. | ||||||||||||||||||||||||||||||||
| ::: | ||||||||||||||||||||||||||||||||
|
Comment on lines
+92
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Hyphenation in “key-less” -The reason we categorize unstructured text KV pairs as auto-generated is because we see them as a set of key-less auto-generated and user-generated values...
+The reason we categorize unstructured text KV pairs as auto-generated is because we see them as a set of keyless auto-generated and user-generated values...📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [json-lines]: https://jsonlines.org/ | ||||||||||||||||||||||||||||||||
| [log-viewer]: https://github.com/y-scope/yscope-log-viewer | ||||||||||||||||||||||||||||||||
| [Zap]: https://github.com/uber-go/zap | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Title Capitalization:
Ensure consistency with other guide sections by using Title Case in the heading. For example, change:
📝 Committable suggestion