mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 16:27:02 -06:00
InfluxDB: Move database information into jsondata (#62308)
* Use dbName in jsonData instead of database * Use dbName in instead of database * Remove database fields and define dbName instead * Fix tests * set database field as empty string
This commit is contained in:
parent
77a186879d
commit
65fbbc06fd
@ -76,11 +76,12 @@ datasources:
|
||||
- name: gdev-influxdb1-influxql
|
||||
type: influxdb
|
||||
access: proxy
|
||||
database: site
|
||||
user: grafana
|
||||
url: http://localhost:8087
|
||||
secureJsonData:
|
||||
password: grafana
|
||||
jsonData:
|
||||
dbName: site
|
||||
|
||||
- name: gdev-influxdb-flux
|
||||
type: influxdb
|
||||
@ -98,9 +99,9 @@ datasources:
|
||||
- name: gdev-influxdb-influxql
|
||||
type: influxdb
|
||||
access: proxy
|
||||
database: mybucket
|
||||
url: http://localhost:8086
|
||||
jsonData:
|
||||
dbName: mybucket
|
||||
httpHeaderName1: "Authorization"
|
||||
secureJsonData:
|
||||
httpHeaderValue1: "Token mytoken"
|
||||
|
@ -32,11 +32,12 @@ datasources:
|
||||
- name: gdev-influxdb1-influxql
|
||||
type: influxdb
|
||||
access: proxy
|
||||
database: site
|
||||
user: grafana
|
||||
url: http://influxdb1:8086
|
||||
secureJsonData:
|
||||
password: grafana
|
||||
jsonData:
|
||||
dbName: site
|
||||
|
||||
- name: gdev-influxdb-flux
|
||||
type: influxdb
|
||||
@ -52,9 +53,9 @@ datasources:
|
||||
- name: gdev-influxdb-influxql
|
||||
type: influxdb
|
||||
access: proxy
|
||||
database: mybucket
|
||||
url: http://influxdb:8086
|
||||
jsonData:
|
||||
dbName: mybucket
|
||||
httpHeaderName1: "Authorization"
|
||||
secureJsonData:
|
||||
httpHeaderValue1: "Token mytoken"
|
||||
|
@ -69,10 +69,14 @@ func newInstanceSettings(httpClientProvider httpclient.Provider) datasource.Inst
|
||||
if version == "" {
|
||||
version = influxVersionInfluxQL
|
||||
}
|
||||
database := jsonData.DbName
|
||||
if database == "" {
|
||||
database = settings.Database
|
||||
}
|
||||
model := &models.DatasourceInfo{
|
||||
HTTPClient: client,
|
||||
URL: settings.URL,
|
||||
Database: settings.Database,
|
||||
DbName: database,
|
||||
Version: version,
|
||||
HTTPMode: httpMode,
|
||||
TimeInterval: jsonData.TimeInterval,
|
||||
@ -178,7 +182,7 @@ func (s *Service) createRequest(ctx context.Context, logger log.Logger, dsInfo *
|
||||
req.Header.Set("User-Agent", "Grafana")
|
||||
|
||||
params := req.URL.Query()
|
||||
params.Set("db", dsInfo.Database)
|
||||
params.Set("db", dsInfo.DbName)
|
||||
params.Set("epoch", "ms")
|
||||
|
||||
if httpMode == "GET" {
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
func TestExecutor_createRequest(t *testing.T) {
|
||||
datasource := &models.DatasourceInfo{
|
||||
URL: "http://awesome-influxdb:1337",
|
||||
Database: "awesome-db",
|
||||
DbName: "awesome-db",
|
||||
HTTPMode: "GET",
|
||||
}
|
||||
query := "SELECT awesomeness FROM somewhere"
|
||||
|
@ -68,7 +68,7 @@ func (f *fakeInstance) Get(pluginContext backend.PluginContext) (instancemgmt.In
|
||||
HTTPClient: client,
|
||||
Token: "sometoken",
|
||||
URL: "https://awesome-influx.com",
|
||||
Database: "testdb",
|
||||
DbName: "testdb",
|
||||
Version: f.version,
|
||||
HTTPMode: "GET",
|
||||
TimeInterval: "10s",
|
||||
|
@ -9,7 +9,7 @@ type DatasourceInfo struct {
|
||||
Token string
|
||||
URL string
|
||||
|
||||
Database string `json:"database"`
|
||||
DbName string `json:"dbName"`
|
||||
Version string `json:"version"`
|
||||
HTTPMode string `json:"httpMode"`
|
||||
TimeInterval string `json:"timeInterval"`
|
||||
|
@ -3,13 +3,13 @@ import React, { PureComponent } from 'react';
|
||||
|
||||
import {
|
||||
DataSourcePluginOptionsEditorProps,
|
||||
SelectableValue,
|
||||
onUpdateDatasourceOption,
|
||||
updateDatasourcePluginResetOption,
|
||||
onUpdateDatasourceJsonDataOption,
|
||||
onUpdateDatasourceJsonDataOptionSelect,
|
||||
onUpdateDatasourceOption,
|
||||
onUpdateDatasourceSecureJsonDataOption,
|
||||
SelectableValue,
|
||||
updateDatasourcePluginJsonDataOption,
|
||||
updateDatasourcePluginResetOption,
|
||||
} from '@grafana/data';
|
||||
import {
|
||||
Alert,
|
||||
@ -18,15 +18,16 @@ import {
|
||||
InlineField,
|
||||
InlineFormLabel,
|
||||
LegacyForms,
|
||||
Select,
|
||||
SecureSocksProxySettings,
|
||||
Select,
|
||||
} from '@grafana/ui';
|
||||
import { config } from 'app/core/config';
|
||||
|
||||
const { Input, SecretFormField } = LegacyForms;
|
||||
import { BROWSER_MODE_DISABLED_MESSAGE } from '../constants';
|
||||
import { InfluxOptions, InfluxSecureJsonData, InfluxVersion } from '../types';
|
||||
|
||||
const { Input, SecretFormField } = LegacyForms;
|
||||
|
||||
const httpModes: SelectableValue[] = [
|
||||
{ label: 'GET', value: 'GET' },
|
||||
{ label: 'POST', value: 'POST' },
|
||||
@ -199,8 +200,17 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
||||
<Input
|
||||
id={`${htmlPrefix}-db`}
|
||||
className="width-20"
|
||||
value={options.database || ''}
|
||||
onChange={onUpdateDatasourceOption(this.props, 'database')}
|
||||
value={options.jsonData.dbName ?? options.database}
|
||||
onChange={(event) => {
|
||||
this.props.onOptionsChange({
|
||||
...options,
|
||||
database: '',
|
||||
jsonData: {
|
||||
...options.jsonData,
|
||||
dbName: event.target.value,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -62,11 +62,11 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
||||
this.username = instanceSettings.username ?? '';
|
||||
this.password = instanceSettings.password ?? '';
|
||||
this.name = instanceSettings.name;
|
||||
this.database = instanceSettings.database;
|
||||
this.basicAuth = instanceSettings.basicAuth;
|
||||
this.withCredentials = instanceSettings.withCredentials;
|
||||
this.access = instanceSettings.access;
|
||||
const settingsData = instanceSettings.jsonData || ({} as InfluxOptions);
|
||||
this.database = settingsData.dbName ?? instanceSettings.database;
|
||||
this.interval = settingsData.timeInterval;
|
||||
this.httpMode = settingsData.httpMode || 'GET';
|
||||
this.responseParser = new ResponseParser();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DataQuery, DataSourceJsonData, AdHocVariableFilter } from '@grafana/data';
|
||||
import { AdHocVariableFilter, DataQuery, DataSourceJsonData } from '@grafana/data';
|
||||
|
||||
export enum InfluxVersion {
|
||||
InfluxQL = 'InfluxQL',
|
||||
@ -11,6 +11,8 @@ export interface InfluxOptions extends DataSourceJsonData {
|
||||
timeInterval?: string;
|
||||
httpMode?: string;
|
||||
|
||||
dbName?: string;
|
||||
|
||||
// With Flux
|
||||
organization?: string;
|
||||
defaultBucket?: string;
|
||||
|
Loading…
Reference in New Issue
Block a user