mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Candlestick: make candlestick a beta plugin (#41779)
This commit is contained in:
parent
757463bd27
commit
6b56ee8bc1
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
@ -24,6 +25,8 @@ const (
|
|||||||
defaultPassword = "password"
|
defaultPassword = "password"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var updateSnapshotFlag = false
|
||||||
|
|
||||||
func TestPlugins(t *testing.T) {
|
func TestPlugins(t *testing.T) {
|
||||||
dir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
dir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
|
||||||
PluginAdminEnabled: true,
|
PluginAdminEnabled: true,
|
||||||
@ -35,7 +38,7 @@ func TestPlugins(t *testing.T) {
|
|||||||
desc string
|
desc string
|
||||||
url string
|
url string
|
||||||
expStatus int
|
expStatus int
|
||||||
expResp string
|
expRespPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Install", func(t *testing.T) {
|
t.Run("Install", func(t *testing.T) {
|
||||||
@ -72,7 +75,7 @@ func TestPlugins(t *testing.T) {
|
|||||||
desc: "should return all loaded core and bundled plugins",
|
desc: "should return all loaded core and bundled plugins",
|
||||||
url: "http://%s/api/plugins",
|
url: "http://%s/api/plugins",
|
||||||
expStatus: http.StatusOK,
|
expStatus: http.StatusOK,
|
||||||
expResp: expectedResp(t, "expectedListResp.json"),
|
expRespPath: "expectedListResp.json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +91,17 @@ func TestPlugins(t *testing.T) {
|
|||||||
require.Equal(t, tc.expStatus, resp.StatusCode)
|
require.Equal(t, tc.expStatus, resp.StatusCode)
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
require.NoError(t, err)
|
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 {
|
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 {
|
if err != nil {
|
||||||
t.Errorf("failed to load %s: %v", filename, err)
|
t.Errorf("failed to load %s: %v", filename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(contents)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -201,6 +201,42 @@
|
|||||||
"signatureType": "",
|
"signatureType": "",
|
||||||
"signatureOrg": ""
|
"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",
|
"name": "CloudWatch",
|
||||||
"type": "datasource",
|
"type": "datasource",
|
||||||
|
@ -20,7 +20,7 @@ export const panelsToCheckFirst = [
|
|||||||
'text',
|
'text',
|
||||||
'dashlist',
|
'dashlist',
|
||||||
'logs',
|
'logs',
|
||||||
// 'candlestick', // uncomment when beta
|
'candlestick',
|
||||||
];
|
];
|
||||||
|
|
||||||
export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): Promise<VisualizationSuggestion[]> {
|
export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): Promise<VisualizationSuggestion[]> {
|
||||||
|
@ -61,6 +61,7 @@ export const candlestickFieldsInfo: Record<keyof CandlestickFieldMap, FieldPicke
|
|||||||
export interface CandlestickData {
|
export interface CandlestickData {
|
||||||
warn?: string;
|
warn?: string;
|
||||||
noTimeField?: boolean;
|
noTimeField?: boolean;
|
||||||
|
autoOpenClose?: boolean;
|
||||||
|
|
||||||
// Special fields
|
// Special fields
|
||||||
open?: Field;
|
open?: Field;
|
||||||
@ -145,6 +146,7 @@ export function prepareCandlestickFields(
|
|||||||
state: undefined,
|
state: undefined,
|
||||||
};
|
};
|
||||||
data.frame.fields.push(data.close);
|
data.frame.fields.push(data.close);
|
||||||
|
data.autoOpenClose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use previous close as 'open' value
|
// Use previous close as 'open' value
|
||||||
@ -159,6 +161,7 @@ export function prepareCandlestickFields(
|
|||||||
state: undefined,
|
state: undefined,
|
||||||
};
|
};
|
||||||
data.frame.fields.push(data.open);
|
data.frame.fields.push(data.open);
|
||||||
|
data.autoOpenClose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the open field for min/max if nothing is set
|
// Use the open field for min/max if nothing is set
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"type": "panel",
|
"type": "panel",
|
||||||
"name": "Candlestick",
|
"name": "Candlestick",
|
||||||
"id": "candlestick",
|
"id": "candlestick",
|
||||||
"state": "alpha",
|
"state": "beta",
|
||||||
|
|
||||||
"info": {
|
"info": {
|
||||||
"author": {
|
"author": {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { VisualizationSuggestionsBuilder } from '@grafana/data';
|
import { VisualizationSuggestionsBuilder, VisualizationSuggestionScore } from '@grafana/data';
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { SuggestionName } from 'app/types/suggestions';
|
import { SuggestionName } from 'app/types/suggestions';
|
||||||
import { prepareCandlestickFields } from './fields';
|
import { prepareCandlestickFields } from './fields';
|
||||||
@ -48,6 +48,7 @@ export class CandlestickSuggestionsSupplier {
|
|||||||
defaults: {},
|
defaults: {},
|
||||||
overrides: [],
|
overrides: [],
|
||||||
},
|
},
|
||||||
|
score: info.autoOpenClose ? VisualizationSuggestionScore.Good : VisualizationSuggestionScore.Best,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user