Skip to content

Commit

Permalink
[Backend] Merge 'master' changes into the backend (#875)
Browse files Browse the repository at this point in the history
* CI: fix shellcheck issues (#789)

Signed-off-by: Mario Trangoni <[email protected]>

* annotations: fix options in grafana 6.x, fix #813

* fix function editor in Grafana 6.4, closes #810

* add typings for grafana packages

* Add $__range_series variable for calculating function over the whole series, #531

* fix tests

* Don't set alert styles for react panels, fix #823

* docs: add range variables

* docs: percentile reference

* fix codespell

* update packages (build with node 12)

* update circleci node image to 12

* fix test configuration (babel)

* Fix 817 (#851)

* problems: update panel schema

* update packages (build with node 12)

* problems: use datasource from target

* problems: fix query editor after schema update

* problems: fix list layout

* update circleci node image to 12

* fix tests

* build(deps-dev): bump lodash from 4.17.10 to 4.17.13 (#852)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.10 to 4.17.13.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.10...4.17.13)

Signed-off-by: dependabot[bot] <[email protected]>

* fix packages security alerts

* problems: fix tags adding and removal

* fix adding func from typeahead, closes #468

* update change log

* bump plugin version to 3.10.5

* problems: fix tag removal (list layout)

* Fix percentile() function, closes #862 (#863)

Like the other aggregation functions, the datapoints need to be sorted in
time before calling groupBy_perf().

* Update copyright, happy New Year!

* fix not acknowledged problem color with a message (#858)

* fix not acknowledged problem color with a message

* fix not acknowledged problem color with a message, closes #857

* Variable query editor (#856)

* refactor: convert module to typescript

* refactor: covert utils to typescript

* variable query editor WIP

* variable editor: fix type error after grafana/ui update

* variable editor: use FormLabel from grafana/ui

* variable editor: refactor

* variable editor: input validation and highlights

* variable editor: fix tests

* variable query: fix backward compatibility with empty queries

* fix linter errors

* variable editor: fix variable replacement in queries

* Fixes for backend

Co-authored-by: Mario Trangoni <[email protected]>
Co-authored-by: Alexander Zobnin <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mark Reibert <[email protected]>
Co-authored-by: memfiz <[email protected]>
  • Loading branch information
6 people committed Jan 15, 2020
1 parent fcfb237 commit 92e7761
Show file tree
Hide file tree
Showing 30 changed files with 2,999 additions and 3,346 deletions.
2 changes: 1 addition & 1 deletion .circleci/make-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi
RELEASE_BRANCH=release-$RELEASE_VER

# Build plugin
git checkout -b $RELEASE_BRANCH
git checkout -b "$RELEASE_BRANCH"
make clean install dist

# Commit release
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

## [3.10.5] - 2019-12-26
### Added
- SLA over time graphs, [#728](https://github.com/alexanderzobnin/grafana-zabbix/issues/728)
- Additional time ranges in functions, [#531](https://github.com/alexanderzobnin/grafana-zabbix/issues/531)

### Fixed
- Problems panel: query editor broken in Grafana 6.4, [#817](https://github.com/alexanderzobnin/grafana-zabbix/issues/817)
- Datasource: function editor is not working, [#810](https://github.com/alexanderzobnin/grafana-zabbix/issues/810)
- Datasource: cannot add a function to query from typeahead, [#468](https://github.com/alexanderzobnin/grafana-zabbix/issues/468)
- Datasource: annotations editor broken in Grafana 6.x, [#813](https://github.com/alexanderzobnin/grafana-zabbix/issues/813)
- React plugins issue, [#823](https://github.com/alexanderzobnin/grafana-zabbix/issues/823)

## [3.10.4] - 2019-08-08
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ First, [configure](https://alexanderzobnin.github.io/grafana-zabbix/configuratio
- Need additional support? Contact me for details [[email protected]](mailto:[email protected])

---
:copyright: 2015-2019 Alexander Zobnin [email protected]
:copyright: 2015-2020 Alexander Zobnin [email protected]

Licensed under the Apache 2.0 License
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
"presets": [
[ "@babel/env", { targets: { node: 'current' } } ],
[ "@babel/preset-env", { "targets": { "node": "current" } } ],
"@babel/react"
],
"retainLines": true
}
};
52 changes: 31 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "grafana-zabbix",
"private": false,
"version": "3.10.4",
"version": "3.10.5",
"description": "Zabbix plugin for Grafana",
"homepage": "http://grafana-zabbix.org",
"scripts": {
"build": "webpack --config webpack/webpack.prod.conf.js --progress --colors",
"dev": "webpack --config webpack/webpack.dev.conf.js --watch --progress --colors",
Expand All @@ -25,21 +26,23 @@
"url": "https://github.com/alexanderzobnin/grafana-zabbix/issues"
},
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/preset-react": "^7.6.3",
"@grafana/data": "^6.4.3",
"@grafana/runtime": "^6.4.3",
"@grafana/toolkit": "^6.4.3",
"@grafana/ui": "^6.4.3",
"@babel/core": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@babel/preset-react": "^7.8.3",
"@emotion/core": "^10.0.27",
"@grafana/data": "canary",
"@grafana/runtime": "canary",
"@grafana/toolkit": "canary",
"@grafana/ui": "canary",
"@types/classnames": "^2.2.9",
"@types/grafana": "github:CorpGlory/types-grafana",
"@types/jest": "^23.1.1",
"@types/jquery": "^3.3.0",
"@types/lodash": "^4.14.104",
"@types/moment": "^2.13.0",
"@types/react": "^16.4.6",
"@types/react-dom": "^16.0.11",
"@types/react": "^16.9.17",
"@types/react-table": "^6.8.6",
"@types/react-dom": "^16.9.4",
"@types/react-transition-group": "^2.0.15",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
Expand All @@ -49,24 +52,24 @@
"classnames": "^2.2.6",
"clean-webpack-plugin": "^0.1.19",
"codecov": "^3.1.0",
"copy-webpack-plugin": "^4.5.4",
"css-loader": "^1.0.0",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "2.1.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"grunt": "^1.0.3",
"grunt-benchmark": "^1.0.0",
"grunt-cli": "^1.3.1",
"grunt-execute": "^0.2.2",
"html-loader": "^0.5.5",
"jest": "^23.6.0",
"jest": "^24.9.0",
"jscs": "^3.0.7",
"jsdom": "~11.3.0",
"jshint": "^2.9.6",
"jshint-stylish": "^2.1.0",
"load-grunt-tasks": "~3.2.0",
"lodash": "~4.17.5",
"lodash": "~4.17.13",
"moment": "~2.21.0",
"ng-annotate-webpack-plugin": "^0.3.0",
"node-sass": "^4.9.4",
"node-sass": "^4.13.0",
"prop-types": "^15.6.2",
"react": "^16.7.0",
"react-dom": "^16.7.0",
Expand All @@ -78,12 +81,19 @@
"sass-loader": "^8.0.0",
"style-loader": "^0.23.1",
"tether-drop": "^1.4.2",
"ts-jest": "^23.10.5",
"ts-jest": "^24.2.0",
"ts-loader": "^6.2.0",
"tslint": "^5.11.0",
"typescript": "^3.6.4",
"webpack": "^4.22.0",
"webpack-cli": "^3.1.2"
"tslint": "5.20.1",
"typescript": "3.7.2",
"webpack": "4.29.6",
"webpack-cli": "3.2.3"
},
"homepage": "http://grafana-zabbix.org"
"resolutions": {
"js-yaml": "^3.13.1",
"lodash": "~4.17.13",
"set-value": "^2.0.1",
"mixin-deep": "^1.3.2",
"minimatch": "^3.0.2",
"fstream": "^1.0.12"
}
}
2 changes: 1 addition & 1 deletion src/datasource-zabbix/add-metric-function.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ angular
}

$scope.$apply(function() {
$scope.addFunction(funcDef);
$scope.ctrl.addFunction(funcDef);
});

$input.trigger('blur');
Expand Down
157 changes: 157 additions & 0 deletions src/datasource-zabbix/components/VariableQueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import React, { PureComponent } from 'react';
import { parseLegacyVariableQuery } from '../utils';
import { Select, Input, AsyncSelect, FormLabel } from '@grafana/ui';
import { SelectableValue } from '@grafana/data';
import { VariableQuery, VariableQueryTypes, VariableQueryProps, VariableQueryData } from '../types';
import { ZabbixInput } from './ZabbixInput';

export class ZabbixVariableQueryEditor extends PureComponent<VariableQueryProps, VariableQueryData> {
queryTypes: Array<SelectableValue<VariableQueryTypes>> = [
{ value: VariableQueryTypes.Group, label: 'Group'},
{ value: VariableQueryTypes.Host, label: 'Host' },
{ value: VariableQueryTypes.Application, label: 'Application' },
{ value: VariableQueryTypes.Item, label: 'Item' },
];

defaults: VariableQueryData = {
selectedQueryType: { value: VariableQueryTypes.Group, label: 'Group' },
queryType: VariableQueryTypes.Group,
group: '/.*/',
host: '',
application: '',
item: '',
};

constructor(props: VariableQueryProps) {
super(props);

if (this.props.query && typeof this.props.query === 'string') {
// Backward compatibility
const query = parseLegacyVariableQuery(this.props.query);
const selectedQueryType = this.getSelectedQueryType(query.queryType);
this.state = {
selectedQueryType,
legacyQuery: this.props.query,
...query
};
} else if (this.props.query) {
const query = (this.props.query as VariableQuery);
const selectedQueryType = this.getSelectedQueryType(query.queryType);
this.state = {
...this.defaults,
...query,
selectedQueryType,
};
} else {
this.state = this.defaults;
}
}

getSelectedQueryType(queryType: VariableQueryTypes) {
return this.queryTypes.find(q => q.value === queryType);
}

handleQueryUpdate = (evt: React.ChangeEvent<HTMLInputElement>, prop: string) => {
const value = evt.currentTarget.value;
this.setState((prevState: VariableQueryData) => {
const newQuery = {
...prevState,
};
newQuery[prop] = value;

return {
...newQuery,
};
});
}

handleQueryChange = () => {
const { queryType, group, host, application, item } = this.state;
const queryModel = { queryType, group, host, application, item };
this.props.onChange(queryModel, `Zabbix - ${queryType}`);
}

handleQueryTypeChange = (selectedItem: SelectableValue<VariableQueryTypes>) => {
this.setState({
...this.state,
selectedQueryType: selectedItem,
queryType: selectedItem.value,
});

const { group, host, application, item } = this.state;
const queryType = selectedItem.value;
const queryModel = { queryType, group, host, application, item };
this.props.onChange(queryModel, `Zabbix - ${queryType}`);
}

render() {
const { selectedQueryType, legacyQuery, group, host, application, item } = this.state;

return (
<>
<div className="gf-form max-width-21">
<FormLabel width={10}>Query Type</FormLabel>
<Select
width={11}
value={selectedQueryType}
options={this.queryTypes}
onChange={this.handleQueryTypeChange}
/>
</div>
<div className="gf-form-inline">
<div className="gf-form max-width-30">
<FormLabel width={10}>Group</FormLabel>
<ZabbixInput
value={group}
onChange={evt => this.handleQueryUpdate(evt, 'group')}
onBlur={this.handleQueryChange}
/>
</div>
{selectedQueryType.value !== VariableQueryTypes.Group &&
<div className="gf-form max-width-30">
<FormLabel width={10}>Host</FormLabel>
<ZabbixInput
value={host}
onChange={evt => this.handleQueryUpdate(evt, 'host')}
onBlur={this.handleQueryChange}
/>
</div>
}
</div>
{(selectedQueryType.value === VariableQueryTypes.Application ||
selectedQueryType.value === VariableQueryTypes.Item) &&
<div className="gf-form-inline">
<div className="gf-form max-width-30">
<FormLabel width={10}>Application</FormLabel>
<ZabbixInput
value={application}
onChange={evt => this.handleQueryUpdate(evt, 'application')}
onBlur={this.handleQueryChange}
/>
</div>
{selectedQueryType.value === VariableQueryTypes.Item &&
<div className="gf-form max-width-30">
<FormLabel width={10}>Item</FormLabel>
<ZabbixInput
value={item}
onChange={evt => this.handleQueryUpdate(evt, 'item')}
onBlur={this.handleQueryChange}
/>
</div>
}
</div>
}

{legacyQuery &&
<div className="gf-form">
<FormLabel width={10} tooltip="Original query string, read-only">Legacy Query</FormLabel>
<Input
value={legacyQuery}
readOnly={true}
/>
</div>
}
</>
);
}
}
70 changes: 70 additions & 0 deletions src/datasource-zabbix/components/ZabbixInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { FC } from 'react';
import { css, cx } from 'emotion';
import { Themeable, withTheme, Input, EventsWithValidation, ValidationEvents } from '@grafana/ui';
import { GrafanaTheme } from '@grafana/data';
import { isRegex, variableRegex } from '../utils';

const variablePattern = RegExp(`^${variableRegex.source}`);

const getStyles = (theme: GrafanaTheme) => ({
inputRegex: css`
color: ${theme.colors.orange}
`,
inputVariable: css`
color: ${theme.colors.variable}
`,
});

const zabbixInputValidationEvents: ValidationEvents = {
[EventsWithValidation.onBlur]: [
{
rule: value => {
if (!value) {
return true;
}
if (value.length > 1 && value[0] === '/') {
if (value[value.length - 1] !== '/') {
return false;
}
}
return true;
},
errorMessage: 'Not a valid regex',
},
{
rule: value => {
if (value === '*') {
return false;
}
return true;
},
errorMessage: 'Wildcards not supported. Use /.*/ instead',
},
],
};

interface Props extends React.ComponentProps<typeof Input>, Themeable {
}

const UnthemedZabbixInput: FC<Props> = ({ theme, value, ref, validationEvents, ...restProps }) => {
const styles = getStyles(theme);

let inputClass;
if (variablePattern.test(value as string)) {
inputClass = styles.inputVariable;
}
if (isRegex(value)) {
inputClass = styles.inputRegex;
}

return (
<Input
className={inputClass}
value={value}
validationEvents={zabbixInputValidationEvents}
{...restProps}
/>
);
};

export const ZabbixInput = withTheme(UnthemedZabbixInput);
8 changes: 5 additions & 3 deletions src/datasource-zabbix/dataProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ function aggregateWrapper(groupByCallback, interval, datapoints) {
}

function percentile(interval, n, datapoints) {
var flattenedPoints = ts.flattenDatapoints(datapoints);
var groupByCallback = _.partial(PERCENTILE, n);
return groupBy(flattenedPoints, interval, groupByCallback);
const flattenedPoints = ts.flattenDatapoints(datapoints);
// groupBy_perf works with sorted series only
const sortedPoints = ts.sortByTime(flattenedPoints);
let groupByCallback = _.partial(PERCENTILE, n);
return groupBy(sortedPoints, interval, groupByCallback);
}

function timeShift(interval, range) {
Expand Down
Loading

0 comments on commit 92e7761

Please sign in to comment.