Candlestick: make candlestick a beta plugin (#41779)

This commit is contained in:
Ryan McKinley 2021-11-17 07:43:25 -08:00 committed by GitHub
parent 757463bd27
commit 6b56ee8bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"testing"
"github.com/grafana/grafana/pkg/bus"
@ -24,6 +25,8 @@ const (
defaultPassword = "password"
)
var updateSnapshotFlag = false
func TestPlugins(t *testing.T) {
dir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
PluginAdminEnabled: true,
@ -32,10 +35,10 @@ func TestPlugins(t *testing.T) {
grafanaListedAddr, store := testinfra.StartGrafana(t, dir, cfgPath)
type testCase struct {
desc string
url string
expStatus int
expResp string
desc string
url string
expStatus int
expRespPath string
}
t.Run("Install", func(t *testing.T) {
@ -69,10 +72,10 @@ func TestPlugins(t *testing.T) {
t.Run("List", func(t *testing.T) {
testCases := []testCase{
{
desc: "should return all loaded core and bundled plugins",
url: "http://%s/api/plugins",
expStatus: http.StatusOK,
expResp: expectedResp(t, "expectedListResp.json"),
desc: "should return all loaded core and bundled plugins",
url: "http://%s/api/plugins",
expStatus: http.StatusOK,
expRespPath: "expectedListResp.json",
},
}
@ -88,7 +91,17 @@ func TestPlugins(t *testing.T) {
require.Equal(t, tc.expStatus, resp.StatusCode)
b, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
require.JSONEq(t, tc.expResp, string(b))
expResp := expectedResp(t, tc.expRespPath)
same := assert.JSONEq(t, expResp, string(b))
if !same {
if updateSnapshotFlag {
t.Log("updating snapshot results")
updateRespSnapshot(t, tc.expRespPath, string(b))
}
t.FailNow()
}
})
}
})
@ -126,10 +139,18 @@ func grafanaAPIURL(username string, grafanaListedAddr string, path string) strin
}
func expectedResp(t *testing.T, filename string) string {
contents, err := ioutil.ReadFile(fmt.Sprintf("data/%s", filename))
//nolint:GOSEC
contents, err := ioutil.ReadFile(filepath.Join("data", filename))
if err != nil {
t.Errorf("failed to load %s: %v", filename, err)
}
return string(contents)
}
func updateRespSnapshot(t *testing.T, filename string, body string) {
err := ioutil.WriteFile(filepath.Join("data", filename), []byte(body), 0600)
if err != nil {
t.Errorf("error writing snapshot %s: %v", filename, err)
}
}

View File

@ -201,6 +201,42 @@
"signatureType": "",
"signatureOrg": ""
},
{
"name": "Candlestick",
"type": "panel",
"id": "candlestick",
"enabled": true,
"pinned": false,
"info": {
"author": {
"name": "Grafana Labs",
"url": "https://grafana.com"
},
"description": "",
"links": null,
"logos": {
"small": "public/app/plugins/panel/candlestick/img/candlestick.svg",
"large": "public/app/plugins/panel/candlestick/img/candlestick.svg"
},
"build": {},
"screenshots": null,
"version": "",
"updated": ""
},
"dependencies": {
"grafanaDependency": "",
"grafanaVersion": "*",
"plugins": []
},
"latestVersion": "",
"hasUpdate": false,
"defaultNavUrl": "/plugins/candlestick/",
"category": "",
"state": "beta",
"signature": "internal",
"signatureType": "",
"signatureOrg": ""
},
{
"name": "CloudWatch",
"type": "datasource",

View File

@ -20,7 +20,7 @@ export const panelsToCheckFirst = [
'text',
'dashlist',
'logs',
// 'candlestick', // uncomment when beta
'candlestick',
];
export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): Promise<VisualizationSuggestion[]> {

View File

@ -61,6 +61,7 @@ export const candlestickFieldsInfo: Record<keyof CandlestickFieldMap, FieldPicke
export interface CandlestickData {
warn?: string;
noTimeField?: boolean;
autoOpenClose?: boolean;
// Special fields
open?: Field;
@ -145,6 +146,7 @@ export function prepareCandlestickFields(
state: undefined,
};
data.frame.fields.push(data.close);
data.autoOpenClose = true;
}
// Use previous close as 'open' value
@ -159,6 +161,7 @@ export function prepareCandlestickFields(
state: undefined,
};
data.frame.fields.push(data.open);
data.autoOpenClose = true;
}
// Use the open field for min/max if nothing is set

View File

@ -2,7 +2,7 @@
"type": "panel",
"name": "Candlestick",
"id": "candlestick",
"state": "alpha",
"state": "beta",
"info": {
"author": {

View File

@ -1,4 +1,4 @@
import { VisualizationSuggestionsBuilder } from '@grafana/data';
import { VisualizationSuggestionsBuilder, VisualizationSuggestionScore } from '@grafana/data';
import { config } from '@grafana/runtime';
import { SuggestionName } from 'app/types/suggestions';
import { prepareCandlestickFields } from './fields';
@ -48,6 +48,7 @@ export class CandlestickSuggestionsSupplier {
defaults: {},
overrides: [],
},
score: info.autoOpenClose ? VisualizationSuggestionScore.Good : VisualizationSuggestionScore.Best,
});
}
}