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

Elastic Integration (Phase II) #339

Merged
merged 42 commits into from
Nov 28, 2016
Merged

Elastic Integration (Phase II) #339

merged 42 commits into from
Nov 28, 2016

Conversation

jonwinton
Copy link
Contributor

@jonwinton jonwinton commented Nov 28, 2016

This PR Includes Breaking Changes

New Features:

  • Amphora now connects to Elastic Search directly rather than via a service in the implementation of Clay. For reference, here is the original method and this is the updated method.
  • New directory called elastic which contains helpers for parsing batch operations from the database. Directory will also house the mappings internal to Amphora (coming soon)
  • Added a utility to Amphora that allows you to dynamically require a module but only if the module exists. Handy for when you're checking to see if something has been added to a specific Clay implementation but is optional.
  • Shifted around and exposed helper methods for parsing batch ops from the dataase.

On The Implementation Side:

  • In any Clay implementation, you can now include a folder called search at the root of your instance and implement a more robust system of parsing data for ES. See example of implementation here.

jonwinton and others added 30 commits November 11, 2016 10:02
@jonwinton
Copy link
Contributor Author

jonwinton commented Nov 28, 2016

You no longer instantiate the search service in the app.js within your Clay instance, all of that is moved into amphora. This vs this.

Copy link
Contributor

@nelsonpecora nelsonpecora left a comment

Choose a reason for hiding this comment

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

two comments, but 👍

@@ -305,9 +334,11 @@ exports.getComponentPackage = control.memoize(getComponentPackage);
exports.isDirectory = control.memoize(isDirectory);
exports.tryRequire = control.memoize(tryRequire);
exports.readFilePromise = control.memoize(readFilePromise);
exports.getFilesPromise = control.memoize(getFilesPromise);
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between this and readFilePromise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

readFilePromise returns the contents of a file, getFilesPromise is like getFiles in that it returns all the filenames within a directory. I just needed to have a version of getFiles which returned a Promise.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohhhh makes sense

// *
// * @return {Promise}
// */
// function createInternalIndices() {
Copy link
Contributor

Choose a reason for hiding this comment

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

commented out...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove this from this PR, but this function will be included in the next phase of changes whenever we actually instantiate the indices that are managed by Amphora.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, then it's cool to leave it in there

@nelsonpecora
Copy link
Contributor

@jonwinton yeah, but that's not a breaking change in amphora's api, is it? You could still technically init that stuff in your clay instance (though you don't need to anymore)

@gloddy
Copy link
Contributor

gloddy commented Nov 28, 2016

@jonwinton @nelsonpecora I'd think that's a breaking change to sites but not amphora.

@gloddy
Copy link
Contributor

gloddy commented Nov 28, 2016

@jonwinton In the feature list:
For reference, here is the original method and this is the updated method.
Both links are the same.

@jonwinton
Copy link
Contributor Author

Ah, sorry about that @gloddy. I've updated the original message.

Copy link
Contributor

@gloddy gloddy left a comment

Choose a reason for hiding this comment

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

This looks great. Just some minor comments and questions.

*/
function filterRefs(op) {
_.each(_.listDeepObjects(op, refProp), function (obj) {
console.log(op[refProp]);
Copy link
Contributor

Choose a reason for hiding this comment

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

console.log helpful in prd?

* @param {string} propertyName
* @returns {Function}
*/
function removeEmptyValuesForProperty(propertyName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this get used anywhere? Popped into my head when I saw this: https://github.com/nymag/amphora/pull/339/files#diff-6612bbbf33f2f172a7fe9e466fbfff28R214

@@ -339,17 +313,59 @@ function batch(ops) {
}

/**
* Create the ES Client or an empty object
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment not helpful anymore?

Copy link
Contributor Author

@jonwinton jonwinton Nov 28, 2016

Choose a reason for hiding this comment

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

// Create client + check the connection
return createClient(overrideClient)
.then(healthCheck)
// .then(createInternalIndices)
Copy link
Contributor

Choose a reason for hiding this comment

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

Holding this here for the next iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

@@ -339,17 +313,59 @@ function batch(ops) {
}

/**
* Create the ES Client or an empty object
* [createClient description]
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete?

@gloddy
Copy link
Contributor

gloddy commented Nov 28, 2016

screen shot 2016-11-28 at 3 11 46 pm

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f45a97f on internal-mappings into 35bc761 on master.

*/
function filterRefs(op) {
_.each(_.listDeepObjects(op, refProp), function (obj) {
console.log(op[refProp]);

Choose a reason for hiding this comment

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

Does this need to be logged? If so, could use winston.

* @returns {boolean}
*/
function isOpForPage(op) {
return op.key.indexOf('/pages/') > 0;

Choose a reason for hiding this comment

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

op.key always a string? Could JSDoc that. Function name could be shortened to isPageOp.

* @returns {boolean}
*/
function isOpForInstance(op) {
return op.key.indexOf('/instances/') > 0;

Choose a reason for hiding this comment

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

Same as above

/**
* True is component is published ("@published")
* @param {object} op
* @returns {boolean}

Choose a reason for hiding this comment

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

@param {string} op.key?

expect(fn(op)).to.equal(true);
});

it('takes an operation and returns false if its key is\'nt a page ref', function () {

Choose a reason for hiding this comment

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

isn\'t or is not -- might want to search replace for this

function compare(expected) {
return function (comparison) {
return expected === comparison;
};

Choose a reason for hiding this comment

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

Arrow function could be nice here return comparison => expected === comparison;

function resolveReferencesForPropertyOfStringType(propertyName) {
return function (ops) {
return bluebird.all(_.map(ops, function (op) {
var result, value = op.value[propertyName];

Choose a reason for hiding this comment

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

always will be an op.value object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yessir!


_.each(ops, function (op) {
if (_.isString(op.value)) {
op.value = JSON.parse(op.value);

Choose a reason for hiding this comment

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

op.value is always an object or JSON string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yessir!

* @returns {Promise}
*/
function validateIndices(mappings) {
return bluebird.all(_.map(Object.keys(mappings), function (index) {

Choose a reason for hiding this comment

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

Could use native map since Object.keys is always an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lodash _.map is still faster than native map because it uses a for loop, plus it maps to the patterns that we've already established. I'd prefer to leave it until there's a good performance reason to switch them all over.

return createClient(overrideClient)
.then(healthCheck)
// .then(createInternalIndices)
.then(setupMappings)

Choose a reason for hiding this comment

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

Does overrideDir get passed through?

Copy link
Contributor Author

@jonwinton jonwinton Nov 28, 2016

Choose a reason for hiding this comment

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

overrideClient? It can be, but really it's only used in testing. The comment is updated to address this.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 99.941% when pulling 564a372 on internal-mappings into 35bc761 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e3ec3ce on internal-mappings into 35bc761 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f537eb5 on internal-mappings into 35bc761 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 87b416f on internal-mappings into 35bc761 on master.

@cruzanmo
Copy link

+1

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 05b3e52 on internal-mappings into 35bc761 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling c7ee98c on internal-mappings into 35bc761 on master.

@dmabuada dmabuada merged commit 6cdadf8 into master Nov 28, 2016
@dmabuada dmabuada deleted the internal-mappings branch November 28, 2016 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants