mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Inital work on SQL metric/annotation data source, #1542
This commit is contained in:
parent
a3fe1efa2b
commit
d0d995da09
@ -73,7 +73,7 @@ func Register(r *macaron.Macaron) {
|
||||
|
||||
// Data sources
|
||||
r.Group("/datasources", func() {
|
||||
r.Combo("/").Get(GetDataSources).Put(AddDataSource).Post(UpdateDataSource)
|
||||
r.Combo("/").Get(GetDataSources).Put(AddDataSource).Post(bind(m.UpdateDataSourceCommand{}), UpdateDataSource)
|
||||
r.Delete("/:id", DeleteDataSource)
|
||||
r.Get("/:id", GetDataSourceById)
|
||||
r.Get("/plugins", GetDataSourcePlugins)
|
||||
|
@ -61,6 +61,7 @@ func GetDataSourceById(c *middleware.Context) {
|
||||
User: ds.User,
|
||||
BasicAuth: ds.BasicAuth,
|
||||
IsDefault: ds.IsDefault,
|
||||
JsonData: ds.JsonData,
|
||||
})
|
||||
}
|
||||
|
||||
@ -101,14 +102,7 @@ func AddDataSource(c *middleware.Context) {
|
||||
c.JsonOK("Datasource added")
|
||||
}
|
||||
|
||||
func UpdateDataSource(c *middleware.Context) {
|
||||
cmd := m.UpdateDataSourceCommand{}
|
||||
|
||||
if !c.JsonBody(&cmd) {
|
||||
c.JsonApiErr(400, "Validation failed", nil)
|
||||
return
|
||||
}
|
||||
|
||||
func UpdateDataSource(c *middleware.Context, cmd m.UpdateDataSourceCommand) {
|
||||
cmd.OrgId = c.OrgId
|
||||
|
||||
err := bus.Dispatch(&cmd)
|
||||
|
@ -38,17 +38,18 @@ type Dashboard struct {
|
||||
}
|
||||
|
||||
type DataSource struct {
|
||||
Id int64 `json:"id"`
|
||||
OrgId int64 `json:"orgId"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Access m.DsAccess `json:"access"`
|
||||
Url string `json:"url"`
|
||||
Password string `json:"password"`
|
||||
User string `json:"user"`
|
||||
Database string `json:"database"`
|
||||
BasicAuth bool `json:"basicAuth"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
Id int64 `json:"id"`
|
||||
OrgId int64 `json:"orgId"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Access m.DsAccess `json:"access"`
|
||||
Url string `json:"url"`
|
||||
Password string `json:"password"`
|
||||
User string `json:"user"`
|
||||
Database string `json:"database"`
|
||||
BasicAuth bool `json:"basicAuth"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
JsonData map[string]interface{} `json:"jsonData"`
|
||||
}
|
||||
|
||||
type MetricQueryResultDto struct {
|
||||
|
@ -38,6 +38,7 @@ type DataSource struct {
|
||||
BasicAuthUser string
|
||||
BasicAuthPassword string
|
||||
IsDefault bool
|
||||
JsonData map[string]interface{}
|
||||
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
@ -63,16 +64,18 @@ type AddDataSourceCommand struct {
|
||||
|
||||
// Also acts as api DTO
|
||||
type UpdateDataSourceCommand struct {
|
||||
Id int64
|
||||
OrgId int64
|
||||
Name string
|
||||
Type string
|
||||
Access DsAccess
|
||||
Url string
|
||||
Password string
|
||||
User string
|
||||
Database string
|
||||
IsDefault bool
|
||||
Id int64 `json:"id" binding:"Required"`
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Type string `json:"type" binding:"Required"`
|
||||
Access DsAccess `json:"access" binding:"Required"`
|
||||
Url string `json:"url"`
|
||||
Password string `json:"password"`
|
||||
User string `json:"user"`
|
||||
Database string `json:"database"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
JsonData map[string]interface{} `json:"jsonData"`
|
||||
|
||||
OrgId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type DeleteDataSourceCommand struct {
|
||||
|
@ -106,8 +106,9 @@ func UpdateDataSource(cmd *m.UpdateDataSourceCommand) error {
|
||||
User: cmd.User,
|
||||
Password: cmd.Password,
|
||||
Database: cmd.Database,
|
||||
Updated: time.Now(),
|
||||
IsDefault: cmd.IsDefault,
|
||||
JsonData: cmd.JsonData,
|
||||
Updated: time.Now(),
|
||||
}
|
||||
|
||||
sess.UseBool("is_default")
|
||||
|
20
src/app/plugins/datasource/sql/datasource.js
Normal file
20
src/app/plugins/datasource/sql/datasource.js
Normal file
@ -0,0 +1,20 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'kbn',
|
||||
],
|
||||
function (angular) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.services');
|
||||
|
||||
module.factory('SqlDatasource', function() {
|
||||
|
||||
function SqlDatasource() {
|
||||
}
|
||||
|
||||
return SqlDatasource;
|
||||
|
||||
});
|
||||
|
||||
});
|
53
src/app/plugins/datasource/sql/partials/config.html
Normal file
53
src/app/plugins/datasource/sql/partials/config.html
Normal file
@ -0,0 +1,53 @@
|
||||
<h2>SQL Options</h2>
|
||||
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 80px">
|
||||
DB Type
|
||||
</li>
|
||||
<li>
|
||||
<select class="input-medium tight-form-input" ng-model="current.jsonData.dbType" ng-options="f for f in ['sqlite3','mysql','postgres']"></select>
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 80px">
|
||||
Host
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-medium" ng-model='current.jsonData.host' placeholder="localhost:3306">
|
||||
</li>
|
||||
<li class="tight-form-item" ng-if="current.jsonData.dbType === 'postgres'">
|
||||
SSL
|
||||
<input class="cr1" id="jsonData.ssl" type="checkbox" ng-model="current.jsonData.ssl" ng-checked="current.jsonData.ssl">
|
||||
<label for="jsonData.ssl" class="cr1"></label>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 80px">
|
||||
Database
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-medium" ng-model='current.database' placeholder="">
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item" style="width: 80px">
|
||||
User
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" class="tight-form-input input-medium" ng-model='current.user' placeholder="">
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 80px">
|
||||
Password
|
||||
</li>
|
||||
<li>
|
||||
<input type="password" class="tight-form-input input-medium" ng-model='current.password' placeholder="">
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
17
src/app/plugins/datasource/sql/partials/query.editor.html
Normal file
17
src/app/plugins/datasource/sql/partials/query.editor.html
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
<div class="fluid-row" style="margin-top: 20px">
|
||||
<div class="span2"></div>
|
||||
<div class="grafana-info-box span8">
|
||||
<h5>Test graph</h5>
|
||||
|
||||
<p>
|
||||
This is just a test data source that generates random walk series. If this is your only data source
|
||||
open the left side menu and navigate to the data sources admin screen and add your data sources. You can change
|
||||
data source using the button to the left of the <strong>Add query</strong> button.
|
||||
</p>
|
||||
</div>
|
||||
<div class="span2"></div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
|
16
src/app/plugins/datasource/sql/plugin.json
Normal file
16
src/app/plugins/datasource/sql/plugin.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"pluginType": "datasource",
|
||||
"name": "Generic SQL (prototype)",
|
||||
|
||||
"type": "generic_sql",
|
||||
"serviceName": "SqlDatasource",
|
||||
|
||||
"module": "plugins/datasource/sql/datasource",
|
||||
|
||||
"partials": {
|
||||
"config": "app/plugins/datasource/sql/partials/config.html",
|
||||
"query": "app/plugins/datasource/sql/partials/query.editor.html"
|
||||
},
|
||||
|
||||
"metrics": true
|
||||
}
|
Loading…
Reference in New Issue
Block a user