mirror of
https://github.com/grafana/grafana.git
synced 2024-11-24 09:50:29 -06: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:
parent
78bb8c10ce
commit
6e776d0fec
@ -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.
|
||||
|
||||
### 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
|
||||
|
||||
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+
|
||||
maxIdleConns: 2 # Grafana v5.4+
|
||||
connMaxLifetime: 14400 # Grafana v5.4+
|
||||
connectionTimeout: 0 # Grafana v9.3+
|
||||
secureJsonData:
|
||||
password: 'Password!'
|
||||
```
|
||||
|
@ -55,10 +55,11 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
||||
func newInstanceSettings(cfg *setting.Cfg) datasource.InstanceFactoryFunc {
|
||||
return func(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||
jsonData := sqleng.JsonData{
|
||||
MaxOpenConns: 0,
|
||||
MaxIdleConns: 2,
|
||||
ConnMaxLifetime: 14400,
|
||||
Encrypt: "false",
|
||||
MaxOpenConns: 0,
|
||||
MaxIdleConns: 2,
|
||||
ConnMaxLifetime: 14400,
|
||||
Encrypt: "false",
|
||||
ConnectionTimeout: 0,
|
||||
}
|
||||
|
||||
err := json.Unmarshal(settings.JSONData, &jsonData)
|
||||
@ -171,6 +172,11 @@ func generateConnectionString(dsInfo sqleng.DataSourceInfo) (string, error) {
|
||||
} else if encrypt == "disable" {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ type JsonData struct {
|
||||
MaxOpenConns int `json:"maxOpenConns"`
|
||||
MaxIdleConns int `json:"maxIdleConns"`
|
||||
ConnMaxLifetime int `json:"connMaxLifetime"`
|
||||
ConnectionTimeout int `json:"connectionTimeout"`
|
||||
Timescaledb bool `json:"timescaledb"`
|
||||
Mode string `json:"sslmode"`
|
||||
ConfigurationMethod string `json:"tlsConfigurationMethod"`
|
||||
|
@ -21,6 +21,7 @@ import {
|
||||
Select,
|
||||
useStyles2,
|
||||
} from '@grafana/ui';
|
||||
import { NumberInput } from 'app/core/components/OptionsUI/NumberInput';
|
||||
import { ConnectionLimits } from 'app/features/plugins/sql/components/configuration/ConnectionLimits';
|
||||
|
||||
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>> = [
|
||||
{ value: MSSQLAuthenticationType.sqlAuth, label: 'SQL Server Authentication' },
|
||||
{ value: MSSQLAuthenticationType.windowsAuth, label: 'Windows Authentication' },
|
||||
@ -74,6 +79,7 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
||||
const shortWidth = 15;
|
||||
const longWidth = 46;
|
||||
const labelWidthSSL = 25;
|
||||
const labelWidthDetails = 20;
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -233,6 +239,7 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
||||
</span>
|
||||
}
|
||||
label="Min time interval"
|
||||
labelWidth={labelWidthDetails}
|
||||
>
|
||||
<Input
|
||||
placeholder="1m"
|
||||
@ -240,6 +247,23 @@ export const ConfigurationEditor = (props: DataSourcePluginOptionsEditorProps<Ms
|
||||
onChange={onUpdateDatasourceJsonDataOption(props, 'timeInterval')}
|
||||
></Input>
|
||||
</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>
|
||||
|
||||
<Alert title="User Permission" severity="info">
|
||||
|
@ -15,4 +15,5 @@ export interface MssqlOptions extends SQLOptions {
|
||||
encrypt?: MSSQLEncryptOptions;
|
||||
sslRootCertFile?: string;
|
||||
serverName?: string;
|
||||
connectionTimeout?: number;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user