Skip to content

Commit 786e1e0

Browse files
feature: Adds 404 retry & close on dispose
1 parent f56259c commit 786e1e0

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

DEVELOPMENT_GUIDE.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ achieved with the following steps:
5353
1. Run `npm version <major|minor|patch>`
5454
2. Run `git push origin main --follow-tags`
5555

56-
57-
# TODO
58-
59-
* [ ] Add support for non-eval queries (read, hisRead, etc)
60-
* [ ] Improve login/logout and add auth/retry logic
61-
6256
---
6357

6458
Below is the original readme generated by Grafana

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ To use them, simply use the value in the input string like this:
5151
[{ts: $__timeRange_start, v0: 0}, {ts: $__timeRange_end, v0: 10}].toGrid
5252
```
5353

54+
# Continuing Work
55+
56+
* [ ] Publish plugin

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require github.com/grafana/grafana-plugin-sdk-go v0.149.1
66

77
require (
8-
github.com/NeedleInAJayStack/haystack v0.1.5
8+
github.com/NeedleInAJayStack/haystack v0.1.6
99
github.com/joho/godotenv v1.5.1
1010
)
1111

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zum
3535
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
3636
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3737
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
38-
github.com/NeedleInAJayStack/haystack v0.1.5 h1:pT+xWnXH6ogtqXbBXyg0TSFJAwCscjrTTAESyR3eAyE=
39-
github.com/NeedleInAJayStack/haystack v0.1.5/go.mod h1:Oho5sG64nQS27mApp6gWOUi7m4OgzpWllZrOtZn8qss=
38+
github.com/NeedleInAJayStack/haystack v0.1.6 h1:LhV4SO2Jgjq8YQPd/JcJdb/a3cq9+Lu548vTDj0NakU=
39+
github.com/NeedleInAJayStack/haystack v0.1.6/go.mod h1:Oho5sG64nQS27mApp6gWOUi7m4OgzpWllZrOtZn8qss=
4040
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
4141
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
4242
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

pkg/plugin/datasource.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Options struct {
6868
// created. As soon as datasource settings change detected by SDK old datasource instance will
6969
// be disposed and a new one will be created using NewSampleDatasource factory function.
7070
func (datasource *Datasource) Dispose() {
71-
// Clean up datasource instance resources.
71+
datasource.client.Close()
7272
}
7373

7474
// QueryData handles multiple queries and returns multiple responses.
@@ -189,7 +189,19 @@ func (datasource *Datasource) eval(expr string, variables map[string]string) (ha
189189
for name, val := range variables {
190190
expr = strings.ReplaceAll(expr, name, val)
191191
}
192-
return datasource.client.Eval(expr)
192+
result, err := datasource.client.Eval(expr)
193+
// If the error is a 404, try to reconnect and try again
194+
switch error := err.(type) {
195+
case client.HTTPError:
196+
if error.Code == 404 {
197+
datasource.client.Open()
198+
return datasource.client.Eval(expr)
199+
} else {
200+
return result, err
201+
}
202+
default:
203+
return result, err
204+
}
193205
}
194206

195207
func (datasource *Datasource) hisRead(id string, timeRange backend.TimeRange) (haystack.Grid, error) {

0 commit comments

Comments
 (0)