I have a need for the ElasticSearch datasource plugin with a few modifications and have used the original repo as starting point for development. After editing the code and removing features that require modules that aren’t exposed or are not necessary for my purpose, I have a working custom ElasticSearch plugin that is able query the data.
One error that I am still getting when I run “yarn dev” is below:
Bundling plugin in dev mode ERROR in /var/lib/grafana/plugins/facsource/src/ConfigEditor.tsx(35,9):
TS2322: Type ‘(options: DataSourceSettings<ElasticsearchOptions, {}>) => void’ is not assignable to type ‘(config: DataSourceSettings<DataSourceJsonData, {}>) => void’.
Types of parameters ‘options’ and ‘config’ are incompatible.
Type ‘DataSourceSettings<DataSourceJsonData, {}>’ is not assignable to type ‘DataSourceSettings<ElasticsearchOptions, {}>’.
Type ‘DataSourceJsonData’ is missing the following properties from type ‘ElasticsearchOptions’: timeField, esVersion, timeInterval
Here is the ConfigEditor that I am using.
export type Props = DataSourcePluginOptionsEditorProps<ElasticsearchOptions>;
export const ConfigEditor = (props: Props) => {
const { options, onOptionsChange } = props;
// Apply some defaults on initial render
useEffect(() => {
const esVersion = options.jsonData.esVersion || 5;
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
timeField: options.jsonData.timeField || '@timestamp',
esVersion,
maxConcurrentShardRequests:
options.jsonData.maxConcurrentShardRequests || defaultMaxConcurrentShardRequests(esVersion),
logMessageField: options.jsonData.logMessageField || '',
logLevelField: options.jsonData.logLevelField || '',
},
});
}, []);
return (
<>
<DataSourceHttpSettings
defaultUrl={'http://localhost:9200'}
dataSourceConfig={options}
showAccessOptions={true}
onChange={onOptionsChange}
/>
<ElasticDetails value={options} onChange={onOptionsChange} />
<LogsConfig
value={options.jsonData}
onChange={newValue =>
onOptionsChange({
...options,
jsonData: newValue,
})
}
/>
</>
);
};
And this is the type definition.
export interface ElasticsearchOptions extends DataSourceJsonData {
timeField: string;
esVersion: number;
interval?: string;
timeInterval: string;
maxConcurrentShardRequests?: number;
logMessageField?: string;
logLevelField?: string;
dataLinks?: DataLinkConfig[];
}
Please let me know if I need to provide more information. I am fairly new to javascript, so this error is quire foreign to me.