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

Log Context #992

Merged
merged 7 commits into from
Oct 11, 2024
Merged

Log Context #992

merged 7 commits into from
Oct 11, 2024

Conversation

SpencerTorres
Copy link
Collaborator

@SpencerTorres SpencerTorres commented Sep 20, 2024

Overview

This PR implements Log Context for logs queries.

feature overview screenshot

show log context button

Implementation

This feature works by taking a logs query and removing all filters and ORDER BYs. Filters are then re-added for every log context column that is matched in the log row. These filters will match a column using the = operator with the exact value from the selected row. These context columns can be configured on the datasource config page.

A time range filter is also added based on the selected time column. An ORDER BY and LIMIT are also added. Two queries are generated in each direction of the log row. You can scroll up and down in either direction to load more pages from the last timestamp offset.

Log Context Column Configuration:

Log context columns should be the minimum number of columns required to narrow your log row to a single source. For most datasets this will likely be some combination of a service name, host name, container ID, or pod name. Keep in mind that this should also match your ClickHouse table's primary key for optimal performance.

Log Context Column Configuration

You must SELECT at least one of these context columns in order for the feature to work. The columns must be selected in order to read the value for filtering. If columns are not configured, or none are matched, the following warning is displayed:

no context columns matched warning

For faster query building, you may enable the Auto-Select Columns setting. This will automatically include the context columns in your SELECT, even if OTel is enabled.

auto column selection example

When your log row matches your context columns, they will be shown at the top where they can be easily copied.

matched context column values

A note for Map columns

Use bracket syntax in the config. If your context columns are defined as ResourceAttributes['container.id'] and ResourceAttributes['host.name'], you can simply select ResourceAttributes and the plugin will be able to match multiple keys inside the map. Individual field selection works too. Without an alias ClickHouse will name these arrayElement(ResourceAttributes, 'container.id'), but the plugin will still identify these.

@mshustov
Copy link
Collaborator

Keep in mind that this should also match your ClickHouse table's primary key for optimal performance.

Do we enforce the right order for filter fields?

Use bracket syntax in the config. If your context columns are defined..

We'll need to extend the guide to recommend the field aliasing feature

@RoryCrispin
Copy link

Brilliant! 👍

@SpencerTorres
Copy link
Collaborator Author

Do we enforce the right order for filter fields?

I don't think they need a specific order, the query analyzer should handle that right?

We'll need to extend the guide to recommend the field aliasing feature

Using ALIAS columns would work well with this. Same as if you extracted a column in a materialized view

Copy link
Contributor

@aangelisc aangelisc left a comment

Choose a reason for hiding this comment

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

This LGTM, just one nit in the comments. I believe it'd be worthwhile updating the documentation to include some of the information you've specified in the PR description as it's extremely beneficial.

@SpencerTorres
Copy link
Collaborator Author

Still suspicious of the yarn lockfile, but that last type is fixed

@mshustov mshustov requested a review from aangelisc October 5, 2024 04:43
@aangelisc aangelisc merged commit b42eb03 into grafana:main Oct 11, 2024
15 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.

4 participants