Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Merge 'master' changes into the backend #875

Merged
merged 28 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fe943ac
CI: fix shellcheck issues (#789)
mjtrangoni Oct 4, 2019
9cf1323
annotations: fix options in grafana 6.x, fix #813
alexanderzobnin Oct 8, 2019
a652eaf
fix function editor in Grafana 6.4, closes #810
alexanderzobnin Oct 9, 2019
ca50d0d
add typings for grafana packages
alexanderzobnin Oct 9, 2019
1827aa9
Add $__range_series variable for calculating function over the whole …
alexanderzobnin Oct 9, 2019
1d13520
fix tests
alexanderzobnin Oct 9, 2019
42d93b4
Don't set alert styles for react panels, fix #823
alexanderzobnin Oct 28, 2019
51d423e
docs: add range variables
alexanderzobnin Oct 28, 2019
bc1453e
docs: percentile reference
alexanderzobnin Oct 28, 2019
bcbbc97
fix codespell
alexanderzobnin Oct 28, 2019
5afeda6
Range-related variables #814
alexanderzobnin Oct 28, 2019
d09830f
update packages (build with node 12)
alexanderzobnin Dec 13, 2019
cf9780c
update circleci node image to 12
alexanderzobnin Dec 25, 2019
c1db914
fix test configuration (babel)
alexanderzobnin Dec 25, 2019
ff4ad19
Fix 817 (#851)
alexanderzobnin Dec 25, 2019
68aa093
build(deps-dev): bump lodash from 4.17.10 to 4.17.13 (#852)
dependabot[bot] Dec 26, 2019
4fcef29
fix packages security alerts
alexanderzobnin Dec 26, 2019
1e6ca2d
problems: fix tags adding and removal
alexanderzobnin Dec 26, 2019
90a9115
fix adding func from typeahead, closes #468
alexanderzobnin Dec 26, 2019
51ef6f7
update change log
alexanderzobnin Dec 26, 2019
90b8bfa
bump plugin version to 3.10.5
alexanderzobnin Dec 26, 2019
d54d6d2
problems: fix tag removal (list layout)
alexanderzobnin Dec 30, 2019
dd28b28
Fix percentile() function, closes #862 (#863)
mr-ns Jan 11, 2020
fe0c5cf
Update copyright, happy New Year!
alexanderzobnin Jan 11, 2020
4f24b2b
fix not acknowledged problem color with a message (#858)
memfiz Jan 13, 2020
82cfda6
Variable query editor (#856)
alexanderzobnin Jan 13, 2020
ef36b91
Merge remote-tracking branch 'upstream/master' into backend-rebase
Jan 14, 2020
ee30f7d
Fixes for backend
Jan 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [alexanderzobnin@gmail.com](mailto:alexanderzobnin@gmail.com)

---
:copyright: 2015-2019 Alexander Zobnin alexanderzobnin@gmail.com
:copyright: 2015-2020 Alexander Zobnin alexanderzobnin@gmail.com

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",
Comment on lines +33 to +36
Copy link
Contributor Author

@alecxvs alecxvs Jan 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's currently an issue that's failing unit tests if we don't mock @grafana/ui and @grafana/runtime: grafana/grafana#20921

However there's also apparently an issue in master that's causing a different error entirely. Neither one works, but we're going to need 6.6 (or whatever release has the fix).

tl;dr Jest tests are broken because of Grafana packages, we can't fix it and need to wait for a good version of @grafana/ui

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, ok, that makes sense. I'll try to investigate. It seems, I remember some build error in grafana/ui related to Table interface.

"@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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current builds of @grafana/ui started using react-table 7. Without defining our own version of the types here, it was using types 7.x and throwing errors due to type changes in the next version.

"@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