2019-10-25 22:43:20 +08:00
|
|
|
import React, { useEffect } from 'react';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2019-10-31 17:48:05 +08:00
|
|
|
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
2022-04-22 21:33:13 +08:00
|
|
|
import { Alert, DataSourceHttpSettings } from '@grafana/ui';
|
|
|
|
|
import { config } from 'app/core/config';
|
|
|
|
|
|
2019-10-25 22:43:20 +08:00
|
|
|
import { ElasticsearchOptions } from '../types';
|
2022-05-05 22:16:34 +08:00
|
|
|
import { isSupportedVersion } from '../utils';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
|
|
|
|
import { DataLinks } from './DataLinks';
|
2021-05-11 16:44:00 +08:00
|
|
|
import { ElasticDetails } from './ElasticDetails';
|
2019-10-25 22:43:20 +08:00
|
|
|
import { LogsConfig } from './LogsConfig';
|
2021-05-11 16:44:00 +08:00
|
|
|
import { coerceOptions, isValidOptions } from './utils';
|
2019-10-25 22:43:20 +08:00
|
|
|
|
|
|
|
|
export type Props = DataSourcePluginOptionsEditorProps<ElasticsearchOptions>;
|
2021-05-11 16:44:00 +08:00
|
|
|
|
2019-10-25 22:43:20 +08:00
|
|
|
export const ConfigEditor = (props: Props) => {
|
2021-05-11 16:44:00 +08:00
|
|
|
const { options: originalOptions, onOptionsChange } = props;
|
|
|
|
|
const options = coerceOptions(originalOptions);
|
2019-10-25 22:43:20 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-05-11 16:44:00 +08:00
|
|
|
if (!isValidOptions(originalOptions)) {
|
|
|
|
|
onOptionsChange(coerceOptions(originalOptions));
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 19:42:14 +08:00
|
|
|
// We can't enforce the eslint rule here because we only want to run this once.
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2019-10-25 22:43:20 +08:00
|
|
|
}, []);
|
|
|
|
|
|
2022-05-05 22:16:34 +08:00
|
|
|
const supportedVersion = isSupportedVersion(options.jsonData.esVersion);
|
2022-05-02 23:08:47 +08:00
|
|
|
|
2019-10-25 22:43:20 +08:00
|
|
|
return (
|
|
|
|
|
<>
|
2020-12-09 21:27:40 +08:00
|
|
|
{options.access === 'direct' && (
|
|
|
|
|
<Alert title="Deprecation Notice" severity="warning">
|
|
|
|
|
Browser access mode in the Elasticsearch datasource is deprecated and will be removed in a future release.
|
|
|
|
|
</Alert>
|
|
|
|
|
)}
|
2022-05-05 22:16:34 +08:00
|
|
|
{!supportedVersion && (
|
|
|
|
|
<Alert title="Deprecation notice" severity="error">
|
|
|
|
|
{`Support for Elasticsearch versions after their end-of-life (currently versions < 7.10) was removed`}
|
2022-05-02 23:08:47 +08:00
|
|
|
</Alert>
|
|
|
|
|
)}
|
2020-12-09 21:27:40 +08:00
|
|
|
|
2019-10-25 22:43:20 +08:00
|
|
|
<DataSourceHttpSettings
|
2021-05-11 16:44:00 +08:00
|
|
|
defaultUrl="http://localhost:9200"
|
2019-10-25 22:43:20 +08:00
|
|
|
dataSourceConfig={options}
|
2021-05-11 16:44:00 +08:00
|
|
|
showAccessOptions
|
2019-10-25 22:43:20 +08:00
|
|
|
onChange={onOptionsChange}
|
2020-10-08 16:03:20 +08:00
|
|
|
sigV4AuthToggleEnabled={config.sigV4AuthEnabled}
|
2019-10-25 22:43:20 +08:00
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<ElasticDetails value={options} onChange={onOptionsChange} />
|
|
|
|
|
|
|
|
|
|
<LogsConfig
|
|
|
|
|
value={options.jsonData}
|
2021-01-20 14:59:48 +08:00
|
|
|
onChange={(newValue) =>
|
2019-10-25 22:43:20 +08:00
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
jsonData: newValue,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
2019-12-12 00:40:56 +08:00
|
|
|
|
|
|
|
|
<DataLinks
|
|
|
|
|
value={options.jsonData.dataLinks}
|
2021-01-20 14:59:48 +08:00
|
|
|
onChange={(newValue) => {
|
2019-12-12 00:40:56 +08:00
|
|
|
onOptionsChange({
|
|
|
|
|
...options,
|
|
|
|
|
jsonData: {
|
|
|
|
|
...options.jsonData,
|
|
|
|
|
dataLinks: newValue,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2019-10-25 22:43:20 +08:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|