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

adds: initial service architecture for Elastic search service port #1802

Closed

Conversation

raygervais
Copy link
Contributor

@raygervais raygervais commented Feb 20, 2021

Issue This PR Addresses

Closes #1737

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

Adds support for search.docker.localhost, which ports the original ELK query controller to a dedicated service. The following is added as a warning to not work further on the original codebase for querying:

/*
 * NOTE: This has been ported to ~/src/api/search
 * Future updates will remove the codebase below
 * and point towards `service.docker.localhost` for querying.
 */

image

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

src/api/search/server.js Show resolved Hide resolved
src/api/search/server.js Outdated Show resolved Hide resolved
Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

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

Left some initial feedback, and let's get CI to work (prettier fixes, eslint fixes).

Also, this needs tests

src/api/docker-compose-api-production.yml Outdated Show resolved Hide resolved
src/api/search/package.json Outdated Show resolved Hide resolved

const query = require('./src/routes/query');

const service = new Satellite();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also do:

const service = new Satellite({ router: query });

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 tried this, and it didn't seem to find the /query route with the above implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

With 1.5.1 or 1.5.2?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've shipped 1.6.0, fyi.

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 had tested with 1.5.2, latest at the time.
Will update to 1.6.0

src/api/search/src/bin/search.js Outdated Show resolved Hide resolved
src/api/search/src/bin/elastic.js Outdated Show resolved Hide resolved
src/api/search/src/routes/health.js Outdated Show resolved Hide resolved
@humphd
Copy link
Contributor

humphd commented Mar 14, 2021

I notice you pushed a bunch of commits, but also that it's quite a bit out of date. Let me know when you want me to review this again.

@raygervais
Copy link
Contributor Author

Will do @humphd, right now just getting the env setup to write tests. Currently running into this issue:

raygervais@MacOS ~/D/R/telescope> docker-compose --env-file config/env.development up -d
                                  
Creating elasticsearch ... 
Creating redis         ... 
Creating elasticsearch ... done
Creating redis         ... done
ERROR: for traefik  Cannot start service traefik: Ports are not available: listen tcp 0.0.0.0:80: bi

@humphd
Copy link
Contributor

humphd commented Mar 15, 2021

What's running on 80 for you?

@raygervais
Copy link
Contributor Author

httpd       111           root    4u  IPv6 0xb9c406840149f42d      0t0    TCP *:80 (LISTEN)
httpd       674           _www    4u  IPv6 0xb9c406840149f42d      0t0    TCP *:80 (LISTEN)

Welp. Looks like I really need to clean this system given I'm fairly confident this is a Apache/PHP setup still running.

@raygervais
Copy link
Contributor Author

Yup it was, back to writing tests now.

@humphd
Copy link
Contributor

humphd commented Mar 15, 2021

Cool. I know you are well versed on docker and such, but if any of this needs explaining, let me know. I had to iterate and change a lot of it to make it all work.

@raygervais
Copy link
Contributor Author

One question which I cannot seem to figure out, according to the README and env.development files, it implies I should be able to access the API via api.telescope.localhost/v1, yet I cannot seem to connect to anything but Traefik itself via localhost:8080. See docker ps output:

raygervais@MacOS ~/D/R/telescope> docker-compose --env-file config/env.development ps -a
     Name                   Command               State                                                           Ports                                                        
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
apm              /usr/local/bin/docker-entr ...   Up      0.0.0.0:55097->8200/tcp                                                                                              
auth             docker-entrypoint.sh dumb- ...   Up      0.0.0.0:55092->7777/tcp                                                                                              
elasticsearch    /tini -- /usr/local/bin/do ...   Up      0.0.0.0:9200->9200/tcp,0.0.0.0:55091->9200/tcp, 9300/tcp                                                             
feed-discovery   docker-entrypoint.sh dumb- ...   Up      0.0.0.0:55095->7777/tcp                                                                                              
firebase         docker-entrypoint.sh fireb ...   Up      0.0.0.0:55099->4000/tcp, 5000/tcp, 5001/tcp, 8080/tcp, 8085/tcp, 0.0.0.0:8088->8088/tcp, 9000/tcp, 9005/tcp, 9099/tcp
image            docker-entrypoint.sh dumb- ...   Up      0.0.0.0:55093->4444/tcp                                                                                              
login            docker-php-entrypoint apac ...   Up      80/tcp, 0.0.0.0:55098->8080/tcp, 8443/tcp                                                                            
posts            docker-entrypoint.sh dumb- ...   Up      0.0.0.0:55094->5555/tcp                                                                                              
redis            docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp,0.0.0.0:55090->6379/tcp                                                                       
search           docker-entrypoint.sh dumb- ...   Up      0.0.0.0:55096->4445/tcp                                                                                              
traefik          /entrypoint.sh --log.level ...   Up      0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp         

