mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
mysql: improved mysql data source, added test feature when adding data source, fixed cache issue
This commit is contained in:
@@ -149,8 +149,8 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
secureJsonData := ds.SecureJsonData.Decrypt()
|
|
||||||
|
|
||||||
|
secureJsonData := ds.SecureJsonData.Decrypt()
|
||||||
for k, v := range secureJsonData {
|
for k, v := range secureJsonData {
|
||||||
|
|
||||||
if _, ok := cmd.SecureJsonData[k]; !ok {
|
if _, ok := cmd.SecureJsonData[k]; !ok {
|
||||||
@@ -158,6 +158,8 @@ func fillWithSecureJsonData(cmd *m.UpdateDataSourceCommand) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set version from db
|
||||||
|
cmd.Version = ds.Version
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -116,8 +116,9 @@ type UpdateDataSourceCommand struct {
|
|||||||
JsonData *simplejson.Json `json:"jsonData"`
|
JsonData *simplejson.Json `json:"jsonData"`
|
||||||
SecureJsonData map[string]string `json:"secureJsonData"`
|
SecureJsonData map[string]string `json:"secureJsonData"`
|
||||||
|
|
||||||
OrgId int64 `json:"-"`
|
OrgId int64 `json:"-"`
|
||||||
Id int64 `json:"-"`
|
Id int64 `json:"-"`
|
||||||
|
Version int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteDataSourceByIdCommand struct {
|
type DeleteDataSourceByIdCommand struct {
|
||||||
|
@@ -141,6 +141,7 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
|
|||||||
JsonData: cmd.JsonData,
|
JsonData: cmd.JsonData,
|
||||||
SecureJsonData: securejsondata.GetEncryptedJsonData(cmd.SecureJsonData),
|
SecureJsonData: securejsondata.GetEncryptedJsonData(cmd.SecureJsonData),
|
||||||
Updated: time.Now(),
|
Updated: time.Now(),
|
||||||
|
Version: cmd.Version + 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.UseBool("is_default")
|
sess.UseBool("is_default")
|
||||||
|
@@ -52,6 +52,34 @@ export class MysqlDatasource {
|
|||||||
}).then(this.processQueryResult.bind(this));
|
}).then(this.processQueryResult.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testDatasource() {
|
||||||
|
return this.backendSrv.datasourceRequest({
|
||||||
|
url: '/api/tsdb/query',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
from: '5m',
|
||||||
|
to: 'now',
|
||||||
|
queries: [{
|
||||||
|
refId: 'A',
|
||||||
|
intervalMs: 1,
|
||||||
|
maxDataPoints: 1,
|
||||||
|
datasourceId: this.id,
|
||||||
|
rawSql: "SELECT 1",
|
||||||
|
format: 'table',
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
return { status: "success", message: "Database Connection OK", title: "Success" };
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
if (err.data && err.data.message) {
|
||||||
|
return { status: "error", message: err.data.message, title: "Error" };
|
||||||
|
} else {
|
||||||
|
return { status: "error", message: err.status, title: "Error" };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
processQueryResult(res) {
|
processQueryResult(res) {
|
||||||
var data = [];
|
var data = [];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user