Skip to content

Conversation

@abelyakin
Copy link
Contributor

@abelyakin abelyakin commented Jun 27, 2025

Description

This PR introduces a new Loki datasource plugin for Perses, enabling log querying and visualization capabilities. The implementation provides a foundation for log-based observability within Perses dashboards.
perses/perses#2999

Key Features

  • Loki Datasource Plugin: Complete implementation supporting Loki API integration
  • Loki Query Plugin: Enables LogQL query execution with results displayed via Perses table component
  • Basic LogQL Editor: Streamlined editor using @uiw/react-codemirror and @grafana/lezer-logql for syntax highlighting and validation. Autocomplete version is WIP and will be released in future PR's.
  • Logs panel: Panel specialized for logs display. UI heavily inspired from other observability platforms. (Screenshots above)
    • Display logs stream
    • Level color indication
    • Expand / collapse row for details
    • Virtualized table for performance
    • Basic panel configs: Wrap lines, Disable expandable rows, show/hide timestamp.

LogQL Editor will be improved as well as separate Logs panel will be introduced in next PRs.

Screenshots

Screenshot 2025-07-09 at 18 04 03
Screenshot 2025-07-09 at 18 04 18
Screenshot 2025-07-09 at 18 04 12

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

@Gladorme Gladorme changed the title Loki datasource plugin [FEATURE] Loki datasource plugin Jun 27, 2025
}
},
{
"kind": "TimeSeriesQuery",
Copy link
Member

Choose a reason for hiding this comment

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

so here I guess we need to provide another super type of Query. Like LogQuery

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I was thinking about as well. While Loki is primarily a log query datasource, it can also return matrix response data that's consumable by other panels which support time series.

So my idea is to use it as a subclass of TimeSeriesQuery.

Copy link
Contributor

Choose a reason for hiding this comment

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

This plugin will probably support both as we can have metrics from logs which match the time series query format, and specific Logs data that was added perses/perses#3104

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion and PR! I’ve added a separate LokiLogQuery type of LogQuery kind, as introduced in your PR. Now we have distinct query kinds for the two main Loki query types:

  • Streams (actual logs): LokiLogQuery (of LogQuery kind)
  • Matrix (timeseries): LokiTimeSeriesQuery (of TimeSeriesQuery kind)

This separation should make the usage of each query type clearer and also allows panels to explicitly define which query types they support

}
},
{
"kind": "Panel",
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense this panel is an independent plugin instead of being related to the Loki datasource ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The question is, how much (are we confident that) this panel is agnostic to Loki specificities & could be compatible with other future log data sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it makes sense to keep this panel datasource-agnostic. We already have a PR with ClickHouse support #241 , but it currently duplicates current LogsTable code and defines a separate log interface. The panel should consume a small Common Log Envelope, and each datasource (Loki, ClickHouse) maps into that envelope.
ClickHouse itself doesn’t enforce a schema, but since the docs recommend OTEL logs, we should explicitly state that the ClickHouse adapter only supports OTEL and reflect that in the shared interface.

This avoids duplication and lets us add others later (Elasticsearch/OpenSearch etc.) by implementing adapters that emit the same envelope.

Aligning both datasources would require adjusting two PRs at once, which feels like too much for now. I think we should properly discuss the direction first, and I’m open for feedback.

Copy link
Member

Choose a reason for hiding this comment

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

Aligning both datasources would require adjusting two PRs at once, which feels like too much for now. I think we should properly discuss the direction first, and I’m open for feedback.

Well I think having in another PR the TableLogs panel would not hurt and it will open the discussion. Then afterwards we can align both PRs or plugins if the PRs are already merged.

Copy link
Member

Choose a reason for hiding this comment

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

Are you willing to lead the change @abelyakin ? Or at least opening the PR with the single panel, and probably the PR with the small common log envelope ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m willing to lead the change 👍
What I’m wondering is whether it makes sense to approach this in two steps: first merge this panel as is to unblock progress, and then start working on a separate datasource agnostic version. That way we can align adapters without blocking the current PR.

What do you think would be the best sequence of steps here?

Copy link
Member

Choose a reason for hiding this comment

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

yes that would be acceptable as long as the new panel is named LogsTable to avoid a breaking change when the panel contained in this plugin will be removed.

Copy link
Member

Choose a reason for hiding this comment

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

and this is a really cool news you are willing to lead it. Thank you @abelyakin !

abelyakin and others added 4 commits August 19, 2025 17:33
Signed-off-by: Alexander Belyakin <[email protected]>
Co-authored-by: Gabriel Bernal <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
abelyakin and others added 12 commits August 19, 2025 17:33
Signed-off-by: Alexander Belyakin <[email protected]>
Co-authored-by: Antoine THEBAUD <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Co-authored-by: Antoine THEBAUD <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Co-authored-by: Gabriel Bernal <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
@Nexucis
Copy link
Member

Nexucis commented Aug 22, 2025

to fix the CI job ci/lint you need to run go mod tidy in the loki folder that should update the file go.sum.

To fix the ci/build, you need to add the dependencies @grafana/lezer-logql to the file loki/package.json as a dependency.

Also as we bumped again a new version of perses/perses (0.52.0-beta.5) you will need to update again the dependencies.

@Nexucis
Copy link
Member

Nexucis commented Aug 22, 2025

excepting my last comment, I think it's in a good shape. @jgbernalp do you see other things to update in this PR ? Perhaps it should follow also what you are doing in #266 ?

@jgbernalp
Copy link
Contributor

jgbernalp commented Aug 22, 2025

excepting my last comment, I think it's in a good shape. @jgbernalp do you see other things to update in this PR ? Perhaps it should follow also what you are doing in #266 ?

Yes, there was some fixes to add. I took the liberty to also fix the dependencies and add one suggestion regarding the default values of the proxy. PTAL @abelyakin I created a PR on your fork abelyakin#1 that will fix the ci

jgbernalp and others added 3 commits August 22, 2025 13:28
Signed-off-by: Gabriel Bernal <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>
@abelyakin
Copy link
Contributor Author

excepting my last comment, I think it's in a good shape. @jgbernalp do you see other things to update in this PR ? Perhaps it should follow also what you are doing in #266 ?

Yes, there was some fixes to add. I took the liberty to also fix the dependencies and add one suggestion regarding the default values of the proxy. PTAL @abelyakin I created a PR on your fork abelyakin#1 that will fix the ci

Great! thanks, merged.

Signed-off-by: Alexander Belyakin <[email protected]>
@abelyakin
Copy link
Contributor Author

added basic tests since npm-test ci action requires tests for plugin

Copy link
Contributor

@jgbernalp jgbernalp left a comment

Choose a reason for hiding this comment

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

Awesome contribution!

Copy link
Member

@Nexucis Nexucis left a comment

Choose a reason for hiding this comment

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

This is amazing. Thank you for this incredible contribution @abelyakin ! Looking forward for the next one around the common LogsTable!

@Nexucis Nexucis added this pull request to the merge queue Aug 29, 2025
Merged via the queue into perses:main with commit d7dba11 Aug 29, 2025
13 checks passed
rafi-ruetcse17 pushed a commit to rafi-ruetcse17/perses_plugins that referenced this pull request Sep 1, 2025
* init

Signed-off-by: Alexander Belyakin <[email protected]>

* add loki datarource with simple logql query editor

Signed-off-by: Alexander Belyakin <[email protected]>

* Update loki/package.json

Co-authored-by: Gabriel Bernal <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>

* update buildUrl

Signed-off-by: Alexander Belyakin <[email protected]>

* update loki query and changed response data model

Signed-off-by: Alexander Belyakin <[email protected]>

* add logs panel

Signed-off-by: Alexander Belyakin <[email protected]>

* Update loki/cue.mod/module.cue

Co-authored-by: Antoine THEBAUD <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>

* Update loki/cue.mod/module.cue

Co-authored-by: Antoine THEBAUD <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>

* Update loki/package.json

Co-authored-by: Gabriel Bernal <[email protected]>
Signed-off-by: Alexander Belyakin <[email protected]>

* Refactor Loki Queries: Introduce Log and Time Series Queries

Signed-off-by: Alexander Belyakin <[email protected]>

* rename logs panel to logstable

Signed-off-by: Alexander Belyakin <[email protected]>

* fixes

Signed-off-by: Alexander Belyakin <[email protected]>

* delete unused

Signed-off-by: Alexander Belyakin <[email protected]>

* add go sdk

Signed-off-by: Alexander Belyakin <[email protected]>

* Update dependencies and clean up configuration files

Signed-off-by: Alexander Belyakin <[email protected]>

* fix: correct versioning

Signed-off-by: Alexander Belyakin <[email protected]>

* [IGNORE] fix loki dependencies

Signed-off-by: Gabriel Bernal <[email protected]>

* pump ver

Signed-off-by: Alexander Belyakin <[email protected]>

* add log query tests

Signed-off-by: Alexander Belyakin <[email protected]>

---------

Signed-off-by: Alexander Belyakin <[email protected]>
Signed-off-by: Gabriel Bernal <[email protected]>
Co-authored-by: Gabriel Bernal <[email protected]>
Co-authored-by: Antoine THEBAUD <[email protected]>
Co-authored-by: Gabriel Bernal <[email protected]>
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