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

fix: set ref id for data frame #20

Closed
wants to merge 14 commits into from
Closed
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 .config/.cprc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "5.5.3"
"version": "5.12.4"
}
6 changes: 6 additions & 0 deletions .config/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"parserOptions": {
"project": "./tsconfig.json"
}
},
{
"files": ["./tests/**/*"],
"rules": {
"react-hooks/rules-of-hooks": "off"
}
}
]
}
15 changes: 8 additions & 7 deletions .config/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ARG grafana_image=grafana-enterprise

FROM grafana/${grafana_image}:${grafana_version}

ARG anonymous_auth_enabled=true
ARG development=false
ARG TARGETARCH

Expand All @@ -14,7 +15,7 @@ ENV DEV "${development}"
# Make it as simple as possible to access the grafana instance for development purposes
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}"
ENV GF_AUTH_BASIC_ENABLED "false"
# Set development mode so plugins can be loaded without the need to sign
ENV GF_DEFAULT_APP_MODE "development"
Expand All @@ -30,14 +31,14 @@ USER root
# Installing supervisor and inotify-tools
RUN if [ "${development}" = "true" ]; then \
if grep -i -q alpine /etc/issue; then \
apk add supervisor inotify-tools git; \
apk add supervisor inotify-tools git; \
elif grep -i -q ubuntu /etc/issue; then \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
else \
echo 'ERROR: Unsupported base image' && /bin/false; \
echo 'ERROR: Unsupported base image' && /bin/false; \
fi \
fi

Expand Down
8 changes: 4 additions & 4 deletions .config/supervisord/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ user=root
[program:grafana]
user=root
directory=/var/lib/grafana
command=bash -c 'while [ ! -f /root/timeplus-timeplus-datasource/dist/gpx_timeplus* ]; do sleep 1; done; /run.sh'
command=bash -c 'while [ ! -f /root/timeplus-proton-datasource/dist/gpx_timeplus* ]; do sleep 1; done; /run.sh'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
Expand All @@ -26,7 +26,7 @@ autorestart=true

[program:build-watcher]
user=root
command=/bin/bash -c 'while inotifywait -e modify,create,delete -r /var/lib/grafana/plugins/timeplus-timeplus-datasource; do echo "Change detected, restarting delve...";supervisorctl restart delve; done'
command=/bin/bash -c 'while inotifywait -e modify,create,delete -r /var/lib/grafana/plugins/timeplus-proton-datasource; do echo "Change detected, restarting delve...";supervisorctl restart delve; done'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
Expand All @@ -37,8 +37,8 @@ autostart=true
[program:mage-watcher]
user=root
environment=PATH="/usr/local/go/bin:/root/go/bin:%(ENV_PATH)s"
directory=/root/timeplus-timeplus-datasource
command=/bin/bash -c 'git config --global --add safe.directory /root/timeplus-timeplus-datasource && mage -v watch'
directory=/root/timeplus-proton-datasource
command=/bin/bash -c 'git config --global --add safe.directory /root/timeplus-proton-datasource && mage -v watch'
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
Expand Down
33 changes: 33 additions & 0 deletions .config/webpack/BuildModeWebpackPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as webpack from 'webpack';

const PLUGIN_NAME = 'BuildModeWebpack';

export class BuildModeWebpackPlugin {
apply(compiler: webpack.Compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
},
async () => {
const assets = compilation.getAssets();
for (const asset of assets) {
if (asset.name.endsWith('plugin.json')) {
const pluginJsonString = asset.source.source().toString();
const pluginJsonWithBuildMode = JSON.stringify(
{
...JSON.parse(pluginJsonString),
buildMode: compilation.options.mode,
},
null,
4
);
compilation.updateAsset(asset.name, new webpack.sources.RawSource(pluginJsonWithBuildMode));
}
}
}
);
});
}
}
19 changes: 11 additions & 8 deletions .config/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { type Configuration, BannerPlugin } from 'webpack';
import LiveReloadPlugin from 'webpack-livereload-plugin';
import VirtualModulesPlugin from 'webpack-virtual-modules';

import { BuildModeWebpackPlugin } from './BuildModeWebpackPlugin';
import { DIST_DIR, SOURCE_DIR } from './constants';
import { getCPConfigVersion, getEntries, getPackageJson, getPluginJson, hasReadme, isWSL } from './utils';

Expand Down Expand Up @@ -175,6 +176,7 @@ const config = async (env): Promise<Configuration> => {
keep: new RegExp(`(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)`),
},
filename: '[name].js',
chunkFilename: env.production ? '[name].js?_cache=[contenthash]' : '[name].js',
library: {
type: 'amd',
},
Expand All @@ -185,6 +187,7 @@ const config = async (env): Promise<Configuration> => {
},

