Adding .zuul job for building plugin

Purpose of this commit is to add Zuul job for building
Monasca-Kibana-Plugin.

List of changes:
- Configuring ESLint with *.json file
- Fixing lint error
- Adding Zuul job for building Monasca-Kibana-Plugin

Please notice that nodejs10-jobs are removed, cause of changes
related to building plugin. It should be fixed.

Change-Id: I9384c0e7995d90df42ee13ab735ec768cef65d3b
This commit is contained in:
Michal Piotrowski 2020-05-04 09:11:26 +02:00
parent bfa95367e0
commit 569382803e
19 changed files with 191 additions and 153 deletions

View File

@ -1,75 +0,0 @@
---
parser: babel-eslint
plugins:
- mocha
env:
es6: true
amd: true
node: true
mocha: true
browser: true
rules:
block-scoped-var: 2
camelcase: [ 2, { properties: never } ]
comma-dangle: 0
comma-style: [ 2, last ]
consistent-return: 0
curly: [ 2, multi-line ]
dot-location: [ 2, property ]
dot-notation: [ 2, { allowKeywords: true } ]
eqeqeq: [ 2, allow-null ]
guard-for-in: 2
indent: [ 2, 2, { SwitchCase: 1 } ]
key-spacing: [ 0, { align: value } ]
max-len: [ 2, 140, 2, { ignoreComments: true, ignoreUrls: true } ]
new-cap: [ 2, { capIsNewExceptions: [ Private ] } ]
no-bitwise: 0
no-caller: 2
no-cond-assign: 0
no-debugger: 2
no-empty: 2
no-eval: 2
no-extend-native: 2
no-extra-parens: 0
no-irregular-whitespace: 2
no-iterator: 2
no-loop-func: 2
no-multi-spaces: 0
no-multi-str: 2
no-nested-ternary: 2
no-new: 0
no-path-concat: 0
no-proto: 2
no-return-assign: 0
no-script-url: 2
no-sequences: 2
no-shadow: 0
no-trailing-spaces: 2
no-undef: 2
no-underscore-dangle: 0
no-unused-expressions: 0
no-unused-vars: 0
no-use-before-define: [ 2, nofunc ]
no-with: 2
one-var: [ 2, never ]
quotes: [ 2, single ]
semi-spacing: [ 2, { before: false, after: true } ]
semi: [ 2, always ]
space-after-keywords: [ 2, always ]
space-before-blocks: [ 2, always ]
space-before-function-paren: [ 2, { anonymous: always, named: never } ]
space-in-parens: [ 2, never ]
space-infix-ops: [ 2, { int32Hint: false } ]
space-return-throw-case: [ 2 ]
space-unary-ops: [ 2 ]
strict: [ 2, never ]
valid-typeof: 2
wrap-iife: [ 2, outside ]
yoda: 0
mocha/no-exclusive-tests: 2
mocha/handle-done-callback: 2

72
.eslintrc.json Normal file
View File

