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

[QA][Code Coverage] Fixup Team Assignment #72467

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"abc": "123"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/

import expect from '@kbn/expect';
import { fetch } from '../team_assignment/get_data';
import { noop } from '../utils';

describe(`Team Assignment`, () => {
const mockPath = 'src/dev/code_coverage/ingest_coverage/__tests__/mocks/team_assign_mock.json';
describe(`fetch fn`, () => {
it(`should be a fn`, () => {
expect(typeof fetch).to.be('function');
});
describe(`applied to a path that exists`, () => {
it(`should return the contents of the path`, () => {
const sut = fetch(mockPath);
expect(sut.chain(JSON.parse)).to.have.property('abc');
});
});
describe(`applied to an non-existing path`, () => {
it(`should return a Left with the error message within`, () => {
const expectLeft = (err) =>
expect(err.message).to.contain('ENOENT: no such file or directory');

fetch('fake_path.json').fold(expectLeft, noop);
});
});
});
});
2 changes: 1 addition & 1 deletion src/dev/code_coverage/ingest_coverage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export const TEAM_ASSIGNMENT_PIPELINE_NAME = process.env.PIPELINE_NAME || 'team_
export const CODE_COVERAGE_CI_JOB_NAME = 'elastic+kibana+code-coverage';
export const RESEARCH_CI_JOB_NAME = 'elastic+kibana+qa-research';
export const CI_JOB_NAME = process.env.COVERAGE_JOB_NAME || RESEARCH_CI_JOB_NAME;
export const RESEARCH_CLUSTER_ES_HOST = process.env.ES_HOST || 'http://localhost:9200';
export const ES_HOST = process.env.ES_HOST || 'http://localhost:9200';
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import { readFileSync } from 'fs';
import { resolve } from 'path';
import { fromNullable } from '../either';
import { tryCatch as tc } from '../either';

const ROOT = resolve(__dirname, '../../../../..');

const resolveFromRoot = resolve.bind(null, ROOT);
const path = `
src/dev/code_coverage/ingest_coverage/team_assignment/ingestion_pipeline_painless.json`;
const resolved = resolveFromRoot(path.trimStart());
const getContents = (scriptPath) => readFileSync(scriptPath, 'utf8');

export const fetch = () => fromNullable(resolved).map(getContents);
const resolved = (path) => () => resolveFromRoot(path);

const getContents = (path) => tc(() => readFileSync(path, 'utf8'));

// fetch :: String -> Left | Right
export const fetch = (path) => tc(resolved(path)).chain(getContents);
32 changes: 21 additions & 11 deletions src/dev/code_coverage/ingest_coverage/team_assignment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,39 @@
import { run } from '@kbn/dev-utils';
import { TEAM_ASSIGNMENT_PIPELINE_NAME } from '../constants';
import { fetch } from './get_data';
import { noop } from '../utils';
import { update } from './update_ingest_pipeline';

export const uploadTeamAssignmentJson = () => run(execute, { description });

const updatePipeline = update(TEAM_ASSIGNMENT_PIPELINE_NAME);

function execute({ flags, log }) {
const execute = ({ flags, log }) => {
if (flags.verbose) log.verbose(`### Verbose logging enabled`);

fetch().fold(noop, updatePipeline(log));
const logLeft = handleErr(log);
const updateAndLog = updatePipeline(log);

const { path } = flags;

fetch(path).fold(logLeft, updateAndLog);
Copy link
Member

Choose a reason for hiding this comment

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

What will happen now if getContents fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

logLeft() should happen.

};

function handleErr(log) {
return (msg) => log.error(msg);
}

function description() {
return `
const description = `

Upload the latest team assignment pipeline def from src,
to the cluster.

`;

Examples:
const flags = {
string: ['path', 'verbose'],
help: `
--path Required, path to painless definition for team assignment.
`,
};

node scripts/load_team_assignment.js --verbose
const usage = 'node scripts/load_team_assignment.js --verbose --path PATH_TO_PAINLESS_SCRIPT.json';

`;
}
export const uploadTeamAssignmentJson = () => run(execute, { description, flags, usage });
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

import { createFailError } from '@kbn/dev-utils';
import { RESEARCH_CLUSTER_ES_HOST } from '../constants';
import { ES_HOST } from '../constants';
import { pretty, green } from '../utils';

const { Client } = require('@elastic/elasticsearch');

const node = RESEARCH_CLUSTER_ES_HOST;
const node = ES_HOST;
const client = new Client({ node });

export const update = (id) => (log) => async (body) => {
Expand Down
2 changes: 1 addition & 1 deletion src/dev/code_coverage/shell_scripts/assign_teams.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export PIPELINE_NAME
ES_HOST="https://${USER_FROM_VAULT}:${PASS_FROM_VAULT}@${HOST_FROM_VAULT}"
export ES_HOST

node scripts/load_team_assignment.js --verbose
node scripts/load_team_assignment.js --verbose --path src/dev/code_coverage/ingest_coverage/team_assignment/ingestion_pipeline_painless.json

echo "### Code Coverage Team Assignment - Complete"
echo ""