Skip to content

Commit

Permalink
✨ feat: add support for multiple metrics queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mullerpeter committed Nov 19, 2022
1 parent 40a347c commit e0db144
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 215 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ jobs:
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
# - name: Lint plugin
# run: |
# git clone https://github.com/grafana/plugin-validator
# pushd ./plugin-validator/pkg/cmd/plugincheck
# go install
# popd
# plugincheck ${{ steps.metadata.outputs.archive }}

- name: Create release
id: create_release
uses: actions/create-release@v1
Expand Down Expand Up @@ -157,6 +149,7 @@ jobs:
asset_name: ${{ steps.metadata.outputs.archive-checksum }}
asset_content_type: text/plain


# - name: Publish to Grafana.com
# run: |
# echo A draft release has been created for your plugin. Please review and publish it. Then submit your plugin to grafana.com/plugins by opening a PR to https://github.com/grafana/grafana-plugin-repository with the following entry:
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.0.5 (Unreleased)
## 0.0.6

Initial release.
- Adds support for multiple metrics queries (SQL Editor only)
- Fixes bug where saved query was not displayed in query builder

---

### 0.0.5

- Adds full text SQL query editor with macros
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ The plugin is still work in progress and currently only offers limited functiona

#### TODO:
- [x] Full-text query editor
- [x] Allow multiple metrics query
- [ ] Add GROUP BY to query form
- [ ] Allow multiple metrics query
- [ ] Autocomplete
- [ ] ...

### Signing

The build plugin in the release section of this repo is signed for `localhost:3000`. If you want to use it on another domain, you either have build it without signing and add the plugin ID to the `allow_loading_unsigned_plugins` in the grafana config or sign it yourself according to the [Grafana Documentation](https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/).
The build plugin in the release section of this repo is signed for `localhost:3000`. If you want to use it on another domain, you either have build it without signing (or simply delete the `MANIFEST.txt`) and add the plugin ID to the `allow_loading_unsigned_plugins` in the grafana config or sign it yourself according to the [Grafana Documentation](https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/).

defaults.ini
```
Expand All @@ -24,15 +24,16 @@ defaults.ini
allow_loading_unsigned_plugins = mullerpeter-databricks-datasource
```

## Query Editor
## Simple Query Editor

![img.png](img/querry_editor.png)

At the moment only simple queries for one value over time are implemented. The Time-range and TimeBucket parameters from Grafana are automatically inserted into the query.
At the moment only simple queries for one value over time are implemented. The Time-range and TimeBucket parameters from Grafana are automatically inserted into the query. If you want to use more advanced queries use the raw SQL editor.

## Raw SQL Editor
![img.png](img/full_text_sql_editor.png)

When using the raw SQL editor, template variables are replaced by the Time-Range and Bucket (see default query in editor for example).
When using the raw SQL editor, template variables are replaced by the Time-Range and Bucket (see query help in editor for examples).

## Plugin Configuration

Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "climeworks-databricks",
"version": "0.0.5",
"name": "mullerpeter-databricks-datasource",
"private": true,
"version": "0.0.6",
"description": "Databricks SQL Connector",
"scripts": {
"build": "grafana-toolkit plugin:build",
Expand All @@ -24,8 +25,5 @@
},
"engines": {
"node": ">=14"
},
"dependencies": {
"@monaco-editor/react": "^4.4.6"
}
}
65 changes: 65 additions & 0 deletions pkg/plugin/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package plugin

import (
"database/sql"
"errors"
"fmt"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/data"
"time"
)

func initDataframeTypes(columnTypes []*sql.ColumnType, columnNames []string, frame *data.Frame) (*data.Frame, error) {
for i := 0; i < len(columnTypes); i++ {

cName := columnNames[i]
switch cType := columnTypes[i].DatabaseTypeName(); cType {
case "BIGINT":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []int64{}),
)
case "BOOLEAN":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []bool{}),
)
case "DATE":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []string{}),
)
case "DOUBLE":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []float64{}),
)
case "FLOAT":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []float64{}),
)
case "INT":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []int32{}),
)
case "SMALLINT":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []int16{}),
)
case "STRING":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []string{}),
)
case "TIMESTAMP":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []time.Time{}),
)
case "TINYINT":
frame.Fields = append(frame.Fields,
data.NewField(cName, nil, []int8{}),
)
default:
err := errors.New(fmt.Sprintf("Unsuported Type %s for column %s", cType, cName))
log.DefaultLogger.Info("Unsuported Type", "err", err)
return frame, err
}

}
return frame, nil
}
Loading

0 comments on commit e0db144

Please sign in to comment.