2020-03-10 12:20:38 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-09-02 03:16:17 -05:00
|
|
|
import { Alert, DataSourceHttpSettings, InlineFormLabel, LegacyForms } from '@grafana/ui';
|
2020-04-07 01:50:54 -05:00
|
|
|
const { Select, Switch } = LegacyForms;
|
2020-03-18 07:00:14 -05:00
|
|
|
import {
|
|
|
|
DataSourcePluginOptionsEditorProps,
|
2021-03-16 04:59:53 -05:00
|
|
|
updateDatasourcePluginJsonDataOption,
|
2020-03-18 07:00:14 -05:00
|
|
|
onUpdateDatasourceJsonDataOptionSelect,
|
|
|
|
onUpdateDatasourceJsonDataOptionChecked,
|
|
|
|
} from '@grafana/data';
|
2020-03-10 12:20:38 -05:00
|
|
|
import { GraphiteOptions, GraphiteType } from '../types';
|
2021-03-16 04:59:53 -05:00
|
|
|
import { DEFAULT_GRAPHITE_VERSION, GRAPHITE_VERSIONS } from '../versions';
|
2021-05-06 02:26:26 -05:00
|
|
|
import { MappingsConfiguration } from './MappingsConfiguration';
|
|
|
|
import { fromString, toString } from './parseLokiLabelMappings';
|
|
|
|
import store from 'app/core/store';
|
|
|
|
|
|
|
|
export const SHOW_MAPPINGS_HELP_KEY = 'grafana.datasources.graphite.config.showMappingsHelp';
|
2020-03-10 12:20:38 -05:00
|
|
|
|
2021-03-16 04:59:53 -05:00
|
|
|
const graphiteVersions = GRAPHITE_VERSIONS.map((version) => ({ label: `${version}.x`, value: version }));
|
2020-03-10 12:20:38 -05:00
|
|
|
|
|
|
|
const graphiteTypes = Object.entries(GraphiteType).map(([label, value]) => ({
|
|
|
|
label,
|
|
|
|
value,
|
|
|
|
}));
|
|
|
|
|
|
|
|
export type Props = DataSourcePluginOptionsEditorProps<GraphiteOptions>;
|
|
|
|
|
2021-05-06 02:26:26 -05:00
|
|
|
type State = {
|
|
|
|
showMappingsHelp: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class ConfigEditor extends PureComponent<Props, State> {
|
2020-03-10 12:20:38 -05:00
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
2021-05-06 02:26:26 -05:00
|
|
|
this.state = {
|
|
|
|
showMappingsHelp: store.getObject(SHOW_MAPPINGS_HELP_KEY, true),
|
|
|
|
};
|
2020-03-10 12:20:38 -05:00
|
|
|
}
|
|
|
|
|
2020-03-18 07:00:14 -05:00
|
|
|
renderTypeHelp = () => {
|
|
|
|
return (
|
|
|
|
<p>
|
|
|
|
There are different types of Graphite compatible backends. Here you can specify the type you are using. If you
|
|
|
|
are using{' '}
|
2020-11-18 08:36:35 -06:00
|
|
|
<a href="https://github.com/grafana/metrictank" className="pointer" target="_blank" rel="noreferrer">
|
2020-03-18 07:00:14 -05:00
|
|
|
Metrictank
|
|
|
|
</a>{' '}
|
|
|
|
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.
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-03-16 04:59:53 -05:00
|
|
|
componentDidMount() {
|
|
|
|
updateDatasourcePluginJsonDataOption(this.props, 'graphiteVersion', this.currentGraphiteVersion);
|
|
|
|
}
|
|
|
|
|
2020-03-10 12:20:38 -05:00
|
|
|
render() {
|
|
|
|
const { options, onOptionsChange } = this.props;
|
|
|
|
|
2021-03-16 04:59:53 -05:00
|
|
|
const currentVersion = graphiteVersions.find((item) => item.value === this.currentGraphiteVersion);
|
2020-03-10 12:20:38 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-09-02 03:16:17 -05:00
|
|
|
{options.access === 'direct' && (
|
|
|
|
<Alert title="Deprecation Notice" severity="warning">
|
|
|
|
This data source uses browser access mode. This mode is deprecated and will be removed in the future. Please
|
|
|
|
use server access mode instead.
|
|
|
|
</Alert>
|
|
|
|
)}
|
2020-03-10 12:20:38 -05:00
|
|
|
<DataSourceHttpSettings
|
|
|
|
defaultUrl="http://localhost:8080"
|
|
|
|
dataSourceConfig={options}
|
|
|
|
onChange={onOptionsChange}
|
|
|
|
/>
|
|
|
|
<h3 className="page-heading">Graphite details</h3>
|
|
|
|
<div className="gf-form-group">
|
|
|
|
<div className="gf-form-inline">
|
|
|
|
<div className="gf-form">
|
2020-04-21 04:42:21 -05:00
|
|
|
<InlineFormLabel tooltip="This option controls what functions are available in the Graphite query editor.">
|
2020-03-10 12:20:38 -05:00
|
|
|
Version
|
2020-04-21 04:42:21 -05:00
|
|
|
</InlineFormLabel>
|
2020-03-10 12:20:38 -05:00
|
|
|
<Select
|
2021-08-04 09:47:53 -05:00
|
|
|
menuShouldPortal
|
2020-03-10 12:20:38 -05:00
|
|
|
value={currentVersion}
|
|
|
|
options={graphiteVersions}
|
|
|
|
width={8}
|
|
|
|
onChange={onUpdateDatasourceJsonDataOptionSelect(this.props, 'graphiteVersion')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="gf-form-inline">
|
|
|
|
<div className="gf-form">
|
2020-04-21 04:42:21 -05:00
|
|
|
<InlineFormLabel tooltip={this.renderTypeHelp}>Type</InlineFormLabel>
|
2020-03-10 12:20:38 -05:00
|
|
|
<Select
|
2021-08-04 09:47:53 -05:00
|
|
|
menuShouldPortal
|
2020-03-10 12:20:38 -05:00
|
|
|
options={graphiteTypes}
|
2021-01-20 00:59:48 -06:00
|
|
|
value={graphiteTypes.find((type) => type.value === options.jsonData.graphiteType)}
|
2020-03-10 12:20:38 -05:00
|
|
|
width={8}
|
|
|
|
onChange={onUpdateDatasourceJsonDataOptionSelect(this.props, 'graphiteType')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-03-18 07:00:14 -05:00
|
|
|
{options.jsonData.graphiteType === GraphiteType.Metrictank && (
|
|
|
|
<div className="gf-form-inline">
|
|
|
|
<div className="gf-form">
|
|
|
|
<Switch
|
|
|
|
label="Rollup indicator"
|
|
|
|
labelClass={'width-10'}
|
|
|
|
tooltip="Shows up as an info icon in panel headers when data is aggregated"
|
2020-07-01 04:40:37 -05:00
|
|
|
checked={!!options.jsonData.rollupIndicatorEnabled}
|
2020-03-18 07:00:14 -05:00
|
|
|
onChange={onUpdateDatasourceJsonDataOptionChecked(this.props, 'rollupIndicatorEnabled')}
|
|
|
|
/>
|
2020-03-10 12:20:38 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-05-06 02:26:26 -05:00
|
|
|
<MappingsConfiguration
|
|
|
|
mappings={(options.jsonData.importConfiguration?.loki?.mappings || []).map(toString)}
|
|
|
|
showHelp={this.state.showMappingsHelp}
|
|
|
|
onDismiss={() => {
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
2020-03-10 12:20:38 -05:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-03-16 04:59:53 -05:00
|
|
|
|
|
|
|
private get currentGraphiteVersion() {
|
|
|
|
return this.props.options.jsonData.graphiteVersion || DEFAULT_GRAPHITE_VERSION;
|
|
|
|
}
|
2020-03-10 12:20:38 -05:00
|
|
|
}
|