diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 6a29160..0000000 --- a/.eslintrc +++ /dev/null @@ -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 diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..8c5880b --- /dev/null +++ b/.eslintrc.json @@ -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 + } +} \ No newline at end of file diff --git a/.zuul.yaml b/.zuul.yaml index 6580506..61a0ff1 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -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 \ No newline at end of file diff --git a/build_monasca_kibana_plugin.sh b/build_monasca_kibana_plugin.sh new file mode 100755 index 0000000..138e596 --- /dev/null +++ b/build_monasca_kibana_plugin.sh @@ -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' \ No newline at end of file diff --git a/index.js b/index.js index 462d4ba..c2f02cf 100644 --- a/index.js +++ b/index.js @@ -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-'), - eventsIndexPrefix: Joi.string().default('events-'), - 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-'), + eventsIndexPrefix: Joi.string().default('events-'), + cookie: cookie, + elasticsearch: elasticsearch + }) + .concat(deprecatedKeystone) + .concat(validKeystone) + .and('url', 'port') + .without('auth_uri', ['url', 'port']) + .default(); } async function init(server) { diff --git a/package.json b/package.json index 9ebcf99..9cc9db5 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/playbooks/monasca-kibana-plugin-build.yml b/playbooks/monasca-kibana-plugin-build.yml new file mode 100644 index 0000000..960c2d5 --- /dev/null +++ b/playbooks/monasca-kibana-plugin-build.yml @@ -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 diff --git a/server/healthcheck/index.js b/server/healthcheck/index.js index 47cb61b..2f4cf67 100644 --- a/server/healthcheck/index.js +++ b/server/healthcheck/index.js @@ -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'); diff --git a/server/mt/auth/scheme.js b/server/mt/auth/scheme.js index c5f6a6d..f50c94c 100644 --- a/server/mt/auth/scheme.js +++ b/server/mt/auth/scheme.js @@ -13,7 +13,7 @@ */ import authenticateFactory from './_authenticate'; -import verify from './verify' +import verify from './verify'; export default (server, opts) => { return { diff --git a/server/mt/auth/verify.js b/server/mt/auth/verify.js index ed2123d..e8fd762 100644 --- a/server/mt/auth/verify.js +++ b/server/mt/auth/verify.js @@ -54,5 +54,5 @@ export default (server) => { // TODO(trebskit) should actually throw error here I guess return reply.continue; - } + }; }; diff --git a/server/mt/kibana/defaultIndexPattern/_exists.js b/server/mt/kibana/defaultIndexPattern/_exists.js index 5384d20..d4eb089 100644 --- a/server/mt/kibana/defaultIndexPattern/_exists.js +++ b/server/mt/kibana/defaultIndexPattern/_exists.js @@ -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') diff --git a/server/mt/kibana/defaultIndexPattern/_set_default_index_pattern.js b/server/mt/kibana/defaultIndexPattern/_set_default_index_pattern.js index 470fee2..127850a 100644 --- a/server/mt/kibana/defaultIndexPattern/_set_default_index_pattern.js +++ b/server/mt/kibana/defaultIndexPattern/_set_default_index_pattern.js @@ -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') diff --git a/server/mt/kibana/defaultIndexPattern/index.js b/server/mt/kibana/defaultIndexPattern/index.js index 68ba0c5..06b362f 100644 --- a/server/mt/kibana/defaultIndexPattern/index.js +++ b/server/mt/kibana/defaultIndexPattern/index.js @@ -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`); } } - }) - }) + }); + }); }; }; diff --git a/server/mt/kibana/savedObjectsToolkit/index.js b/server/mt/kibana/savedObjectsToolkit/index.js index 81410df..deb6218 100644 --- a/server/mt/kibana/savedObjectsToolkit/index.js +++ b/server/mt/kibana/savedObjectsToolkit/index.js @@ -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; diff --git a/server/mt/routing/_map_uri.js b/server/mt/routing/_map_uri.js index 18026d7..543d8ec 100644 --- a/server/mt/routing/_map_uri.js +++ b/server/mt/routing/_map_uri.js @@ -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'); diff --git a/server/mt/routing/_utils.js b/server/mt/routing/_utils.js index 944347d..608cb50 100644 --- a/server/mt/routing/_utils.js +++ b/server/mt/routing/_utils.js @@ -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) diff --git a/server/mt/routing/routes/bulk_get.js b/server/mt/routing/routes/bulk_get.js index 0260a59..fd26fa4 100644 --- a/server/mt/routing/routes/bulk_get.js +++ b/server/mt/routing/routes/bulk_get.js @@ -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) { diff --git a/server/mt/routing/routes/find.js b/server/mt/routing/routes/find.js index 077ad0a..e212266 100644 --- a/server/mt/routing/routes/find.js +++ b/server/mt/routing/routes/find.js @@ -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; diff --git a/server/session/index.js b/server/session/index.js index 5c7380d..b2fe4a6 100644 --- a/server/session/index.js +++ b/server/session/index.js @@ -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();