Skip to content

Commit

Permalink
Merge branch 'master' into bug/component-templates-empty-state
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Jul 2, 2020
2 parents 5501d3a + 0e008e3 commit a9e1b88
Show file tree
Hide file tree
Showing 41 changed files with 376 additions and 103 deletions.
9 changes: 8 additions & 1 deletion .ci/Jenkinsfile_coverage
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@ kibanaPipeline(timeoutMinutes: 240) {
}

def handleIngestion(timestamp) {
def previousSha = handlePreviousSha()
kibanaPipeline.downloadCoverageArtifacts()
kibanaCoverage.prokLinks("### Process HTML Links")
kibanaCoverage.collectVcsInfo("### Collect VCS Info")
kibanaCoverage.generateReports("### Merge coverage reports")
kibanaCoverage.uploadCombinedReports()
kibanaCoverage.ingest(env.JOB_NAME, BUILD_NUMBER, BUILD_URL, timestamp, '### Ingest && Upload')
kibanaCoverage.ingest(env.JOB_NAME, BUILD_NUMBER, BUILD_URL, timestamp, previousSha, '### Ingest && Upload')
kibanaCoverage.uploadCoverageStaticSite(timestamp)
}

def handlePreviousSha() {
def previous = kibanaCoverage.downloadPrevious('### Download OLD Previous')
kibanaCoverage.uploadPrevious('### Upload NEW Previous')
return previous
}

