Start of dashboard query API (#49547)

This PR adds endpoints for public dashboards to retrieve data from the backend (trusted) query engine. It works by executing queries defined on the backend without any user input and does not support template variables.

* Public dashboard query API
* Create new API on service for building metric request
* Flesh out testing, implement BuildPublicDashboardMetricRequest
* Test for errors and missing panels
* Refactor tests, add supporting code for multiple datasources
* Handle queries from multiple datasources
* Explicitly pass no user for querying public dashboard

Co-authored-by: Jeff Levin <jeff@levinology.com>
This commit is contained in:
Jesse Weaver
2022-06-13 15:23:56 -08:00
committed by GitHub
co-authored by Jeff Levin
parent 07aa2bbbba
commit 0371884cdd
15 changed files with 650 additions and 6 deletions
+12
View File
@@ -9,6 +9,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
)
@@ -48,6 +49,17 @@ func NewJson(body []byte) (*Json, error) {
return j, nil
}
// MustJson returns a pointer to a new `Json` object, panicking if `body` cannot be parsed.
func MustJson(body []byte) *Json {
j, err := NewJson(body)
if err != nil {
panic(fmt.Sprintf("could not unmarshal JSON: %q", err))
}
return j
}
// New returns a pointer to a new, empty `Json` object
func New() *Json {
return &Json{
@@ -263,3 +263,12 @@ func TestPathWillOverwriteExisting(t *testing.T) {
assert.Equal(t, nil, err)
assert.Equal(t, "bar", s)
}
func TestMustJson(t *testing.T) {
js := MustJson([]byte(`{"foo": "bar"}`))
assert.Equal(t, js.Get("foo").MustString(), "bar")
assert.PanicsWithValue(t, "could not unmarshal JSON: \"unexpected EOF\"", func() {
MustJson([]byte(`{`))
})
}