Skip to content

Commit e0db144

Browse files
committed
✨ feat: add support for multiple metrics queries
1 parent 40a347c commit e0db144

File tree

9 files changed

+240
-215
lines changed

9 files changed

+240
-215
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,6 @@ jobs:
116116
md5sum ${{ steps.metadata.outputs.archive }} > ${{ steps.metadata.outputs.archive-checksum }}
117117
echo "::set-output name=checksum::$(cat ./${{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
118118
119-
# - name: Lint plugin
120-
# run: |
121-
# git clone https://github.com/grafana/plugin-validator
122-
# pushd ./plugin-validator/pkg/cmd/plugincheck
123-
# go install
124-
# popd
125-
# plugincheck ${{ steps.metadata.outputs.archive }}
126-
127119
- name: Create release
128120
id: create_release
129121
uses: actions/create-release@v1
@@ -157,6 +149,7 @@ jobs:
157149
asset_name: ${{ steps.metadata.outputs.archive-checksum }}
158150
asset_content_type: text/plain
159151

152+
160153
# - name: Publish to Grafana.com
161154
# run: |
162155
# 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:

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3-
## 0.0.5 (Unreleased)
3+
## 0.0.6
44

5-
Initial release.
5+
- Adds support for multiple metrics queries (SQL Editor only)
6+
- Fixes bug where saved query was not displayed in query builder
7+
8+
---
9+
10+
### 0.0.5
11+
12+
- Adds full text SQL query editor with macros

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ The plugin is still work in progress and currently only offers limited functiona
88

99
#### TODO:
1010
- [x] Full-text query editor
11+
- [x] Allow multiple metrics query
1112
- [ ] Add GROUP BY to query form
12-
- [ ] Allow multiple metrics query
1313
- [ ] Autocomplete
1414
- [ ] ...
1515

1616
### Signing
1717

18-
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/).
18+
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/).
1919

2020
defaults.ini
2121
```
@@ -24,15 +24,16 @@ defaults.ini
2424
allow_loading_unsigned_plugins = mullerpeter-databricks-datasource
2525
```
2626

27-
## Query Editor
27+
## Simple Query Editor
2828

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

31-
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.
31+
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.
3232

33+
## Raw SQL Editor
3334
![img.png](img/full_text_sql_editor.png)
3435

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

3738
## Plugin Configuration
3839

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"name": "climeworks-databricks",
3-
"version": "0.0.5",
2+
"name": "mullerpeter-databricks-datasource",
3+
"private": true,
4+
"version": "0.0.6",
45
"description": "Databricks SQL Connector",
56
"scripts": {
67
"build": "grafana-toolkit plugin:build",
@@ -24,8 +25,5 @@
2425
},
2526
"engines": {
2627
"node": ">=14"
27-
},
28-
"dependencies": {
29-
"@monaco-editor/react": "^4.4.6"
3028
}
3129
}

pkg/plugin/helper.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package plugin
2+
3+
import (
4+
"database/sql"
5+
"errors"
6+
"fmt"
7+
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
8+
"github.com/grafana/grafana-plugin-sdk-go/data"
9+
"time"
10+
)
11+
12+
func initDataframeTypes(columnTypes []*sql.ColumnType, columnNames []string, frame *data.Frame) (*data.Frame, error) {
13+
for i := 0; i < len(columnTypes); i++ {
14+
15+
cName := columnNames[i]
16+
switch cType := columnTypes[i].DatabaseTypeName(); cType {
17+
case "BIGINT":
18+
frame.Fields = append(frame.Fields,
19+
data.NewField(cName, nil, []int64{}),
20+
)
21+
case "BOOLEAN":
22+
frame.Fields = append(frame.Fields,
23+
data.NewField(cName, nil, []bool{}),
24+
)
25+
case "DATE":
26+
frame.Fields = append(frame.Fields,
27+
data.NewField(cName, nil, []string{}),
28+
)
29+
case "DOUBLE":
30+
frame.Fields = append(frame.Fields,
31+
data.NewField(cName, nil, []float64{}),
32+
)
33+
case "FLOAT":
34+
frame.Fields = append(frame.Fields,
35+
data.NewField(cName, nil, []float64{}),
36+
)
37+
case "INT":
38+
frame.Fields = append(frame.Fields,
39+
data.NewField(cName, nil, []int32{}),
40+
)
41+
case "SMALLINT":
42+
frame.Fields = append(frame.Fields,
43+
data.NewField(cName, nil, []int16{}),
44+
)
45+
case "STRING":
46+
frame.Fields = append(frame.Fields,
47+
data.NewField(cName, nil, []string{}),
48+
)
49+
case "TIMESTAMP":
50+
frame.Fields = append(frame.Fields,
51+
data.NewField(cName, nil, []time.Time{}),
52+
)
53+
case "TINYINT":
54+
frame.Fields = append(frame.Fields,
55+
data.NewField(cName, nil, []int8{}),
56+
)
57+
default:
58+
err := errors.New(fmt.Sprintf("Unsuported Type %s for column %s", cType, cName))
59+
log.DefaultLogger.Info("Unsuported Type", "err", err)
60+
return frame, err
61+
}
62+
63+
}
64+
return frame, nil
65+
}

0 commit comments

Comments
 (0)