And traefik:
Screen Shot 2021-03-14 at 8 55 51 PM

@humphd
Copy link
Contributor

humphd commented Mar 15, 2021

@raygervais we found out today that Docker on Windows can't do this custom domain name resolution via its DNS, so we switched to use localhost:80/v1/image etc. It's not as pretty as api.telescope.localhost but it lets our Windows friends play along.

I'm fixing it in #1944, which you can review if you want.

…backend

fixes: missing variables from port

adds: documentation updates and code cleanup

adds: corrections based on feedback and improvements

adds: port of original tests (failing WIP)

fixes: rebase issues and updates docker env
@@ -157,3 +185,22 @@ services:
hard: -1
ports:
- '9200'
labels:
Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE: @manekenpix recently changed this to expose 9200 in development, since we can't do fancy domain names for localhost. Check what's on master.

Copy link
Contributor

Choose a reason for hiding this comment

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

@humphd @manekenpix I don't see the Labels part on master - should it be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Follow the way things are on master yes. NOTE: we define things in different places now: the docker-compose.yml is our base file, and development.yml are overrides/extras for development/CI; production.yml for production. So look in all three places.

environment:
- ELASTIC_APM_SERVICE_NAME=search
- SEARCH_PORT

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

Copy link
Contributor

Choose a reason for hiding this comment

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

@humphd Can you please clarify what should be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the blank line

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

# Specify the redis port
- 'traefik.http.services.elasticsearch.loadbalancer.server.port=9200'

apm:
Copy link
Contributor

Choose a reason for hiding this comment

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

This belongs in production.yml

Copy link
Contributor

@izhuravlev izhuravlev Apr 8, 2021

Choose a reason for hiding this comment

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

According to This ToDo, I will move the APM part to production.yml.

@humphd @manekenpix Also, why don't we have all of this on master, but just referenced in a ToDo?

Copy link
Contributor

Choose a reason for hiding this comment

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

We haven't done the Elastic/ELK stuff yet for logging, etc. We started to, but will follow-up with it later.


COPY --chown=node:node . .

RUN npm install ci --only=production
Copy link
Contributor

Choose a reason for hiding this comment

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

RUN npm install --only=production --no-package-lock

Copy link
Contributor

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

"version": "1.0.0",
"description": "A service for optimizing images",
"scripts": {
"dev": "nodemon server.js | pino-pretty -c -t",
Copy link
Contributor

Choose a reason for hiding this comment

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

pino pretty isn't needed now, we do it for you in Satellite.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

"scripts": {
"dev": "nodemon server.js | pino-pretty -c -t",
"start": "node server.js",
"test": "jest test.js"
Copy link
Contributor

Choose a reason for hiding this comment

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

Test config and execution all happens from the root now. Setup your tests like we do in image, feed-discovery, posts, etc. https://github.com/Seneca-CDOT/telescope/blob/master/src/api/image/jest.config.js

"node": ">=12.0.0"
},
"devDependencies": {
"del-cli": "^3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove everything in here except supertest and nodemon.

Copy link
Contributor

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

const { text, filter, page, perPage } = req.query;
res.send(await search(text, filter, page, perPage));
} catch (error) {
res.status(500).send(`There was an error while executing your query: ${error}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

For the sake of using APM, you might want to call next(err) instead, and let it go down through to the error handler, where we'll log and deal with it in APM.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,118 @@
const request = require('supertest');
process.env.ELASTICSEARCH_HOSTS = 'http://elasticsearch:9200';
Copy link
Contributor

Choose a reason for hiding this comment

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

Your tests can read in config/env.development (see how auth's jest tests do it).

@izhuravlev
Copy link
Contributor

@raygervais Do you need help on this one? Do you want me to participate?

@raygervais
Copy link
Contributor Author

If you @izhuravlev or @HyperTHD want to take this over, it would be greatly appreciated. I'm bogged down with work and other items right now.

@izhuravlev
Copy link
Contributor

@raygervais I'll take that.

@HyperTHD your help and advice will be greatly appreciated!

@humphd humphd modified the milestones: 1.9 Release, 2.0-alpha Release Mar 26, 2021
@manekenpix manekenpix mentioned this pull request Apr 4, 2021
8 tasks
@humphd
Copy link
Contributor

humphd commented Apr 8, 2021

@izhuravlev What's the status on this?

@izhuravlev
Copy link
Contributor

@izhuravlev What's the status on this?

@humphd added some changes and added a couple of questions above for the parts that are unclear.

@izhuravlev izhuravlev mentioned this pull request Apr 9, 2021
8 tasks
@humphd
Copy link
Contributor

humphd commented Apr 9, 2021

Moving this work to #2106, thanks for getting it started.

@humphd humphd closed this Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a search microservice
5 participants