import React from 'react'; import { DataSourceSettings, EventsWithValidation, FormField, Input, regexValidation, Select } from '@grafana/ui'; import { ElasticsearchOptions } from '../types'; import { SelectableValue } from '@grafana/data'; const indexPatternTypes = [ { label: 'No pattern', value: 'none' }, { label: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' }, { label: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' }, { label: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' }, { label: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' }, { label: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' }, ]; const esVersions = [ { label: '2.x', value: 2 }, { label: '5.x', value: 5 }, { label: '5.6+', value: 56 }, { label: '6.0+', value: 60 }, { label: '7.0+', value: 70 }, ]; type Props = { value: DataSourceSettings; onChange: (value: DataSourceSettings) => void; }; export const ElasticDetails = (props: Props) => { const { value, onChange } = props; return ( <>

Elasticsearch details

pattern.value === (value.jsonData.interval === undefined ? 'none' : value.jsonData.interval) )} /> } />
{ const maxConcurrentShardRequests = getMaxConcurrenShardRequestOrDefault( value.jsonData.maxConcurrentShardRequests, option.value ); onChange({ ...value, jsonData: { ...value.jsonData, esVersion: option.value, maxConcurrentShardRequests, }, }); }} value={esVersions.find(version => version.value === value.jsonData.esVersion)} /> } />
{value.jsonData.esVersion >= 56 && (
)}
} tooltip={ <> A lower limit for the auto group by time interval. Recommended to be set to write frequency, for example 1m if your data is written every minute. } />
); }; const changeHandler = ( key: keyof DataSourceSettings, value: Props['value'], onChange: Props['onChange'] ) => (event: React.SyntheticEvent) => { onChange({ ...value, [key]: event.currentTarget.value, }); }; const jsonDataChangeHandler = (key: keyof ElasticsearchOptions, value: Props['value'], onChange: Props['onChange']) => ( event: React.SyntheticEvent ) => { onChange({ ...value, jsonData: { ...value.jsonData, [key]: event.currentTarget.value, }, }); }; const intervalHandler = (value: Props['value'], onChange: Props['onChange']) => (option: SelectableValue) => { const { database } = value; // If option value is undefined it will send its label instead so we have to convert made up value to undefined here. const newInterval = option.value === 'none' ? undefined : option.value; if (!database || database.length === 0 || database.startsWith('[logstash-]')) { let newDatabase = ''; if (newInterval !== undefined) { const pattern = indexPatternTypes.find(pattern => pattern.value === newInterval); if (pattern) { newDatabase = pattern.example; } } onChange({ ...value, database: newDatabase, jsonData: { ...value.jsonData, interval: newInterval, }, }); } else { onChange({ ...value, jsonData: { ...value.jsonData, interval: newInterval, }, }); } }; function getMaxConcurrenShardRequestOrDefault(maxConcurrentShardRequests: number, version: number): number { if (maxConcurrentShardRequests === 5 && version < 70) { return 256; } if (maxConcurrentShardRequests === 256 && version >= 70) { return 5; } return maxConcurrentShardRequests || defaultMaxConcurrentShardRequests(version); } export function defaultMaxConcurrentShardRequests(version: number) { return version >= 70 ? 5 : 256; }