Skip to content

Commit

Permalink
update sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed Feb 25, 2024
1 parent f70ba8b commit 236a088
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/models/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package models

import (
"reflect"
"testing"

"github.com/grafana/grafana-plugin-sdk-go/experimental/spec"
"github.com/stretchr/testify/require"
)

func TestSchemaDefinitions(t *testing.T) {
builder, err := spec.NewSchemaBuilder(
spec.BuilderOptions{
BasePackage: "github.com/grafana/google-sheets-datasource/pkg/models",
CodePath: "./",
},
)
require.NoError(t, err)
err = builder.AddQueries(spec.QueryTypeInfo{
Name: "default",
GoType: reflect.TypeOf(&QueryModel{}),
Examples: []spec.QueryExample{
{
Name: "public query",
SaveModel: QueryModel{
Spreadsheet: "YourSheetID",
Range: "A1:D6",
},
},
},
})

require.NoError(t, err)

// Update the query schemas resource
builder.UpdateQueryDefinition(t, "../../src/static/schema")
}
13 changes: 13 additions & 0 deletions src/static/schema/query.request.examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"from": "now-1h",
"to": "now",
"queries": [
{
"refId": "A",
"maxDataPoints": 1000,
"intervalMs": 5,
"spreadsheet": "YourSheetID",
"range": "A1:D6"
}
]
}
143 changes: 143 additions & 0 deletions src/static/schema/query.request.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"type": "object",
"required": [
"queries"
],
"properties": {
"$schema": {
"description": "helper",
"type": "string"
},
"debug": {
"type": "boolean"
},
"from": {
"description": "From Start time in epoch timestamps in milliseconds or relative using Grafana time units.",
"type": "string"
},
"queries": {
"type": "array",
"items": {
"description": "Datasource request model",
"type": "object",
"required": [
"spreadsheet"
],
"properties": {
"cacheDurationSeconds": {
"description": "Cache duration in seconds",
"type": "integer"
},
"datasource": {
"description": "The datasource",
"type": "object",
"required": [
"type",
"uid"
],
"properties": {
"type": {
"description": "The datasource plugin type",
"type": "string"
},
"uid": {
"description": "Datasource UID",
"type": "string"
}
},
"additionalProperties": false
},
"hide": {
"description": "true if query is disabled (ie should not be returned to the dashboard)\nNOTE: this does not always imply that the query should not be executed since\nthe results from a hidden query may be used as the input to other queries (SSE etc)",
"type": "boolean"
},
"intervalMs": {
"description": "Interval is the suggested duration between time points in a time series query.\nNOTE: the values for intervalMs is not saved in the query model. It is typically calculated\nfrom the interval required to fill a pixels in the visualization",
"type": "number"
},
"maxDataPoints": {
"description": "MaxDataPoints is the maximum number of data points that should be returned from a time series query.\nNOTE: the values for maxDataPoints is not saved in the query model. It is typically calculated\nfrom the number of pixels visible in a visualization",
"type": "integer"
},
"queryType": {
"description": "QueryType is an optional identifier for the type of query.\nIt can be used to distinguish different types of queries.",
"type": "string"
},
"range": {
"description": "A1 notation",
"type": "string"
},
"refId": {
"description": "RefID is the unique identifier of the query, set by the frontend call.",
"type": "string"
},
"resultAssertions": {
"description": "Optionally define expected query result behavior",
"type": "object",
"required": [
"typeVersion"
],
"properties": {
"maxBytes": {
"description": "Maximum bytes that can be read -- if the query planning expects more then this, the query may fail fast",
"type": "integer"
},
"maxFrames": {
"description": "Maximum frame count",
"type": "integer"
},
"type": {
"description": "Type asserts that the frame matches a known type structure.",
"type": "string"
},
"typeVersion": {
"description": "TypeVersion is the version of the Type property. Versions greater than 0.0 correspond to the dataplane\ncontract documentation https://grafana.github.io/dataplane/contract/.",
"type": "array",
"maxItems": 2,
"minItems": 2,
"items": {
"type": "integer"
}
}
},
"additionalProperties": false
},
"spreadsheet": {
"description": "The google sheets spreadsheet ID",
"type": "string"
},
"timeRange": {
"description": "TimeRange represents the query range\nNOTE: unlike generic /ds/query, we can now send explicit time values in each query\nNOTE: the values for timeRange are not saved in a dashboard, they are constructed on the fly",
"type": "object",
"required": [
"from",
"to"
],
"properties": {
"from": {
"description": "From is the start time of the query.",
"type": "string"
},
"to": {
"description": "To is the end time of the query.",
"type": "string"
}
},
"additionalProperties": false
},
"useTimeFilter": {
"description": "Use the query time range to filer values from the table",
"type": "boolean"
}
},
"additionalProperties": false,
"$schema": "https://json-schema.org/draft-04/schema"
}
},
"to": {
"description": "To end time in epoch timestamps in milliseconds or relative using Grafana time units.",
"type": "string"
}
},
"additionalProperties": false
}
116 changes: 116 additions & 0 deletions src/static/schema/query.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"description": "object saved in dashboard/alert",
"type": "object",
"required": [
"spreadsheet"
],
"properties": {
"cacheDurationSeconds": {
"description": "Cache duration in seconds",
"type": "integer"
},
"datasource": {
"description": "The datasource",
"type": "object",
"required": [
"type",
"uid"
],
"properties": {
"type": {
"description": "The datasource plugin type",
"type": "string"
},
"uid": {
"description": "Datasource UID",
"type": "string"
}
},
"additionalProperties": false
},
"hide": {
"description": "true if query is disabled (ie should not be returned to the dashboard)\nNOTE: this does not always imply that the query should not be executed since\nthe results from a hidden query may be used as the input to other queries (SSE etc)",
"type": "boolean"
},
"intervalMs": {
"description": "Interval is the suggested duration between time points in a time series query.\nNOTE: the values for intervalMs is not saved in the query model. It is typically calculated\nfrom the interval required to fill a pixels in the visualization",
"type": "number"
},
"maxDataPoints": {
"description": "MaxDataPoints is the maximum number of data points that should be returned from a time series query.\nNOTE: the values for maxDataPoints is not saved in the query model. It is typically calculated\nfrom the number of pixels visible in a visualization",
"type": "integer"
},
"queryType": {
"description": "QueryType is an optional identifier for the type of query.\nIt can be used to distinguish different types of queries.",
"type": "string"
},
"range": {
"description": "A1 notation",
"type": "string"
},
"refId": {
"description": "RefID is the unique identifier of the query, set by the frontend call.",
"type": "string"
},
"resultAssertions": {
"description": "Optionally define expected query result behavior",
"type": "object",
"required": [
"typeVersion"
],
"properties": {
"maxBytes": {
"description": "Maximum bytes that can be read -- if the query planning expects more then this, the query may fail fast",
"type": "integer"
},
"maxFrames": {
"description": "Maximum frame count",
"type": "integer"
},
"type": {
"description": "Type asserts that the frame matches a known type structure.",
"type": "string"
},
"typeVersion": {
"description": "TypeVersion is the version of the Type property. Versions greater than 0.0 correspond to the dataplane\ncontract documentation https://grafana.github.io/dataplane/contract/.",
"type": "array",
"maxItems": 2,
"minItems": 2,
"items": {
"type": "integer"
}
}
},
"additionalProperties": false
},
"spreadsheet": {
"description": "The google sheets spreadsheet ID",
"type": "string"
},
"timeRange": {
"description": "TimeRange represents the query range\nNOTE: unlike generic /ds/query, we can now send explicit time values in each query\nNOTE: the values for timeRange are not saved in a dashboard, they are constructed on the fly",
"type": "object",
"required": [
"from",
"to"
],
"properties": {
"from": {
"description": "From is the start time of the query.",
"type": "string"
},
"to": {
"description": "To is the end time of the query.",
"type": "string"
}
},
"additionalProperties": false
},
"useTimeFilter": {
"description": "Use the query time range to filer values from the table",
"type": "boolean"
}
},
"additionalProperties": false,
"$schema": "https://json-schema.org/draft-04/schema"
}

0 comments on commit 236a088

Please sign in to comment.