diff --git a/src/configuration/ConfigEditor.tsx b/src/configuration/ConfigEditor.tsx index efa011c..b169d52 100644 --- a/src/configuration/ConfigEditor.tsx +++ b/src/configuration/ConfigEditor.tsx @@ -49,24 +49,6 @@ export const QuickwitDetails = ({ value, onChange }: DetailsProps) => { width={40} /> - - onChange({ ...value, jsonData: {...value.jsonData, timeField: event.currentTarget.value}})} - placeholder="timestamp" - width={40} - /> - - - onChange({ ...value, jsonData: {...value.jsonData, timeOutputFormat: event.currentTarget.value}})} - placeholder="unix_timestamp_millisecs" - width={40} - /> - { return createDatasourceSettings({ - timeField: 'timestamp', - timeOutputFormat: 'unix_timestamp_millisecs', logMessageField: 'test.message', logLevelField: 'test.level', index: 'test', diff --git a/src/datasource.ts b/src/datasource.ts index 36cd0a2..7a0fc76 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -58,7 +58,6 @@ export class QuickwitDataSource { index: string; timeField: string; - timeOutputFormat: string; logMessageField?: string; logLevelField?: string; queryBuilder: ElasticQueryBuilder; @@ -72,13 +71,20 @@ export class QuickwitDataSource super(instanceSettings); const settingsData = instanceSettings.jsonData || ({} as QuickwitOptions); this.index = settingsData.index || ''; - this.timeField = settingsData.timeField || ''; - this.timeOutputFormat = settingsData.timeOutputFormat || ''; - this.logMessageField = settingsData.logMessageField || ''; - this.logLevelField = settingsData.logLevelField || ''; + this.timeField = '' this.queryBuilder = new ElasticQueryBuilder({ timeField: this.timeField, }); + from(this.getResource('indexes/' + this.index + '/describe')).pipe( + map(config => config.timestamp_field_name) + ).subscribe(result => { + this.timeField = result; + this.queryBuilder = new ElasticQueryBuilder({ + timeField: this.timeField, + }); + }); + this.logMessageField = settingsData.logMessageField || ''; + this.logLevelField = settingsData.logLevelField || ''; this.dataLinks = settingsData.dataLinks || []; this.languageProvider = new ElasticsearchLanguageProvider(this); } @@ -104,12 +110,7 @@ export class QuickwitDataSource message: 'Cannot save datasource, `index` is required', }; } - if (this.timeField === '' ) { - return { - status: 'error', - message: 'Cannot save datasource, `timeField` is required', - }; - } + return lastValueFrom( from(this.getResource('indexes/' + this.index)).pipe( mergeMap((indexMetadata) => { @@ -145,16 +146,16 @@ export class QuickwitDataSource } let fields = getAllFields(indexMetadata.index_config.doc_mapping.field_mappings); let timestampField = fields.find((field) => field.json_path === this.timeField); + // Should never happen. if (timestampField === undefined) { return `No field named '${this.timeField}' found in the doc mapping. This should never happen.`; } - if (timestampField.field_mapping.output_format !== this.timeOutputFormat) { - return `Timestamp output format is declared as '${timestampField.field_mapping.output_format}' in the doc mapping, not '${this.timeOutputFormat}'.`; - } + + let timeOutputFormat = timestampField.field_mapping.output_format || 'unknown'; const supportedTimestampOutputFormats = ['unix_timestamp_secs', 'unix_timestamp_millis', 'unix_timestamp_micros', 'unix_timestamp_nanos', 'iso8601', 'rfc3339']; - if (!supportedTimestampOutputFormats.includes(this.timeOutputFormat)) { - return `Timestamp output format '${this.timeOutputFormat} is not yet supported.`; + if (!supportedTimestampOutputFormats.includes(timeOutputFormat)) { + return `Timestamp output format '${timeOutputFormat} is not yet supported.`; } return; } diff --git a/src/mocks.ts b/src/mocks.ts index 349c4b5..218b0a2 100644 --- a/src/mocks.ts +++ b/src/mocks.ts @@ -38,8 +38,6 @@ export function createElasticDatasource( access: 'proxy', url: '', jsonData: { - timeField: '', - timeOutputFormat: '', index: '', ...jsonData, }, diff --git a/src/quickwit.ts b/src/quickwit.ts index 7688a65..a7b4163 100644 --- a/src/quickwit.ts +++ b/src/quickwit.ts @@ -2,8 +2,6 @@ import { DataSourceJsonData } from "@grafana/data"; import { DataLinkConfig } from "types"; export interface QuickwitOptions extends DataSourceJsonData { - timeField: string; - timeOutputFormat: string; interval?: Interval; logMessageField?: string; logLevelField?: string;