Skip to content

[FEATURE] Add GreptimeDB datasource Plugin#629

Open
sunchanglong wants to merge 19 commits into
perses:mainfrom
GreptimeTeam:main
Open

[FEATURE] Add GreptimeDB datasource Plugin#629
sunchanglong wants to merge 19 commits into
perses:mainfrom
GreptimeTeam:main

Conversation

@sunchanglong
Copy link
Copy Markdown

Description

This pull request adds a new GreptimeDB plugin to the plugins repository so Perses can query and visualize metrics & logs data from GreptimeDB.

The implementation covers the main GreptimeDB query workflows used in Perses dashboards:

querying time series data from GreptimeDB based on panel time range
converting GreptimeDB responses into the data format expected by Perses panels, so charts and related visual components can consume results without additional handling

A few points worth calling out for review:

GreptimeDB response data is normalized and mapped into Perses-compatible series/frames, including timestamps, values, and label dimensions
plugin schemas, SDK integration helpers, datasource configuration, query editor support, and tests are included in the same change
only files required for the GreptimeDB plugin and workspace/plugin registration were touched
This change is intended to address GreptimeDB datasource support discussed in the linked issue and related follow-up conversations.

Screenshots

Pasted Graphic 7 Pasted Graphic 8 Pasted Graphic 9 Pasted Graphic 10

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.

Signed-off-by: sun <sunchang_long@163.com>
@sunchanglong sunchanglong requested review from a team, AntoineThebaud and Nexucis as code owners April 15, 2026 02:45
@sunchanglong sunchanglong requested review from jgbernalp and removed request for a team April 15, 2026 02:45
@sunchanglong
Copy link
Copy Markdown
Author

The CI workflow failure seems unrelated to the changes in this PR.
Could you please try rerunning the job?

Comment thread greptimedb/src/queries/greptimedb-log-query/greptimedb-log-query-types.test.ts Outdated
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
@sunchanglong
Copy link
Copy Markdown
Author

Added GreptimeDBResponseData to refine the unknown types. This ensures better type safety and clarifies the expected data structure from GreptimeDB.

@sunchanglong
Copy link
Copy Markdown
Author

sunchanglong commented May 13, 2026

Hi team, @jgbernalp we have addressed most review issues could you please check again.
We're using the Perses GreptimeDB plugin in our project: dashboard

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.

Is there any reason why we don't have here a trace query sdk related files? Is this out of scope?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching this.This SDK is simply not used in our work at the moment.
Added trace query Go SDK support, aligned with the existing time-series and log builders.

Comment thread greptimedb/src/queries/greptimedb-trace-query/get-greptimedb-trace-data.ts Outdated
if (raw !== undefined) {
const normalized = (dataType ?? '').toLowerCase();
if (normalized.includes('nanosecond')) return String(Math.trunc(raw));
if (normalized.includes('microsecond')) return String(Math.trunc(raw * 1000));
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.

Could this be a resolution loss when multiplying, when large raw values are multiplied the MAX_INTEGER might be exceeded, maybe safer to use BigInt arithmetic:

Suggested change
if (normalized.includes('microsecond')) return String(Math.trunc(raw * 1000));
if (normalized.includes('microsecond')) return String(BigInt(Math.trunc(raw)) * 1000n);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the code,Agreed, now uses BigInt for unit scaling.

const endTimeUnixNano =
(endIndex !== undefined ? toNanoString(row[endIndex], columns[endIndex]?.data_type) : undefined) ??
(durationIndex !== undefined
? String(parseInt(startTimeUnixNano, 10) + parseInt(toNanoString(row[durationIndex]) ?? '0', 10))
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.

same here, nano seconds can be very large.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure, fixed the same way.

Comment thread greptimedb/go.mod Outdated
Comment thread greptimedb/go.mod Outdated
import { GreptimeDBLogQuerySpec } from './greptimedb-log-query-types';
import { LogQueryPlugin } from './log-query-plugin-interface';

function buildLogs(records: GreptimeDBRecords | undefined): LogData {
Copy link
Copy Markdown
Contributor

@jgbernalp jgbernalp May 13, 2026

Choose a reason for hiding this comment

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

It seems tests for this function are not present. It seems important to assert the data mapping is correct and avoids regressions in the future. WDYT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added coverage in greptimedb-log-query-types.test.ts

Comment thread greptimedb/src/queries/greptimedb-log-query/greptimedb-log-query-types.test.ts Outdated
return dataType.toLowerCase();
}

export function toTimestampMs(value: unknown, dataType: string | undefined): number | null {
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.

It seems this function is used extensively but has no tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added unit test in greptimedb-query-data-model.test.ts

.sort((a, b) => b.startTimeUnixMs - a.startTimeUnixMs);
}

function toNanoString(value: unknown, dataType?: string): string | undefined {
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.

it seems this function is used extensively but has no tests

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure, Added test in get-greptimedb-trace-data.test.ts

const examplesStyle = {
fontSize: '11px',
color: '#777',
backgroundColor: '#f5f5f5',
Copy link
Copy Markdown
Contributor

@jgbernalp jgbernalp May 13, 2026

Choose a reason for hiding this comment

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

hardcoded colors wont work on dark mode, theme colors should be used here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

replaced the hardcoded color with theme style

Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
Signed-off-by: sun <sunchang_long@163.com>
@sunchanglong
Copy link
Copy Markdown
Author

the CI error was caused by perses-dev peerDependencies upgration, should be fixed

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.

2 participants