import React, { FC, useEffect, useState } from 'react'; import { useDebounce } from 'react-use'; import { ConnectionConfig } from '@grafana/aws-sdk'; import { rangeUtil, DataSourcePluginOptionsEditorProps, onUpdateDatasourceJsonDataOption, updateDatasourcePluginJsonDataOption, } from '@grafana/data'; import { Input, InlineField } from '@grafana/ui'; import { notifyApp } from 'app/core/actions'; import { createWarningNotification } from 'app/core/copy/appNotification'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { store } from 'app/store/store'; import { CloudWatchDatasource } from '../datasource'; import { CloudWatchJsonData, CloudWatchSecureJsonData } from '../types'; import { XrayLinkConfig } from './XrayLinkConfig'; export type Props = DataSourcePluginOptionsEditorProps; export const ConfigEditor: FC = (props: Props) => { const { options } = props; const datasource = useDatasource(options.name); useAuthenticationWarning(options.jsonData); const logsTimeoutError = useTimoutValidation(props.options.jsonData.logsTimeout); return ( <> datasource!.getRegions().then((r) => r.filter((r) => r.value !== 'default').map((v) => v.value))) } >

CloudWatch Logs

updateDatasourcePluginJsonDataOption(props, 'tracingDatasourceUid', uid)} datasourceUid={options.jsonData.tracingDatasourceUid} /> ); }; function useAuthenticationWarning(jsonData: CloudWatchJsonData) { const addWarning = (message: string) => { store.dispatch(notifyApp(createWarningNotification('CloudWatch Authentication', message))); }; useEffect(() => { if (jsonData.authType === 'arn') { addWarning('Since grafana 7.3 authentication type "arn" is deprecated, falling back to default SDK provider'); } else if (jsonData.authType === 'credentials' && !jsonData.profile && !jsonData.database) { addWarning( 'As of grafana 7.3 authentication type "credentials" should be used only for shared file credentials. \ If you don\'t have a credentials file, switch to the default SDK provider for extracting credentials \ from environment variables or IAM roles' ); } }, [jsonData.authType, jsonData.database, jsonData.profile]); } function useDatasource(datasourceName: string) { const [datasource, setDatasource] = useState(); useEffect(() => { getDatasourceSrv() .loadDatasource(datasourceName) .then((datasource) => { // It's really difficult to type .loadDatasource() because it's inherently untyped as it involves two JSON.parse()'s // So a "as" type assertion here is a necessary evil. setDatasource(datasource as CloudWatchDatasource); }); }, [datasourceName]); return datasource; } function useTimoutValidation(value: string | undefined) { const [err, setErr] = useState(undefined); useDebounce( () => { if (value) { try { rangeUtil.describeInterval(value); setErr(undefined); } catch (e) { setErr(e.toString()); } } else { setErr(undefined); } }, 350, [value] ); return err; }