Build plugin with grafana toolkit (#1539)

* Use grafana toolkit template for building plugin

* Fix linter and type errors

* Update styles building

* Fix sass deprecation warning

* Remove empty js files produced by webpack building sass

* Fix signing script

* Replace classnames with cx

* Fix data source config page

* Use custom webpack config instead of overriding original one

* Use gpx_ prefix for plugin executable

* Remove unused configs

* Roll back react hooks dependencies usage

* Move plugin-specific ts config to root config file

* Temporary do not use rst2html for function description tooltip

* Remove unused code

* remove unused dependencies

* update react table dependency

* Migrate tests to typescript

* remove unused dependencies

* Remove old webpack configs

* Add sign target to makefile

* Add magefile

* Update CI test job

* Update go packages

* Update build instructions

* Downgrade go version to 1.18

* Fix go version in ci

* Fix metric picker

* Add comment to webpack config

* remove angular mocks

* update bra config

* Rename datasource-zabbix to datasource (fix mage build)

* Add instructions for building backend with mage

* Fix webpack targets

* Fix ci backend tests

* Add initial e2e tests

* Fix e2e ci tests

* Update docker compose for cypress tests

* build grafana docker image

* Fix docker stop task

* CI: add Grafana compatibility check
This commit is contained in:
Alexander Zobnin
2022-12-09 14:14:34 +03:00
committed by GitHub
parent 26ed740945
commit e3e896742b
136 changed files with 5765 additions and 4636 deletions

View File

@@ -0,0 +1,208 @@
import React, { useEffect } from 'react';
import { QueryEditorProps, SelectableValue } from '@grafana/data';
import { InlineField, InlineFieldRow, Select } from '@grafana/ui';
import * as c from '../constants';
import * as migrations from '../migrations';
import { ZabbixDatasource } from '../datasource';
import { ShowProblemTypes, ZabbixDSOptions, ZabbixMetricsQuery, ZabbixQueryOptions } from '../types';
import { MetricsQueryEditor } from './QueryEditor/MetricsQueryEditor';
import { QueryFunctionsEditor } from './QueryEditor/QueryFunctionsEditor';
import { QueryOptionsEditor } from './QueryEditor/QueryOptionsEditor';
import { TextMetricsQueryEditor } from './QueryEditor/TextMetricsQueryEditor';
import { ProblemsQueryEditor } from './QueryEditor/ProblemsQueryEditor';
import { ItemIdQueryEditor } from './QueryEditor/ItemIdQueryEditor';
import { ITServicesQueryEditor } from './QueryEditor/ITServicesQueryEditor';
import { TriggersQueryEditor } from './QueryEditor/TriggersQueryEditor';
const zabbixQueryTypeOptions: Array<SelectableValue<string>> = [
{
value: c.MODE_METRICS,
label: 'Metrics',
description: 'Query numeric metrics',
},
{
value: c.MODE_TEXT,
label: 'Text',
description: 'Query text data',
},
{
value: c.MODE_ITSERVICE,
label: 'IT Services',
description: 'Query IT Services data',
},
{
value: c.MODE_ITEMID,
label: 'Item Id',
description: 'Query metrics by item ids',
},
{
value: c.MODE_TRIGGERS,
label: 'Triggers',
description: 'Query triggers data',
},
{
value: c.MODE_PROBLEMS,
label: 'Problems',
description: 'Query problems',
},
];
const getDefaultQuery: () => Partial<ZabbixMetricsQuery> = () => ({
queryType: c.MODE_METRICS,
group: { filter: '' },
host: { filter: '' },
application: { filter: '' },
itemTag: { filter: '' },
item: { filter: '' },
functions: [],
triggers: {
count: true,
minSeverity: 3,
acknowledged: 2,
},
trigger: { filter: '' },
tags: { filter: '' },
proxy: { filter: '' },
textFilter: '',
options: {
showDisabledItems: false,
skipEmptyValues: false,
disableDataAlignment: false,
useZabbixValueMapping: false,
},
table: {
skipEmptyValues: false,
},
});
function getSLAQueryDefaults() {
return {
itServiceFilter: '',
slaProperty: 'sla',
slaInterval: 'none',
};
}
function getProblemsQueryDefaults(): Partial<ZabbixMetricsQuery> {
return {
showProblems: ShowProblemTypes.Problems,
options: {
minSeverity: 0,
sortProblems: 'default',
acknowledged: 2,
hostsInMaintenance: false,
hostProxy: false,
limit: c.DEFAULT_ZABBIX_PROBLEMS_LIMIT,
useTimeRange: false,
},
};
}
export interface ZabbixQueryEditorProps
extends QueryEditorProps<ZabbixDatasource, ZabbixMetricsQuery, ZabbixDSOptions> {}
export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: ZabbixQueryEditorProps) => {
query = { ...getDefaultQuery(), ...query };
const { queryType } = query;
if (queryType === c.MODE_PROBLEMS || queryType === c.MODE_TRIGGERS) {
const defaults = getProblemsQueryDefaults();
query = { ...defaults, ...query };
query.options = { ...defaults.options, ...query.options };
}
if (queryType === c.MODE_ITSERVICE) {
query = { ...getSLAQueryDefaults(), ...query };
}
// Migrate query on load
useEffect(() => {
const migratedQuery = migrations.migrate(query);
onChange(migratedQuery);
}, []);
const onPropChange = (prop: string) => {
return (option: SelectableValue) => {
if (option.value !== null) {
onChangeInternal({ ...query, [prop]: option.value });
}
};
};
const onChangeInternal = (query: ZabbixMetricsQuery) => {
onChange(query);
onRunQuery();
};
const onOptionsChange = (options: ZabbixQueryOptions) => {
onChangeInternal({ ...query, options });
};
const renderMetricsEditor = () => {
return (
<>
<MetricsQueryEditor query={query} datasource={datasource} onChange={onChangeInternal} />
<QueryFunctionsEditor query={query} onChange={onChangeInternal} />
</>
);
};
const renderItemIdsEditor = () => {
return (
<>
<ItemIdQueryEditor query={query} onChange={onChangeInternal} />
<QueryFunctionsEditor query={query} onChange={onChangeInternal} />
</>
);
};
const renderTextMetricsEditor = () => {
return (
<>
<TextMetricsQueryEditor query={query} datasource={datasource} onChange={onChangeInternal} />
{/* <QueryFunctionsEditor query={query} onChange={onChangeInternal} /> */}
</>
);
};
const renderITServicesEditor = () => {
return (
<>
<ITServicesQueryEditor query={query} datasource={datasource} onChange={onChangeInternal} />
<QueryFunctionsEditor query={query} onChange={onChangeInternal} />
</>
);
};
const renderProblemsEditor = () => {
return <ProblemsQueryEditor query={query} datasource={datasource} onChange={onChangeInternal} />;
};
const renderTriggersEditor = () => {
return <TriggersQueryEditor query={query} datasource={datasource} onChange={onChangeInternal} />;
};
return (
<>
<InlineFieldRow>
<InlineField label="Query type" labelWidth={12}>
<Select
isSearchable={false}
width={24}
value={queryType}
options={zabbixQueryTypeOptions}
onChange={onPropChange('queryType')}
/>
</InlineField>
<div className="gf-form gf-form--grow">
<div className="gf-form-label gf-form-label--grow" />
</div>
</InlineFieldRow>
{queryType === c.MODE_METRICS && renderMetricsEditor()}
{queryType === c.MODE_ITEMID && renderItemIdsEditor()}
{queryType === c.MODE_TEXT && renderTextMetricsEditor()}
{queryType === c.MODE_ITSERVICE && renderITServicesEditor()}
{queryType === c.MODE_PROBLEMS && renderProblemsEditor()}
{queryType === c.MODE_TRIGGERS && renderTriggersEditor()}
<QueryOptionsEditor queryType={queryType} queryOptions={query.options} onChange={onOptionsChange} />
</>
);
};