mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 12:02:24 +08:00
MSSQL: Add connection timeout setting in configuration page (#58631)
* MSSQL add connection timeout * add docs * Update docs and add min value to the timeout setting
This commit is contained in:
@ -77,6 +77,10 @@ For example, use `1m` if Microsoft SQL Server writes data every minute.
|
|||||||
|
|
||||||
You can also override this setting in a dashboard panel under its data source options.
|
You can also override this setting in a dashboard panel under its data source options.
|
||||||
|
|
||||||
|
### Connection timeout
|
||||||
|
|
||||||
|
The **Connection timeout** setting defines the maximum number of seconds to wait for a connection to the database before timing out. Default is 0 for no timeout.
|
||||||
|
|
||||||
### Database user permissions
|
### Database user permissions
|
||||||
|
|
||||||
Grafana doesn't validate that a query is safe, and could include any SQL statement.
|
Grafana doesn't validate that a query is safe, and could include any SQL statement.
|
||||||
@ -119,6 +123,7 @@ datasources:
|
|||||||
maxOpenConns: 0 # Grafana v5.4+
|
maxOpenConns: 0 # Grafana v5.4+
|
||||||
maxIdleConns: 2 # Grafana v5.4+
|
maxIdleConns: 2 # Grafana v5.4+
|
||||||
connMaxLifetime: 14400 # Grafana v5.4+
|
connMaxLifetime: 14400 # Grafana v5.4+
|
||||||
|
connectionTimeout: 0 # Grafana v9.3+
|
||||||
secureJsonData:
|
secureJsonData:
|
||||||
password: 'Password!'
|
password: 'Password!'
|
||||||
```
|
```
|
||||||
|
@ -55,10 +55,11 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
|||||||
func newInstanceSettings(cfg *setting.Cfg) datasource.InstanceFactoryFunc {
|
func newInstanceSettings(cfg *setting.Cfg) datasource.InstanceFactoryFunc {
|
||||||
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||||
jsonData := sqleng.JsonData{
|
jsonData := sqleng.JsonData{
|
||||||
MaxOpenConns: 0,
|
MaxOpenConns: 0,
|
||||||
MaxIdleConns: 2,
|
MaxIdleConns: 2,
|
||||||
ConnMaxLifetime: 14400,
|
ConnMaxLifetime: 14400,
|
||||||
Encrypt: "false",
|
Encrypt: "false",
|
||||||
|
ConnectionTimeout: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := json.Unmarshal(settings.JSONData, &jsonData)
|
err := json.Unmarshal(settings.JSONData, &jsonData)
|
||||||
@ -171,6 +172,11 @@ func generateConnectionString(dsInfo sqleng.DataSourceInfo) (string, error) {
|
|||||||
} else if encrypt == "disable" {
|
} else if encrypt == "disable" {
|
||||||
connStr += fmt.Sprintf("encrypt=%s;", dsInfo.JsonData.Encrypt)
|
connStr += fmt.Sprintf("encrypt=%s;", dsInfo.JsonData.Encrypt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dsInfo.JsonData.ConnectionTimeout != 0 {
|
||||||
|
connStr += fmt.Sprintf("connection timeout=%d;", dsInfo.JsonData.ConnectionTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
return connStr, nil
|
return connStr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ type JsonData struct {
|
|||||||
MaxOpenConns int `json:"maxOpenConns"`
|
MaxOpenConns int `json:"maxOpenConns"`
|
||||||
MaxIdleConns int `json:"maxIdleConns"`
|
MaxIdleConns int `json:"maxIdleConns"`
|
||||||
ConnMaxLifetime int `json:"connMaxLifetime"`
|
ConnMaxLifetime int `json:"connMaxLifetime"`
|
||||||
|
ConnectionTimeout int `json:"connectionTimeout"`
|
||||||
Timescaledb bool `json:"timescaledb"`
|
Timescaledb bool `json:"timescaledb"`
|
||||||
Mode string `json:"sslmode"`
|
Mode string `json:"sslmode"`
|
||||||
ConfigurationMethod string `json:"tlsConfigurationMethod"`
|
ConfigurationMethod string `json:"tlsConfigurationMethod"`
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
Select,
|
Select,
|
||||||
useStyles2,
|
useStyles2,
|
||||||
} from '@grafana/ui';
|
} from '@grafana/ui';
|
||||||
|
import { NumberInput } from 'app/core/components/OptionsUI/NumberInput';
|
||||||
import { ConnectionLimits } from 'app/features/plugins/sql/components/configuration/ConnectionLimits';
|
import { ConnectionLimits } from 'app/features/plugins/sql/components/configuration/ConnectionLimits';
|
||||||
|
|
||||||
import { MSSQLAuthenticationType, MSSQLEncryptOptions, MssqlOptions } from '../types';
|
import { MSSQLAuthenticationType, MSSQLEncryptOptions, MssqlOptions } from '../types';
|
||||||
@ -60,6 +61,10 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onConnectionTimeoutChanged = (connectionTimeout?: number) => {
|
||||||
|
updateDatasourcePluginJsonDataOption(props, 'connectionTimeout', connectionTimeout ?? 0);
|
||||||
|
};
|
||||||
|
|
||||||
const authenticationOptions: Array<SelectableValue<MSSQLAuthenticationType>> = [
|
const authenticationOptions: Array<SelectableValue<MSSQLAuthenticationType>> = [
|
||||||
{ value: MSSQLAuthenticationType.sqlAuth, label: 'SQL Server Authentication' },
|
{ value: MSSQLAuthenticationType.sqlAuth, label: 'SQL Server Authentication' },
|
||||||
{ value: MSSQLAuthenticationType.windowsAuth, label: 'Windows Authentication' },
|
{ value: MSSQLAuthenticationType.windowsAuth, label: 'Windows Authentication' },
|
||||||
@ -74,6 +79,7 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
|||||||
const shortWidth = 15;
|
const shortWidth = 15;
|
||||||
const longWidth = 46;
|
const longWidth = 46;
|
||||||
const labelWidthSSL = 25;
|
const labelWidthSSL = 25;
|
||||||
|
const labelWidthDetails = 20;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -233,6 +239,7 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
label="Min time interval"
|
label="Min time interval"
|
||||||
|
labelWidth={labelWidthDetails}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
placeholder="1m"
|
placeholder="1m"
|
||||||
@ -240,6 +247,23 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
|||||||
onChange={onUpdateDatasourceJsonDataOption(props, 'timeInterval')}
|
onChange={onUpdateDatasourceJsonDataOption(props, 'timeInterval')}
|
||||||
></Input>
|
></Input>
|
||||||
</InlineField>
|
</InlineField>
|
||||||
|
<InlineField
|
||||||
|
tooltip={
|
||||||
|
<span>
|
||||||
|
The number of seconds to wait before canceling the request when connecting to the database. The default is{' '}
|
||||||
|
<code>0</code>, meaning no timeout.
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
label="Connection timeout"
|
||||||
|
labelWidth={labelWidthDetails}
|
||||||
|
>
|
||||||
|
<NumberInput
|
||||||
|
placeholder="60"
|
||||||
|
min={0}
|
||||||
|
value={jsonData.connectionTimeout}
|
||||||
|
onChange={onConnectionTimeoutChanged}
|
||||||
|
></NumberInput>
|
||||||
|
</InlineField>
|
||||||
</FieldSet>
|
</FieldSet>
|
||||||
|
|
||||||
<Alert title="User Permission" severity="info">
|
<Alert title="User Permission" severity="info">
|
||||||
|
@ -15,4 +15,5 @@ export interface MssqlOptions extends SQLOptions {
|
|||||||
encrypt?: MSSQLEncryptOptions;
|
encrypt?: MSSQLEncryptOptions;
|
||||||
sslRootCertFile?: string;
|
sslRootCertFile?: string;
|
||||||
serverName?: string;
|
serverName?: string;
|
||||||
|
connectionTimeout?: number;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user