@ -0,0 +1,72 @@
{
"root": true,
"parser": "babel-eslint",
"plugins": ["mocha"],
"env": {
"es6": true,
"amd": true,
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"block-scoped-var": 2,
"camelcase": [ 2, { "properties": "never" } ],
"comma-dangle": 0,
"comma-style": [ 2, "last" ],
"consistent-return": 0,
"curly": [ 2, "multi-line" ],
"dot-location": [ 2, "property" ],
"dot-notation": [ 2, { "allowKeywords": true } ],
"eqeqeq": [ 2, "allow-null" ],
"guard-for-in": 2,
"indent": [ 2, 2, { "SwitchCase": 1 } ],
"key-spacing": [ 0, { "align": "value" } ],
"max-len": [ 2, 140, 2, { "ignoreComments": true, "ignoreUrls": true } ],
"new-cap": [ 2, { "capIsNewExceptions": [ "Private" ] } ],
"no-bitwise": 0,
"no-caller": 2,
"no-cond-assign": 0,
"no-debugger": 2,
"no-empty": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-parens": 0,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-loop-func": 2,
"no-multi-spaces": 0,
"no-multi-str": 2,
"no-nested-ternary": 2,
"no-new": 0,
"no-path-concat": 0,
"no-proto": 2,
"no-return-assign": 0,
"no-script-url": 2,
"no-sequences": 2,
"no-shadow": 0,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-underscore-dangle": 0,
"no-unused-expressions": 0,
"no-unused-vars": 0,
"no-use-before-define": [ 2, "nofunc" ],
"no-with": 2,
"one-var": [ 2, "never" ],
"quotes": [ 2, "single" ],
"semi-spacing": [ 2, { "before": false, "after": true } ],
"semi": [ 2, "always" ],
"keyword-spacing": [ 2, { "before": true, "after": true } ],
"space-before-blocks": [ 2, "always" ],
"space-before-function-paren": [ 2, { "anonymous": "always", "named": "never" } ],
"space-in-parens": [ 2, "never" ],
"space-infix-ops": [ 2, { "int32Hint": false } ],
"space-unary-ops": [ 2 ],
"strict": [ 2, "never" ],
"valid-typeof": 2,
"wrap-iife": [ 2, "outside" ],
"yoda": 0,
"mocha/no-exclusive-tests": 2,
"mocha/handle-done-callback": 2
}
}

View File

@ -2,6 +2,14 @@
check:
jobs:
- monasca-tempest-log-python3-influxdb
- build-monasca-kibana-plugin
gate:
jobs:
- monasca-tempest-log-python3-influxdb
- job:
name: build-monasca-kibana-plugin
run: playbooks/monasca-kibana-plugin-build.yml
required-projects:
- openstack/monasca-kibana-plugin
- elastic/kibana
attempts: 1

24
build_monasca_kibana_plugin.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -x # Print each script step.
set -eo pipefail # Exit the script if any statement returns error.
cd $KIBANA_PATH
git checkout -f 7.3
cp -avr /home/zuul/src/opendev.org/openstack/monasca-kibana-plugin $KIBANA_PATH/plugins
chmod -R 777 $KIBANA_PATH
chown -R zuul: $KIBANA_PATH
runuser -l zuul -c '
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash;
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh";
VERSION="10.15.2";
nvm install ${VERSION};
nvm use ${VERSION};
npm install -g yarn;
cd /home/zuul/src/github.com/elastic/kibana;
yarn kbn bootstrap;
cd plugins/monasca-kibana-plugin
yarn build'

View File