plugins: [
new BuildModeWebpackPlugin(),
virtualPublicPath,
// Insert create plugin version information into the bundle
new BannerPlugin({
Expand All @@ -200,14 +203,14 @@ const config = async (env): Promise<Configuration> => {
{ from: 'plugin.json', to: '.' },
{ from: '../LICENSE', to: '.' },
{ from: '../CHANGELOG.md', to: '.', force: true },
{ from: '**/*.json', to: '.' }, // TODO<Add an error for checking the basic structure of the repo>
{ from: '**/*.svg', to: '.', noErrorOnMissing: true }, // Optional
{ from: '**/*.png', to: '.', noErrorOnMissing: true }, // Optional
{ from: '**/*.html', to: '.', noErrorOnMissing: true }, // Optional
{ from: 'img/**/*', to: '.', noErrorOnMissing: true }, // Optional
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true }, // Optional
{ from: 'static/**/*', to: '.', noErrorOnMissing: true }, // Optional
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true }, // Optional
{ from: '**/*.json', to: '.' },
{ from: '**/*.svg', to: '.', noErrorOnMissing: true },
{ from: '**/*.png', to: '.', noErrorOnMissing: true },
{ from: '**/*.html', to: '.', noErrorOnMissing: true },
{ from: 'img/**/*', to: '.', noErrorOnMissing: true },
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true },
{ from: 'static/**/*', to: '.', noErrorOnMissing: true },
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true },
],
}),
// Replace certain template-variables in the README and plugin.json
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.1.0

Key changes:

* Able to define dashboard variables with this data source. Please make sure turning off the streaming query mode in the SQL to populate the variable values, and only return 1 or 2 columns. You can also refer to `__from` and `__to` variables in the SQL to get the time range of the dashboard.
* Able to define annotations with this data source
* Use default values for HTTP/TCP ports and username if they are not set in the data source configuration

## 2.0.0

Key changes:
Expand Down
8 changes: 7 additions & 1 deletion Magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ package main
import (
// mage:import
build "github.com/grafana/grafana-plugin-sdk-go/build"
"github.com/magefile/mage/mg"
)

func Build4() { //revive:disable-line
b := build.Build{}
mg.Deps(b.Windows, b.Darwin, b.DarwinARM64, b.Linux, b.LinuxARM64, b.GenerateManifestFile)
}

// Default configures the default target.
var Default = build.BuildAll
var Default = Build4
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ID = timeplus-proton-datasource
Version = 2.0.0
Version = 2.1.0

init:
npm install
Expand Down
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ As the core engine of [Timeplus Enterprise](https://timeplus.com), [Proton](http

## Requirements

Grafana v10.0.3 or above
Grafana v11.3 or above (older versions may work but not verified)

A running Timeplus Proton or Timeplus Enterprise instance with TCP port 8463 (for database connection) and HTTP port 3218 (for query analazyer REST API).

Expand All @@ -22,16 +22,47 @@ A data source for Timeplus is created automatically.

### Use your own Grafana deployment

Download the latest version from https://d.timeplus.com/grafana/timeplus-proton-datasource-2.1.0.zip

Unzip the file and copy the folder to the Grafana plugin directory, usually `/var/lib/grafana/plugins/`.

For example, on a Linux machine, you can run the following commands:

```bash
cd /var/lib/grafana
mkdir plugins
cd plugins
wget d.timeplus.com/grafana/timeplus-proton-datasource-2.1.0.zip
unzip timeplus-proton-datasource-2.1.0.zip
/bin/systemctl start grafana-server.service
```

For macOS, you can run the following commands:

```bash
cd /opt/homebrew/var/lib/grafana
mkdir plugins
cd plugins
wget d.timeplus.com/grafana/timeplus-proton-datasource-2.1.0.zip
unzip timeplus-proton-datasource-2.1.0.zip
brew services restart grafana
```

In the navigation menu, choose Connections -> Add new connection.

Search for Timeplus and accept the default settings (localhost,port 8463 and 3218 as proton connection). This plugin is expected to run in localhost or trusted network. Username and password for Timeplus will be added later. This tool supports self-hosted Timeplus Enterprise, but not for Timeplus Cloud.
Search for Timeplus and accept the default settings (localhost,port 8463 and 3218 as proton connection). For Timeplus Enterprise deployment, also set the username and password.

Create a new dashboard or explore data with this Timeplus data source.

There are unbounded streaming query and bounded historical query in proton, all queries like `select count(*) from stream_name` are streaming queries, and adding `table` function to the stream name will turn the query into bounded query, e.g. `select count(*) from table(stream_name)`.
There are unbounded streaming query and bounded historical query in Timeplus, all queries like `select count(*) from stream_name` are streaming queries, and adding `table` function to the stream name will turn the query into bounded query, e.g. `select count(*) from table(stream_name)`.

![query editor](src/img/query.png)

### Query Variables
You can define dashboard variables with this data source. Please make sure turning off the streaming query mode in the SQL to populate the variable values, and only return 1 or 2 columns. When there is 1 column returned, it will be set as both value and label. If there are 2 columns, the first column will be set as value and the second column as the label. You can also refer to `__from` and `__to` variables in the SQL to get the time range of the dashboard, e.g.:
```sql
SELECT distinct product_id FROM table(coinbase) where _tp_time < to_datetime($__to/1000) and _tp_time > to_datetime($__from/1000)
```

## Development

Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
context: ./.config
args:
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
grafana_version: ${GRAFANA_VERSION:-11.2.2}
grafana_version: ${GRAFANA_VERSION:-11.3.1}
development: ${DEVELOPMENT:-false}
ports:
- 3000:3000/tcp
Expand Down Expand Up @@ -35,7 +35,7 @@ services:
ports:
- 3218:3218 # HTTP Streaming
- 8463:8463 # TCP Streaming

carsharing_datagen:
image: timeplus/cardemo:latest
pull_policy: always
Expand All @@ -49,4 +49,4 @@ services:
interval: 200
host: proton
depends_on:
- proton
- proton
Loading