def handleFail() {
def buildStatus = buildUtils.getBuildStatus()
if(params.NOTIFY_ON_FAILURE && buildStatus != 'SUCCESS' && buildStatus != 'ABORTED' && buildStatus != 'UNSTABLE') {
Expand Down
15 changes: 15 additions & 0 deletions .fossa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by FOSSA CLI (https://github.com/fossas/fossa-cli)
# Visit https://fossa.com to learn more

version: 2
cli:
server: https://app.fossa.com
fetcher: custom
project: kibana
analyze:
modules:
- name: kibana
type: nodejs
strategy: yarn.lock
target: .
path: .
19 changes: 19 additions & 0 deletions docs/settings/reporting-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ When `xpack.reporting.capture.browser.type` is set to `chromium` (default) you c
large exports from causing performance and storage issues.
Defaults to `10485760` (10mB).

| `xpack.reporting.csv.scroll.size`
| Number of documents retrieved from {es} for each scroll iteration during a CSV
export.
Defaults to `500`.

| `xpack.reporting.csv.scroll.duration`
| Amount of time allowed before {kib} cleans the scroll context during a CSV export.
Defaults to `30s`.

| `xpack.reporting.csv.checkForFormulas`
| Enables a check that warns you when there's a potential formula involved in the output (=, -, +, and @ chars).
See OWASP: https://www.owasp.org/index.php/CSV_Injection
Defaults to `true`.

| `xpack.reporting.csv.enablePanelActionDownload`
| Enables CSV export from a saved search on a dashboard. This action is available in the dashboard
panel menu for the saved search.
Defaults to `true`.

|===

[float]
Expand Down
20 changes: 10 additions & 10 deletions src/dev/code_coverage/ingest_coverage/__tests__/either.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@
* under the License.
*/

import { fromNullable, tryCatch, left, right } from '../either';
import * as Either from '../either';
import { noop } from '../utils';
import expect from '@kbn/expect';

const pluck = (x) => (obj) => obj[x];
const expectNull = (x) => expect(x).to.equal(null);
const attempt = (obj) => fromNullable(obj).map(pluck('detail'));
const attempt = (obj) => Either.fromNullable(obj).map(pluck('detail'));

describe(`either datatype functions`, () => {
describe(`helpers`, () => {
it(`'fromNullable' should be a fn`, () => {
expect(typeof fromNullable).to.be('function');
expect(typeof Either.fromNullable).to.be('function');
});
it(`'tryCatch' should be a fn`, () => {
expect(typeof tryCatch).to.be('function');
it(`' Either.tryCatch' should be a fn`, () => {
expect(typeof Either.tryCatch).to.be('function');
});
it(`'left' should be a fn`, () => {
expect(typeof left).to.be('function');
expect(typeof Either.left).to.be('function');
});
it(`'right' should be a fn`, () => {
expect(typeof right).to.be('function');
expect(typeof Either.right).to.be('function');
});
});
describe('tryCatch', () => {
describe(' Either.tryCatch', () => {
let sut = undefined;
it(`should return a 'Left' on error`, () => {
sut = tryCatch(() => {
sut = Either.tryCatch(() => {
throw new Error('blah');
});
expect(sut.inspect()).to.be('Left(Error: blah)');
});
it(`should return a 'Right' on successful execution`, () => {
sut = tryCatch(noop);
sut = Either.tryCatch(noop);
expect(sut.inspect()).to.be('Right(undefined)');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import expect from '@kbn/expect';
import { ciRunUrl, coveredFilePath, itemizeVcs } from '../transforms';
import { ciRunUrl, coveredFilePath, itemizeVcs, prokPrevious } from '../transforms';

describe(`Transform fn`, () => {
describe(`ciRunUrl`, () => {
Expand Down Expand Up @@ -61,6 +61,14 @@ describe(`Transform fn`, () => {
});
});
});
describe(`prokPrevious`, () => {
const comparePrefixF = () => 'https://github.com/elastic/kibana/compare';
process.env.FETCHED_PREVIOUS = 'A';
it(`should return a previous compare url`, () => {
const actual = prokPrevious(comparePrefixF)('B');
expect(actual).to.be(`https://github.com/elastic/kibana/compare/A...B`);
});
});
describe(`itemizeVcs`, () => {
it(`should return a sha url`, () => {
const vcsInfo = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const env = {
ES_HOST: 'https://super:changeme@some.fake.host:9243',
NODE_ENV: 'integration_test',
COVERAGE_INGESTION_KIBANA_ROOT: '/var/lib/jenkins/workspace/elastic+kibana+code-coverage/kibana',
FETCHED_PREVIOUS: 'FAKE_PREVIOUS_SHA',
};

describe('Ingesting coverage', () => {
Expand Down Expand Up @@ -68,31 +69,64 @@ describe('Ingesting coverage', () => {
expect(folderStructure.test(actualUrl)).ok();
});
});

describe(`vcsInfo`, () => {
let stdOutWithVcsInfo = '';
describe(`without a commit msg in the vcs info file`, () => {
let vcsInfo;
const args = [
'scripts/ingest_coverage.js',
'--verbose',
'--vcsInfoPath',
'src/dev/code_coverage/ingest_coverage/integration_tests/mocks/VCS_INFO_missing_commit_msg.txt',
'--path',
];

beforeAll(async () => {
const args = [
'scripts/ingest_coverage.js',
'--verbose',
'--vcsInfoPath',
'src/dev/code_coverage/ingest_coverage/integration_tests/mocks/VCS_INFO_missing_commit_msg.txt',
'--path',
];
const opts = [...args, resolved];
const { stdout } = await execa(process.execPath, opts, { cwd: ROOT_DIR, env });
vcsInfo = stdout;
stdOutWithVcsInfo = stdout;
});

it(`should be an obj w/o a commit msg`, () => {
const commitMsgRE = /"commitMsg"/;
expect(commitMsgRE.test(vcsInfo)).to.not.be.ok();
expect(commitMsgRE.test(stdOutWithVcsInfo)).to.not.be.ok();
});
});
describe(`including previous sha`, () => {
let stdOutWithPrevious = '';
beforeAll(async () => {
const opts = [...verboseArgs, resolved];
const { stdout } = await execa(process.execPath, opts, { cwd: ROOT_DIR, env });
stdOutWithPrevious = stdout;
});

it(`should have a vcsCompareUrl`, () => {
const previousCompareUrlRe = /vcsCompareUrl.+\s*.*https.+compare\/FAKE_PREVIOUS_SHA\.\.\.f07b34f6206/;
expect(previousCompareUrlRe.test(stdOutWithPrevious)).to.be.ok();
});
});
describe(`with a commit msg in the vcs info file`, () => {
beforeAll(async () => {
const args = [
'scripts/ingest_coverage.js',
'--verbose',
'--vcsInfoPath',
'src/dev/code_coverage/ingest_coverage/integration_tests/mocks/VCS_INFO.txt',
'--path',
];
const opts = [...args, resolved];
const { stdout } = await execa(process.execPath, opts, { cwd: ROOT_DIR, env });
stdOutWithVcsInfo = stdout;
});

it(`should be an obj w/ a commit msg`, () => {
const commitMsgRE = /commitMsg/;
expect(commitMsgRE.test(stdOutWithVcsInfo)).to.be.ok();
});
});
});
describe(`team assignment`, () => {
let shouldNotHavePipelineOut = '';
let shouldIndeedHavePipelineOut = '';

const args = [
'scripts/ingest_coverage.js',
'--verbose',
Expand All @@ -101,26 +135,30 @@ describe('Ingesting coverage', () => {
'--path',
];

it(`should not occur when going to the totals index`, async () => {
const teamAssignRE = /"pipeline":/;
const shouldNotHavePipelineOut = await prokJustTotalOrNot(true, args);
const teamAssignRE = /pipeline:/;

beforeAll(async () => {
const summaryPath = 'jest-combined/coverage-summary-just-total.json';
const resolved = resolve(MOCKS_DIR, summaryPath);
const opts = [...args, resolved];
const { stdout } = await execa(process.execPath, opts, { cwd: ROOT_DIR, env });
shouldNotHavePipelineOut = stdout;
});
beforeAll(async () => {
const summaryPath = 'jest-combined/coverage-summary-manual-mix.json';
const resolved = resolve(MOCKS_DIR, summaryPath);
const opts = [...args, resolved];
const { stdout } = await execa(process.execPath, opts, { cwd: ROOT_DIR, env });
shouldIndeedHavePipelineOut = stdout;
});

it(`should not occur when going to the totals index`, () => {
const actual = teamAssignRE.test(shouldNotHavePipelineOut);
expect(actual).to.not.be.ok();
});
it(`should indeed occur when going to the coverage index`, async () => {
const shouldIndeedHavePipelineOut = await prokJustTotalOrNot(false, args);
const onlyForTestingRe = /ingest-pipe=>team_assignment/;
const actual = onlyForTestingRe.test(shouldIndeedHavePipelineOut);
it(`should indeed occur when going to the coverage index`, () => {
const actual = /ingest-pipe=>team_assignment/.test(shouldIndeedHavePipelineOut);
expect(actual).to.be.ok();
});
});
});
async function prokJustTotalOrNot(isTotal, args) {
const justTotalPath = 'jest-combined/coverage-summary-just-total.json';
const notJustTotalPath = 'jest-combined/coverage-summary-manual-mix.json';

const resolved = resolve(MOCKS_DIR, isTotal ? justTotalPath : notJustTotalPath);
const opts = [...args, resolved];
const { stdout } = await execa(process.execPath, opts, { cwd: ROOT_DIR, env });
return stdout;
}
84 changes: 84 additions & 0 deletions src/dev/code_coverage/ingest_coverage/maybe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint new-cap: 0 */
/* eslint no-unused-vars: 0 */

/**
* Just monad used for valid values
*/
export function Just(x) {
return {
value: () => x,
map: (f) => Maybe.of(f(x)),
isJust: () => true,
inspect: () => `Just(${x})`,
};
}
Just.of = function of(x) {
return Just(x);
};
export function just(x) {
return Just.of(x);
}

/**
* Maybe monad.
* Maybe.fromNullable` lifts an `x` into either a `Just`
* or a `Nothing` typeclass.
*/
export function Maybe(x) {
return {
chain: (f) => f(x),
map: (f) => Maybe(f(x)),
inspect: () => `Maybe(${x})`,
nothing: () => Nothing(),
isNothing: () => false,
isJust: () => false,
};
}
Maybe.of = function of(x) {
return just(x);
};

export function maybe(x) {
return Maybe.of(x);
}
export function fromNullable(x) {
return x !== null && x !== undefined && x !== false && x !== 'undefined' ? just(x) : nothing();
}

/**
* Nothing wraps undefined or null values and prevents errors
* that otherwise occur when mapping unexpected undefined or null
* values
*/
export function Nothing() {
return {
value: () => {
throw new TypeError(`Nothing algebraic data type returns...no value :)`);
},
map: (f) => {},
isNothing: () => true,
inspect: () => `[Nothing]`,
};
}
export function nothing() {
return Nothing();
}
Loading

0 comments on commit a9e1b88

Please sign in to comment.