@ -43,18 +43,18 @@ export default (kibana) => {
.default(60 * 60 * 1000) // 1 hour
}).default();
const deprecated_keystone = Joi.object({
const deprecatedKeystone = Joi.object({
url : Joi.string().uri({scheme: ['http', 'https']}),
port: Joi.number(),
})
.tags(['deprecated'])
.notes(['url,port settings have been deprecated in favour of auth_uri'])
.default();
.tags(['deprecated'])
.notes(['url,port settings have been deprecated in favour of auth_uri'])
.default();
const valid_keystone = Joi.object({
const validKeystone = Joi.object({
auth_uri: Joi.string().uri({scheme: ['http', 'https']})
})
.default();
.default();
//Elasticsearch parameter added due to the fact that retrieving elasticsearch url via server.config() is impossible
const elasticsearch = Joi.object({
@ -62,22 +62,22 @@ export default (kibana) => {
}).default();
return Joi
.object({
enabled: Joi.boolean().default(true),
events: Joi.boolean().default(false),
logs: Joi.boolean().default(true),
defaultTimeField: Joi.string().default('@timestamp'),
defaultEventsTimeField: Joi.string().default('@timestamp'),
logsIndexPrefix: Joi.string().default('logs-<project_id>'),
eventsIndexPrefix: Joi.string().default('events-<project_id>'),
cookie: cookie,
elasticsearch: elasticsearch
})
.concat(deprecated_keystone)
.concat(valid_keystone)
.and('url', 'port')
.without('auth_uri', ['url', 'port'])
.default();
.object({
enabled: Joi.boolean().default(true),
events: Joi.boolean().default(false),
logs: Joi.boolean().default(true),
defaultTimeField: Joi.string().default('@timestamp'),
defaultEventsTimeField: Joi.string().default('@timestamp'),
logsIndexPrefix: Joi.string().default('logs-<project_id>'),
eventsIndexPrefix: Joi.string().default('events-<project_id>'),
cookie: cookie,
elasticsearch: elasticsearch
})
.concat(deprecatedKeystone)
.concat(validKeystone)
.and('url', 'port')
.without('auth_uri', ['url', 'port'])
.default();
}
async function init(server) {

View File

@ -35,24 +35,24 @@
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-react": "^7.12.4",
"@hapi/wreck": "^15.0.1",
"bluebird": "^3.2.1",
"boom": "^2.8.0",
"chai": "^3.5.0",
"gulp": "^3.9.0",
"gulp-eslint": "^1.1.1",
"gulp-gzip": "^1.2.0",
"gulp-mocha": "^2.2.0",
"gulp-tar": "^1.8.0",
"gulp-util": "^3.0.7",
"joi": "^9.0.4",
"lodash": "^4.2.1",
"mkdirp": "^0.5.1",
"proxyquire": "^1.7.4",
"rimraf": "^2.5.1",
"rsync": "^0.4.0",
"semver": "^5.3.0",
"sinon": "^1.17.3",
"hoek": "^4.0.1",
"bluebird": "^3.2.1",
"boom": "^2.8.0",
"chai": "^3.5.0",
"gulp": "^3.9.0",
"gulp-eslint": "^1.1.1",
"gulp-gzip": "^1.2.0",
"gulp-mocha": "^2.2.0",
"gulp-tar": "^1.8.0",
"gulp-util": "^3.0.7",
"joi": "^9.0.4",
"lodash": "^4.2.1",
"mkdirp": "^0.5.1",
"proxyquire": "^1.7.4",
"rimraf": "^2.5.1",
"rsync": "^0.4.0",
"semver": "^5.3.0",
"sinon": "^1.17.3",
"hoek": "^4.0.1",
"keystone-v3-client": "~0.0.8",
"@hapi/yar": "^9.2.x",
"request": "^2.88.0"

View File

@ -0,0 +1,9 @@
---
- hosts: all
tasks:
- name: Build monasca-kibana-plugin
shell: "{{ zuul.project.src_dir }}/build_monasca_kibana_plugin.sh"
environment:
MONASCA_COMMON_TAG: "{{ zuul.tag if zuul.pipeline == 'release' else zuul.branch | basename }}"
KIBANA_PATH: "/home/zuul/src/github.com/elastic/kibana"
become: true

View File

@ -43,16 +43,16 @@ module.exports = function healthcheck(plugin, server) {
function check() {
return new Promise((resolve, reject)=> {
const req = request(
requestParams, (res)=> {
const statusCode = res.statusCode;
if (statusCode >= 400) {
plugin.status.red('Unavailable');
reject(false);
} else {
plugin.status.green('Ready');
resolve(true);
}
});
requestParams, (res)=> {
const statusCode = res.statusCode;
if (statusCode >= 400) {
plugin.status.red('Unavailable');
reject(false);
} else {
plugin.status.green('Ready');
resolve(true);
}
});
req.on('error', (error)=> {
plugin.status.red('Unavailable: Failed to communicate with Keystone');

View File

@ -13,7 +13,7 @@
*/
import authenticateFactory from './_authenticate';
import verify from './verify'
import verify from './verify';
export default (server, opts) => {
return {

View File

@ -54,5 +54,5 @@ export default (server) => {
// TODO(trebskit) should actually throw error here I guess
return reply.continue;
}
};
};

View File

@ -12,7 +12,7 @@
* the License.
*/
import {find} from "../savedObjectsToolkit";
import {find} from '../savedObjectsToolkit';
export async function defaultLogsIndexExists(server, userObj) {
const pattern = server.config().get('monasca-kibana-plugin.logsIndexPrefix')

View File

@ -13,7 +13,7 @@
*/
import {updateConfig} from "../savedObjectsToolkit";
import {updateConfig} from '../savedObjectsToolkit';
export async function updateLogsConfig(server, userObj) {
const pattern = server.config().get('monasca-kibana-plugin.logsIndexPrefix')

View File

@ -12,10 +12,10 @@
* the License.
*/
import {createEventsIndexPattern, createLogsIndexPattern} from "./_create";
import {defaultEventsIndexExists, defaultLogsIndexExists} from "./_exists";
import {deleteDefaultEventsIndex, deleteDefaultLogsIndex} from "./_delete";
import {updateEventsConfig, updateLogsConfig} from "./_set_default_index_pattern";
import {createEventsIndexPattern, createLogsIndexPattern} from './_create';
import {defaultEventsIndexExists, defaultLogsIndexExists} from './_exists';
import {deleteDefaultEventsIndex, deleteDefaultLogsIndex} from './_delete';
import {updateEventsConfig, updateLogsConfig} from './_set_default_index_pattern';
export default (server, userObj) => {
return () => {
@ -24,7 +24,7 @@ export default (server, userObj) => {
.then((logsExists) => {
if (server.config().get('monasca-kibana-plugin.logs')) {
server.log(['status', 'info', 'keystone'],
`Default logs-index pattern is enabled in kibana config file`);
'Default logs-index pattern is enabled in kibana config file');
if (!logsExists) {
server.log(['status', 'warning', 'keystone'],
`Default logs-index pattern for ${project} does not exist`);
@ -38,7 +38,7 @@ export default (server, userObj) => {
}
} else {
server.log(['status', 'info', 'keystone'],
`Default logs-index pattern is disabled in kibana config file`);
'Default logs-index pattern is disabled in kibana config file');
if (logsExists) {
server.log(['status', 'warning', 'keystone'],
`Default logs-index pattern for ${project} exists, but it should not`);
@ -54,13 +54,13 @@ export default (server, userObj) => {
.then((eventsExists) => {
if (server.config().get('monasca-kibana-plugin.events')) {
server.log(['status', 'info', 'keystone'],
`Default events-index pattern is enabled in kibana config file`);
'Default events-index pattern is enabled in kibana config file');
if (!eventsExists) {
server.log(['status', 'warning', 'keystone'],
`Default events-index pattern for ${project} does not exist`);
return createEventsIndexPattern(server, userObj)
.then(() => {
return updateEventsConfig(server, userObj)
return updateEventsConfig(server, userObj);
});
} else {
server.log(['status', 'info', 'keystone'],
@ -68,7 +68,7 @@ export default (server, userObj) => {
}
} else {
server.log(['status', 'info', 'keystone'],
`Default events-index pattern is disabled in kibana config file`);
'Default events-index pattern is disabled in kibana config file');
if (eventsExists) {
server.log(['status', 'warning', 'keystone'],
`Default events-index pattern for ${project} exists, but it should not`);
@ -78,7 +78,7 @@ export default (server, userObj) => {
`Default events-index pattern for ${project} does not exist`);
}
}
})
})
});
});
};
};

View File

@ -55,7 +55,7 @@ function _createMetaForSavedObject(object, version) {
title: `Advanced Settings [${version}]`,
inAppUrl: {
path: `${inAppPrefix}${managementPrefix}/settings`,
uiCapabilitiesPath: "advancedSettings.show"
uiCapabilitiesPath: 'advancedSettings.show'
}
};
break;
@ -66,7 +66,7 @@ function _createMetaForSavedObject(object, version) {
editUrl: `${managementPrefix}/index_patterns/${object.title}`,
inAppUrl: {
path: `${inAppPrefix}${managementPrefix}/index_patterns/${object.id}`,
uiCapabilitiesPath: "management.kibana.index_patterns"
uiCapabilitiesPath: 'management.kibana.index_patterns'
}
};
break;
@ -77,7 +77,7 @@ function _createMetaForSavedObject(object, version) {
editUrl: `${managementPrefix}/objects/savedSearches/${object.id}`,
inAppUrl: {
path: `${inAppPrefix}/discover/${object.id}`,
uiCapabilitiesPath: "discover.show"
uiCapabilitiesPath: 'discover.show'
}
};
break;
@ -88,7 +88,7 @@ function _createMetaForSavedObject(object, version) {
editUrl: `${managementPrefix}/objects/savedVisualizations/${object.id}`,
inAppUrl: {
path: `${inAppPrefix}/visualize/edit/${object.id}`,
uiCapabilitiesPath: "visualize.show"
uiCapabilitiesPath: 'visualize.show'
}
};
break;
@ -99,7 +99,7 @@ function _createMetaForSavedObject(object, version) {
editUrl: `${managementPrefix}/objects/savedDashboards/${object.id}`,
inAppUrl: {
path: `${inAppPrefix}/dashboard/${object.id}`,
uiCapabilitiesPath: "dashboard.show"
uiCapabilitiesPath: 'dashboard.show'
}
};
break;

View File

@ -23,7 +23,7 @@ import { PREFIX } from './_utils';
export default (server, request) => {
const config = server.config();
const path = request.path.replace(`${PREFIX}`, '').replace(`/elasticsearch`, '');
const path = request.path.replace(`${PREFIX}`, '').replace('/elasticsearch', '');
const query = querystring.stringify(request.query);
let url = config.get('monasca-kibana-plugin.elasticsearch.url');

View File

@ -13,7 +13,7 @@
*/
import createAgent from './_create_agent';
import {bulkGetSavedObjects} from "../kibana/savedObjectsToolkit";
import {bulkGetSavedObjects} from '../kibana/savedObjectsToolkit';
export const PREFIX = '/mt';
@ -92,7 +92,7 @@ function isAllowedSavedObject(element, patterns) {
function isAllowedDashboard(element, patterns) {
const dashboardRefs = element.references.map((el) => {
return {id: el.id, type: el.type}
return {id: el.id, type: el.type};
});
return bulkGetSavedObjects(dashboardRefs)

View File

@ -13,7 +13,7 @@
*/
import {bulkGetSavedObjects} from '../../kibana/savedObjectsToolkit';
import getAllowedPatterns from '../../kibana/defaultIndexPattern/_get_allowed_patterns'
import getAllowedPatterns from '../../kibana/defaultIndexPattern/_get_allowed_patterns';
import {SESSION_USER_KEY} from '../../../const';
export default function (server, method, path) {

View File

@ -13,7 +13,7 @@
*/
import {findWithMeta} from '../../kibana/savedObjectsToolkit';
import {filterResponse} from "../_utils";
import {filterResponse} from '../_utils';
import {SESSION_USER_KEY} from '../../../const';
import getAllowedPatterns from '../../kibana/defaultIndexPattern/_get_allowed_patterns';
@ -38,7 +38,7 @@ export default function (server, method, path) {
}
return findWithMeta(server, params)
.then((response) => {
return filterResponse(response, patterns, server)
return filterResponse(response, patterns, server);
})
.then((response) => {
response.total = response.saved_objects.length;

View File

@ -11,9 +11,9 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
import yarCookie from "@hapi/yar"
import yarCookie from '@hapi/yar';
import multiTenancy from '../mt';
import {initClients} from "../mt/kibana/savedObjectsToolkit";
import {initClients} from '../mt/kibana/savedObjectsToolkit';
export default (server) => {
const config = server.config();