2019-10-25 09:43:20 -05:00
|
|
|
import React from 'react';
|
2019-10-31 04:48:05 -05:00
|
|
|
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
|
|
|
|
import { FormField, DataSourceHttpSettings } from '@grafana/ui';
|
2019-10-25 09:43:20 -05:00
|
|
|
import { LokiOptions } from '../types';
|
|
|
|
|
|
|
|
export type Props = DataSourcePluginOptionsEditorProps<LokiOptions>;
|
|
|
|
|
|
|
|
const makeJsonUpdater = <T extends any>(field: keyof LokiOptions) => (
|
|
|
|
options: DataSourceSettings<LokiOptions>,
|
|
|
|
value: T
|
|
|
|
): DataSourceSettings<LokiOptions> => {
|
|
|
|
return {
|
|
|
|
...options,
|
|
|
|
jsonData: {
|
|
|
|
...options.jsonData,
|
|
|
|
[field]: value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const setMaxLines = makeJsonUpdater('maxLines');
|
|
|
|
|
|
|
|
export const ConfigEditor = (props: Props) => {
|
|
|
|
const { options, onOptionsChange } = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DataSourceHttpSettings
|
|
|
|
defaultUrl={'http://localhost:3100'}
|
|
|
|
dataSourceConfig={options}
|
|
|
|
showAccessOptions={false}
|
|
|
|
onChange={onOptionsChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="gf-form-group">
|
|
|
|
<div className="gf-form-inline">
|
|
|
|
<div className="gf-form">
|
|
|
|
<MaxLinesField
|
|
|
|
value={options.jsonData.maxLines}
|
|
|
|
onChange={value => onOptionsChange(setMaxLines(options, value))}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
type MaxLinesFieldProps = {
|
|
|
|
value: string;
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const MaxLinesField = (props: MaxLinesFieldProps) => {
|
|
|
|
const { value, onChange } = props;
|
|
|
|
return (
|
|
|
|
<FormField
|
|
|
|
label="Maximum lines"
|
|
|
|
labelWidth={11}
|
|
|
|
inputWidth={20}
|
|
|
|
inputEl={
|
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
className="gf-form-input width-8 gf-form-input--has-help-icon"
|
|
|
|
value={value}
|
|
|
|
onChange={event => onChange(event.currentTarget.value)}
|
|
|
|
spellCheck={false}
|
|
|
|
placeholder="1000"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
tooltip={
|
|
|
|
<>
|
|
|
|
Loki queries must contain a limit of the maximum number of lines returned (default: 1000). Increase this limit
|
|
|
|
to have a bigger result set for ad-hoc analysis. Decrease this limit if your browser becomes sluggish when
|
|
|
|
displaying the log results.
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|