Skip to content

Commit

Permalink
update to 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
amonakhov committed Aug 12, 2019
1 parent 2934ec7 commit cbbe244
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 17 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 1.9.0 (2019-08-12)

## New features:

* Add macro `conditionalTest` (thx to @TH-HA) #122
* Add support for connect to Yandex.Cloud ClickHouse (thx to @negasus) #106

## Fixes:

* Fix identifier back quoting when there is a function call
* Fix AST parser errors for quotes (thx to @Fiery-Fenix) #128
* Added default database to all requests from datasource options (thx to @Fiery-Fenix) #126
* Drop lodash fcn composition (thx to @simPod) #110
* Cleanup build (thx to @simPod) #112


# 1.8.1 (2019-02-01)

## New features:
Expand Down
107 changes: 99 additions & 8 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Plugin supports the following marcos:
* $interval - replaced with selected "Group by time interval" value (as a number of seconds)
* $timeFilter - replaced with currently selected "Time Range".
Requires Column:Date and Column:DateTime or Column:TimeStamp to be selected
* $timeFilterColumn($column) - replaced with currently selected "Time Range" for column passed as `$column` argument. Use it in queries or query variables as `...WHERE $timeFilterColumn($column)...` or `...WHERE $timeFilterColumn(created_at)...`.
* $timeFilterByColumn($column) - replaced with currently selected "Time Range" for column passed as `$column` argument. Use it in queries or query variables as `...WHERE $timeFilterColumn($column)...` or `...WHERE $timeFilterColumn(created_at)...`.
* $timeSeries - replaced with special ClickHouse construction to convert results as time-series data. Use it as "SELECT $timeSeries...".
* $unescape - unescapes variable value by removing single quotes. Used for multiple-value string variables: "SELECT $unescape($column) FROM requests WHERE $unescape($column) = 5"
* $adhoc - replaced with a rendered ad-hoc filter expression, or "1" if no ad-hoc filters exist. Since ad-hoc applies automatically only to outer queries the macros can be used for filtering in inner queries.
Expand Down Expand Up @@ -279,6 +279,87 @@ ORDER BY t ASC

---

## Templating

### Query Variable

If you add a template variable of the type `Query`, you can write a ClickHouse query that can
return things like measurement names, key names or key values that are shown as a dropdown select box.

For example, you can have a variable that contains all values for the `hostname` column in a table if you specify a query like this in the templating variable *Query* setting.

```sql
SELECT hostname FROM host
```

To use time range dependent macros like `timeFilterByColumn($column)` in your query the refresh mode of the template variable needs to be set to *On Time Range Change*.

```sql
SELECT event_name FROM event_log WHERE $timeFilterByColumn(time_column)
```

Another option is a query that can create a key/value variable. The query should return two columns that are named `__text` and `__value`. The `__text` column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allows you to have a friendly name as text and an id as the value. An example query with `hostname` as the text and `id` as the value:

```sql
SELECT hostname AS __text, id AS __value FROM host
```

You can also create nested variables. For example if you had another variable named `region`. Then you could have the hosts variable only show hosts from the current selected region with a query like this (if `region` is a multi-value variable then use the `IN` comparison operator rather than `=` to match against multiple values):

```sql
SELECT hostname FROM host WHERE region IN ($region)
```

### Conditional Predicate

If you are using templating to feed your predicate , you will face performance degradation when everything is selected as the predicate is not necessary. It's also true for textbox when nothing is enter , you have to write specific sql code to handle that.

To workaround this issue a new macro $conditionalTest(SQL Predicate,$variable) can be used to remove some part of the query.
If the variable is type query with all selected or if the variable is a textbox with nothing enter , then the SQL Predicate is not included in the generated query.

To give an example:
with 2 variables
$var query with include All option
$text textbox

The following query
```sql
SELECT
$timeSeries as t,
count()
FROM $table
WHERE $timeFilter
$conditionalTest(AND toLowerCase(column) in ($var),$var)
$conditionalTest(AND toLowerCase(column2) like '%$text%',$text)
GROUP BY t
ORDER BY t
```

if the $var is all selected and the $text is empty , the query will be converted into

```sql
SELECT
$timeSeries as t,
count()
FROM $table
WHERE $timeFilter
GROUP BY t
ORDER BY t
```
If $var have some element selected and the $text has at least one char , the query will be converted into

```sql
SELECT
$timeSeries as t,
count()
FROM $table
WHERE $timeFilter
AND toLowerCase(column) in ($var)
AND toLowerCase(column2) like '%$text%'
GROUP BY t
ORDER BY t
```

### Working with panels

#### Piechart (https://grafana.com/plugins/grafana-piechart-panel)
Expand Down Expand Up @@ -464,20 +545,30 @@ That's why plugin checks prev datapoints and tries to predict last datapoint val
Alerts feature requires changes in `Grafana`'s backend, which can't be extended for now. `Grafana`'s maintainers are working on this feature.
### Build
### Development
The build works with either NPM or Yarn:
There are following scripts defined in package.json:
```
npm run build
```
- `build:prod` – production-ready build
- `build:dev` - development build (no uglify etc.)
- `build:watch` - automatically rebuilds code on change (handy while developing)
- `test` - runs test suite using Jest
- `test:watch` - runs test suite using Jest in watch mode. Automatically reruns tests on source change.
Tests can be run with following command:
Each script can be run using NPM or Yarn package managers:
```sh
npm run <script>
```
npm run test

or

```sh
yarn run <script>
```

(for example `npm run build`)

For test examples please see `spec` folder. We strongly encourage contributors to add tests to check new changes or functionality.

### Contribute
Expand Down
9 changes: 4 additions & 5 deletions dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"url": "https://github.com/Vertamedia/clickhouse-grafana"
}
],
"version": "1.8.1"
"version": "1.9.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vertamedia-clickhouse",
"version": "1.8.1",
"version": "1.9.0",
"description": "ClickHouse datasource for Grafana",
"scripts": {
"build:prod": "webpack --config webpack.config.prod.js",
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"url": "https://github.com/Vertamedia/clickhouse-grafana"
}
],
"version": "1.8.1"
"version": "1.9.0"
}
}

0 comments on commit cbbe244

Please sign in to comment.