Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ sphinx>=8.1.3
sphinx_design>=0.6.1
sphinx-copybutton>=0.5.2
sphinxcontrib-mermaid>=1.0.0

# Lock to v2.* to work around https://github.com/sphinx-doc/sphinx/issues/13533
snowballstemmer~=2.2
92 changes: 92 additions & 0 deletions docs/src/dev-guide/design-kv-ir-streams/auto-gen-kv-pairs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Auto-generated KV pairs

Copy link
Copy Markdown
Contributor

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:

-# Auto-generated KV pairs
+# Auto-generated KV Pairs
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Auto-generated KV pairs
# 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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.
logging library added the timestamp and level KV pairs automatically.
Although the keys for the message, timestamp, and log level can be configured via Zap options,
storing these two categories of KV pairs in a format like JSON requires additional effort to prevent
keys conflicts, since both categories share the same key namespace:
* Users must avoid selecting keys that might conflict with those used by the logging framework—-this
may even require knowledge of all reserved keys.
* The logging library must choose keys that are unlikely to collide with user-defined keys, and
still implement a policy to resolve any conflicts that do occur.
  • Add a little more details to explain why this is really a headache and inevitable.
  • How about using users instead a user? Feel like it's easier to read.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do you mean "A user"?

Comment thread
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
}
```
Comment thread
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Missing Article:
Add the article “a” before “user-generated KV pair” so the sentence reads:

“…both an auto-generated KV pair and a user-generated KV pair with the key timestamp…”

🧰 Tools
🪛 LanguageTool

[uncategorized] ~61-~61: You might be missing the article “a” here.
Context: ... has both an auto-generated KV pair and user-generated KV pair with the key `timesta...

(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.
Comment thread
kirkrodrigues marked this conversation as resolved.
Resolved

## Additional benefits

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Heading Case Consistency
Apply Title Case to this section header:

-## Additional benefits
+## Additional Benefits
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Additional benefits
## Additional Benefits


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Reduce Redundancy in Phrase
The phrase “auto-generated KV pairs” appears twice in the same sentence. Consider tightening it for readability:

-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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

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
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.
For instance, if a user is logging in both Java and Python, and they use CLP logging

plugins to generate KV-IR streams, the streams generated should both use the same key for log

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
plugins to generate KV-IR streams, the streams generated should both use the same key for log
plugins to generate KV-IR streams, the generated streams should both use the same key for log

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.
Comment thread
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Hyphenation in “key-less”
For consistency with common usage, consider using “keyless” without a hyphen:

-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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
:::{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.
:::
:::{note}
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, formatted into a single string.
:::


[json-lines]: https://jsonlines.org/
[log-viewer]: https://github.com/y-scope/yscope-log-viewer
[Zap]: https://github.com/uber-go/zap
5 changes: 3 additions & 2 deletions docs/src/dev-guide/design-kv-ir-streams/background.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ As [Figure 3](#figure-3) shows, the archive-level schema tree uses different *na
more than just the KV pairs that appear *in* the event. For instance, the `Metadata` namespace
contains metadata KV pairs like the log event's index in the archive. The `Default` namespace
contains the KV pairs that aren't specific to a special namespace, which in the case of Figure 3,
are the KV pairs that appear in the example log events. As we'll see in future docs, namespaces
also allow clp-s to compress log events that contain namespaces themselves.
are the KV pairs that appear in the example log events. As we'll see in the docs about
[auto-generated KV pairs](auto-gen-kv-pairs.md), namespaces also allow clp-s to compress log events
that contain namespaces themselves.

To merge an event's schema tree with the archive-level schema tree, clp-s iterates over each pair of
nodes---one from each tree:
Expand Down
8 changes: 8 additions & 0 deletions docs/src/dev-guide/design-kv-ir-streams/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Background
^^^
Any necessary information to understand the stream's format.
:::

:::{grid-item-card}
:link: auto-gen-kv-pairs
Auto-generated KV pairs
^^^
An overview of auto-generated KV pairs and their handling in streams.
:::
::::

:::{warning}
Expand All @@ -26,4 +33,5 @@ Any necessary information to understand the stream's format.
:hidden:

background
auto-gen-kv-pairs
:::