import React from 'react'; import { gte, lt, valid } from 'semver'; import { DataSourceSettings, SelectableValue } from '@grafana/data'; import { FieldSet, InlineField, Input, Select, InlineSwitch } from '@grafana/ui'; import { ElasticsearchOptions, Interval } from '../types'; import { isTruthy } from './utils'; const indexPatternTypes: Array> = [ { 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: SelectableValue[] = [ { label: '7.10+', value: '7.10.0' }, { label: '8.0+', value: '8.0.0', description: 'support for Elasticsearch 8 is currently experimental', }, ]; type Props = { value: DataSourceSettings; onChange: (value: DataSourceSettings) => void; }; export const ElasticDetails = ({ value, onChange }: Props) => { const currentVersion = esVersions.find((version) => version.value === value.jsonData.esVersion); const customOption = !currentVersion && valid(value.jsonData.esVersion) ? { label: value.jsonData.esVersion, value: value.jsonData.esVersion, } : undefined; return ( <>
)} 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. } error="Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s" invalid={!!value.jsonData.timeInterval && !/^\d+(ms|[Mwdhmsy])$/.test(value.jsonData.timeInterval)} > {gte(value.jsonData.esVersion, '6.6.0') && value.jsonData.xpack && ( )}
); }; // TODO: Use change handlers from @grafana/data const changeHandler = (key: keyof DataSourceSettings, value: Props['value'], onChange: Props['onChange']) => (event: React.SyntheticEvent) => { onChange({ ...value, [key]: event.currentTarget.value, }); }; // TODO: Use change handlers from @grafana/data const jsonDataChangeHandler = (key: keyof ElasticsearchOptions, value: Props['value'], onChange: Props['onChange']) => (event: React.SyntheticEvent) => { onChange({ ...value, jsonData: { ...value.jsonData, [key]: event.currentTarget.value, }, }); }; const jsonDataSwitchChangeHandler = (key: keyof ElasticsearchOptions, value: Props['value'], onChange: Props['onChange']) => (event: React.SyntheticEvent) => { onChange({ ...value, jsonData: { ...value.jsonData, [key]: event.currentTarget.checked, }, }); }; 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 | undefined, version: string): number { if (maxConcurrentShardRequests === 5 && lt(version, '7.0.0')) { return 256; } if (maxConcurrentShardRequests === 256 && gte(version, '7.0.0')) { return 5; } return maxConcurrentShardRequests || defaultMaxConcurrentShardRequests(version); } export function defaultMaxConcurrentShardRequests(version: string) { return gte(version, '7.0.0') ? 5 : 256; }