Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/dev/docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
perses:
image: persesdev/perses:main-2026-02-26-739dc289-distroless-debug
image: persesdev/perses:main-2026-11-26-4d10594e-distroless-debug
container_name: perses
network_mode: host
environment:
Expand Down
47 changes: 25 additions & 22 deletions clickhouse/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
# Plugin Module: click-house
# ClickHouse plugin for Perses

### How to install
The ClickHouse plugin runs SQL against [ClickHouse](https://clickhouse.com) through its HTTP interface. It provides time series, log, trace and profile queries, a variable, an annotation and an explorer, and lists the alerts of [ClickStack](https://clickhouse.com/docs/use-cases/observability/clickstack).

This plugin requires react and react-dom 18 or 19.
The queries read any table. They know the tables written by the ClickHouse exporter of the OpenTelemetry Collector and by ClickStack: metrics with their histograms and exemplars, logs, traces and profiles.

Install peer dependencies:
See the [documentation](https://github.com/perses/plugins/blob/main/docs/clickhouse/README.md) of the plugins, and [Writing queries](https://github.com/perses/plugins/blob/main/docs/clickhouse/queries.md) for the macros, the variables and the columns each query expects.

```bash
npm install react@18 react-dom@18 # or react@19 react-dom@19
```
## Datasource setup

Install the plugin:
### ClickHouse

```bash
npm install @my-org/click-house
```
Use a proxied datasource pointing at the HTTP interface of ClickHouse, such as `http://clickhouse.example.com:8123`, and allow `POST ^/$`, for the queries, and `GET ^/ping$`, for the connection test. Store the credentials of the ClickHouse user in a Perses Secret referenced by the proxy.

## Development
The plugin sends every query as read-only (`readonly=2`), with a few settings making the results unambiguous and bounded: ISO date/times, quoted 64-bit integers and a limit of 100 000 rows. This is no protection against a user editing a dashboard: connect with a ClickHouse user that is only granted `SELECT` on the tables to display. When that user is not allowed to change settings (`readonly=1`), the plugin stops sending them and reads the results as they come.

### Setup
Datasources created before queries were sent with `POST` allow `GET` on the root path only. They keep working: their queries are sent in the URL, which limits their size.

Install dependencies:
Set the default database of the datasource to the one holding the tables, for instance the database of the OpenTelemetry tables, to write queries without qualifying them.

```bash
npm install
```
### ClickStack

The ClickStack datasource reads the alerts from the API of ClickStack (HyperDX), at `http://<host>:8000`, or at `http://<host>:8080/api` when only the port of the UI is reachable. Use a proxied datasource allowing `GET ^/api/v2/alerts$` and `GET ^/api/v2$`, with a Secret holding an API key of ClickStack as a bearer token. ClickStack does not accept the requests of browsers other than the ones of its own UI.

### Get Started
The ClickHouse server of ClickStack is a ClickHouse datasource like any other.

Start the dev server:
## Development

Install the dependencies from the root of the repository, then start the dev server of the plugin:

```bash
npm run dev
npm install
npm run dev -w clickhouse
```

Build the plugin for distribution:
Check the plugin:

```bash
npm run build
npm run lint -w clickhouse
npm run type-check -w clickhouse
npm run test -w clickhouse
percli plugin test-schemas --plugin.path=clickhouse
(cd clickhouse && go test ./...)
```
63 changes: 63 additions & 0 deletions clickhouse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,69 @@
},
"name": "ClickHouseLogQuery"
}
},
{
"kind": "TraceQuery",
"spec": {
"display": {
"name": "ClickHouse Trace Query"
},
"name": "ClickHouseTraceQuery"
}
},
{
"kind": "ProfileQuery",
"spec": {
"display": {
"name": "ClickHouse Profile Query"
},
"name": "ClickHouseProfileQuery"
}
},
{
"kind": "Variable",
"spec": {
"display": {
"name": "ClickHouse SQL Variable"
},
"name": "ClickHouseSQLVariable"
}
},
{
"kind": "Annotation",
"spec": {
"display": {
"name": "ClickHouse SQL Annotation"
},
"name": "ClickHouseSQLAnnotation"
}
},
{
"kind": "Datasource",
"spec": {
"display": {
"name": "ClickStack Datasource"
},
"name": "ClickStackDatasource"
}
},
{
"kind": "AlertsQuery",
"spec": {
"display": {
"name": "ClickStack Alerts Query"
},
"name": "ClickStackAlertsQuery"
}
},
{
"kind": "Explore",
"spec": {
"display": {
"name": "ClickHouse Explorer"
},
"name": "ClickHouseExplorer"
}
}
]
}
Expand Down
13 changes: 10 additions & 3 deletions clickhouse/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ export default createConfigForPlugin({
},
moduleFederation: {
exposes: {
'./ClickHouseDatasource': './src/datasources/click-house-datasource',
'./ClickHouseTimeSeriesQuery': './src/queries/click-house-time-series-query',
'./ClickHouseLogQuery': './src/queries/click-house-log-query',
'./ClickHouseDatasource': './src/datasources/click-house-datasource/ClickHouseDatasource.tsx',
'./ClickHouseTimeSeriesQuery': './src/queries/click-house-time-series-query/ClickHouseQuery.tsx',
'./ClickHouseLogQuery': './src/queries/click-house-log-query/ClickHouseLogQuery.tsx',
'./ClickHouseTraceQuery': './src/queries/click-house-trace-query/ClickHouseTraceQuery.tsx',
'./ClickHouseProfileQuery': './src/queries/click-house-profile-query/ClickHouseProfileQuery.tsx',
'./ClickHouseSQLVariable': './src/variables/click-house-sql-variable/ClickHouseSQLVariable.tsx',
'./ClickHouseSQLAnnotation': './src/annotations/click-house-sql-annotation/ClickHouseSQLAnnotation.tsx',
'./ClickStackDatasource': './src/datasources/click-stack-datasource/ClickStackDatasource.tsx',
'./ClickStackAlertsQuery': './src/queries/click-stack-alerts-query/ClickStackAlertsQuery.tsx',
'./ClickHouseExplorer': './src/explore/ClickHouseExplorer.tsx',
},
shared: {
react: { requiredVersion: '^18.3.0 || ^19.0.0', singleton: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

export const queryExample = `-- Time Series Query
SELECT
toStartOfMinute(timestamp) as time,
avg(cpu_usage) as avg_cpu,
max(memory_usage) as max_memory
FROM system_metrics
WHERE timestamp BETWEEN '{start}' AND '{end}'
GROUP BY time ORDER BY time
-- Logs Query
SELECT
Timestamp as log_time,
Body,
ServiceName,
ResourceAttributes,
SeverityNumber,
SeverityText
FROM application_logs
WHERE timestamp >= '{start}'
ORDER BY time DESC LIMIT 1000`;
package model

import (
"strings"
ds "github.com/perses/plugins/clickhouse/schemas/datasources/click-house-datasource:model"
)

kind: "ClickHouseSQLAnnotation"
spec: close({
ds.#selector

// Query returning one row per annotation, with a "time" column, or a "start" and an "end" column.
// Optional columns: "title" and "legend". The other columns are the tags of the annotation.
query: strings.MinRunes(1)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "ClickHouseSQLAnnotation",
"spec": {
"query": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "ClickHouseSQLAnnotation",
"spec": {
"query": "SELECT now() AS time",
"title": "Deployment"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "ClickHouseSQLAnnotation",
"spec": {
"query": "SELECT Timestamp AS time, Body AS title, ServiceName FROM otel_logs WHERE $__timeFilter(Timestamp) AND SeverityNumber >= 17"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "ClickHouseSQLAnnotation",
"spec": {
"datasource": "$clickhouse",
"query": "SELECT started AS start, finished AS end, name AS title FROM deployments WHERE $__timeFilter(started)"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright The Perses Authors
// Licensed under the Apache License, Version 2.0 (the \"License\");
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an \"AS IS\" BASIS,
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Expand All @@ -23,6 +23,10 @@ import (
kind: #kind
spec: {
datasource.#HTTPDatasourceSpec

// Database the unqualified table names of the queries are read from.
// Defaults to "default".
database?: string
}

#selector: common.#datasourceSelector & {_kind: #kind}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"kind": "ClickHouseDatasource",
"spec": {
"directUrl": "http://localhost:8123",
"proxy": {
"kind": "HTTPProxy",
"spec": {
"url": "http://clickhouse:8123"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "ClickHouseDatasource",
"spec": {
"directUrl": "http://localhost:8123",
"database": 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "ClickHouseDatasource",
"spec": {
"directUrl": "http://localhost:8123"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"kind": "ClickHouseDatasource",
"spec": {
"database": "otel",
"proxy": {
"kind": "HTTPProxy",
"spec": {
"url": "http://clickhouse:8123",
"allowedEndpoints": [
{
"endpointPattern": "^/$",
"method": "POST"
},
{
"endpointPattern": "^/ping$",
"method": "GET"
}
],
"secret": "clickhouse"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The Perses Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

import (
"github.com/perses/shared/cue/common"
"github.com/perses/spec/cue/datasource"
)

#kind: "ClickStackDatasource"

kind: #kind
spec: {
datasource.#HTTPDatasourceSpec

// URL of the ClickStack UI, as users open it in their browser. The alerts link to it.
uiUrl?: string
}

#selector: common.#datasourceSelector & {_kind: #kind}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "ClickStackDatasource",
"spec": {
"uiUrl": "https://clickstack.example.com"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "ClickStackDatasource",
"spec": {
"directUrl": "http://localhost:8000",
"uiUrl": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"kind": "ClickStackDatasource",
"spec": {
"directUrl": "http://localhost:8000"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"kind": "ClickStackDatasource",
"spec": {
"uiUrl": "https://clickstack.example.com",
"proxy": {
"kind": "HTTPProxy",
"spec": {
"url": "http://clickstack:8000",
"allowedEndpoints": [
{
"endpointPattern": "^/api/v2/alerts$",
"method": "GET"
},
{
"endpointPattern": "^/api/v2$",
"method": "GET"
}
],
"secret": "clickstack-api-key"
}
}
}
}
Loading
Loading