import React, { PureComponent } from 'react'; import { DataSourcePluginOptionsEditorProps, updateDatasourcePluginJsonDataOption, onUpdateDatasourceJsonDataOptionSelect, onUpdateDatasourceJsonDataOptionChecked, } from '@grafana/data'; import { Alert, DataSourceHttpSettings, InlineFormLabel, LegacyForms } from '@grafana/ui'; import store from 'app/core/store'; import { GraphiteOptions, GraphiteType } from '../types'; import { DEFAULT_GRAPHITE_VERSION, GRAPHITE_VERSIONS } from '../versions'; import { MappingsConfiguration } from './MappingsConfiguration'; import { fromString, toString } from './parseLokiLabelMappings'; const { Select, Switch } = LegacyForms; export const SHOW_MAPPINGS_HELP_KEY = 'grafana.datasources.graphite.config.showMappingsHelp'; const graphiteVersions = GRAPHITE_VERSIONS.map((version) => ({ label: `${version}.x`, value: version })); const graphiteTypes = Object.entries(GraphiteType).map(([label, value]) => ({ label, value, })); export type Props = DataSourcePluginOptionsEditorProps; type State = { showMappingsHelp: boolean; }; export class ConfigEditor extends PureComponent { constructor(props: Props) { super(props); this.state = { showMappingsHelp: store.getObject(SHOW_MAPPINGS_HELP_KEY, true), }; } renderTypeHelp = () => { return (

There are different types of Graphite compatible backends. Here you can specify the type you are using. If you are using{' '} Metrictank {' '} then select that here. This will enable Metrictank specific features like query processing meta data. Metrictank is a multi-tenant timeseries engine for Graphite and friends.

); }; componentDidMount() { updateDatasourcePluginJsonDataOption(this.props, 'graphiteVersion', this.currentGraphiteVersion); } render() { const { options, onOptionsChange } = this.props; const currentVersion = graphiteVersions.find((item) => item.value === this.currentGraphiteVersion); return ( <> {options.access === 'direct' && ( This data source uses browser access mode. This mode is deprecated and will be removed in the future. Please use server access mode instead. )}

Graphite details

Version type.value === options.jsonData.graphiteType)} width={8} onChange={onUpdateDatasourceJsonDataOptionSelect(this.props, 'graphiteType')} />
{options.jsonData.graphiteType === GraphiteType.Metrictank && (
)}
{ this.setState({ showMappingsHelp: false }); store.setObject(SHOW_MAPPINGS_HELP_KEY, false); }} onRestoreHelp={() => { this.setState({ showMappingsHelp: true }); store.setObject(SHOW_MAPPINGS_HELP_KEY, true); }} onChange={(mappings) => { onOptionsChange({ ...options, jsonData: { ...options.jsonData, importConfiguration: { ...options.jsonData.importConfiguration, loki: { mappings: mappings.map(fromString), }, }, }, }); }} /> ); } private get currentGraphiteVersion() { return this.props.options.jsonData.graphiteVersion || DEFAULT_GRAPHITE_VERSION; } }