Git Product home page Git Product logo

opbeans-node's Introduction

Opbeans for Node.js

The Opbeans inventory management system is a demo app created and maintained by Elastic.

Build Status Lint status

Technology Stack

This application uses the following technologies:

Configuration

Setup the following environment variables:

  • NODE_ENV - The current Node environment (set to production to enable Elastic APM)
  • PORT - The port at which to run the Opbeans server (default: 3000)
  • PGHOST - PostgreSQL server host
  • PGPORT - PostgreSQL server port
  • PGUSER - PostgreSQL database username
  • PGPASSWORD - PostgreSQL database password
  • PGDATABASE - PostgreSQL database name (default: opbeans)
  • ELASTIC_APM_SERVICE_NAME - Elastic APM service name for the server app (default: opbeans-node)
  • ELASTIC_APM_SERVER_URL - APM Server URL (default: http://localhost:8200)
  • ELASTIC_APM_JS_SERVER_URL - Elastic APM Server URL for the client app (default: http://localhost:3000)
  • ELASTIC_APM_JS_SERVICE_NAME - Elastic APM App Name for the client app (defaults to name from opbeans-frontend package.json file
  • ELASTIC_APM_JS_SERVICE_VERSION - Elastic APM App Name for the client app (defaults to version from opbeans-frontend package.json file

For a complete list of Elastic APM agent environment variables, see the offical documentation

For a complete list of PostgreSQL environment variables see the official documentation.

Bootstrap

Populate the database with tables and basic data:

npm run db-setup

Generate random orders:

node db/generate_orders.js <num>

Where <num> is the amount of orders to create.

Start

npm start

Updating the client

If NODE_ENV isn't production, running npm install will also clone, install and build [opbeats-frontend]. If you ever want to update the opbeans-frontend, just run:

npm run client-update

Testing locally

The simplest way to test this demo is by running:

make test

Tests are written using bats under the tests dir

Publishing to dockerhub locally

Publish the docker image with

VERSION=1.2.3 make publish

NOTE: VERSION refers to the tag for the docker image which will be published in the registry

Demo notes

Trigger error

The app have a built-in bug that you can trigger by navigating to the path /is-it-coffee-time.

Trigger slowness

The app have two npm scripts for adding a new customer:

  • customer-add-ok, which will add a new customer
  • customer-add-redos, which fail adding a new customer and block the server from processing any other requests in the meantime.

Run either of the two scripts using npm run <name>.

If running inside docker, you can run it using docker-compose, e.g:

docker-compose exec opbeans-node npm run customer-add-redos

License

MIT


Made with ♥️ and ☕️ by Elastic.

opbeans-node's People

Contributors

andremm avatar apmmachine avatar beniwohli avatar dependabot[bot] avatar github-actions[bot] avatar grosa1 avatar hmdhk avatar jahtalab avatar jlvoiseux avatar kuisathaverat avatar qard avatar reakaleek avatar roncohen avatar trentm avatar v1v avatar vanjacosic avatar watson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opbeans-node's Issues

Investigate extremely slow requests captures on Edge environment

Observing the app performance overtime on Edge environment, I noticed that it sometimes has rare but extremely slow transactions (2-5 minutes slow).
image

Details don't capture why this could be happening.
image

I suggest to investigate a little to better understand what could be happening.
cc @trentm

New icon proposal

Hi, I am a graphic designer, I want to help others in graphic design.

After I reviewed your project, you have no logo on this project. Therefore I want to contribute to this project by creating a new logo / icon. what do you think?

"Opbeans Node Bump" job fails with "You are not currently on a branch"

Recent in #163 the code to handle running ".ci/bump-version.sh" and gitPush() etc. was moved from apm-agent-nodejs/.ci/Jenkinsfile to this repo (opbeans-node/.ci/bump-opbeans-node.groovy).

The failure was (https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-nodejs%2Fbump-opbeans-node-mbp/detail/main/2/pipeline):

git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/elastic/opbeans-node.git — Git push<1s

[2022-06-18T20:09:25.801Z] + git push https://****:****@github.com/elastic/opbeans-node.git
[2022-06-18T20:09:25.801Z] fatal: You are not currently on a branch.
[2022-06-18T20:09:25.801Z] To push the history leading to the current (detached HEAD)
[2022-06-18T20:09:25.801Z] state now, use
[2022-06-18T20:09:25.801Z] 
[2022-06-18T20:09:25.801Z]     git push https://****:****@github.com/elastic/opbeans-node.git HEAD:<name-of-remote-branch>
[2022-06-18T20:09:25.801Z] 
script returned exit code 128

details

elastic/apm-agent-nodejs#2764 removed support from apm-agent-nodejs.git. So before we had:

-        stage('Opbeans') {
-          environment {
-            REPO_NAME = "${OPBEANS_REPO}"
-          }
-          steps {
-            deleteDir()
-            dir("${OPBEANS_REPO}"){
-              git(credentialsId: 'f6c7695a-671e-4f4f-a331-acdce44ff9ba',
-                  url: "[email protected]:elastic/${OPBEANS_REPO}.git",
-                  branch: 'main')
-              // It's required to transform the tag value to the artifact version
-              sh script: ".ci/bump-version.sh ${env.BRANCH_NAME.replaceAll('^v', '')}", label: 'Bump version'
-              // The opbeans pipeline will trigger a release for the main branch
-              gitPush()
-              // The opbeans pipeline will trigger a release for the release tag
-              gitCreateTag(tag: "${env.BRANCH_NAME}")
-            }
-          }
-        }

and now we have:

+      steps {
+        withGithubNotify(context: 'Update Agent Dep') {
+          deleteDir()
+          gitCheckout(basedir: BASE_DIR)
+          dir(BASE_DIR){
+            script {
+              AVAIL_AGENT_UPDATE_VER = sh(
+                  script: '.ci/avail-agent-update-ver.sh',
+                  returnStdout: true
+              ).trim()
+              if (AVAIL_AGENT_UPDATE_VER) {
+                echo "Available agent version update: '${AVAIL_AGENT_UPDATE_VER}'"
+                sh(script: ".ci/bump-version.sh ${AVAIL_AGENT_UPDATE_VER}")
+                gitPush()
+                gitCreateTag(tag: "v${AVAIL_AGENT_UPDATE_VER}")
+              } else {
+                echo "This repo is already using the latest available APM agent version."
+              }
+            }
+          }
+        }

@v1v Do you think the fix might be to add credentialsId to the git checkout here:

gitCheckout(basedir: BASE_DIR)
? E.g. this:

diff --git a/.ci/bump-opbeans-node.groovy b/.ci/bump-opbeans-node.groovy
index d8ade27..60302ba 100644
--- a/.ci/bump-opbeans-node.groovy
+++ b/.ci/bump-opbeans-node.groovy
@@ -36,7 +36,9 @@ pipeline {
       steps {
         withGithubNotify(context: 'Update Agent Dep') {
           deleteDir()
-          gitCheckout(basedir: BASE_DIR)
+          gitCheckout(basedir: BASE_DIR,
+            credentialsId: 'f6c7695a-671e-4f4f-a331-acdce44ff9ba',
+            branch: 'main')
           dir(BASE_DIR){
             script {
               AVAIL_AGENT_UPDATE_VER = sh(

"Opbeans Node Bump" job fails attempting to push to 'https://github.com/null/null.git/'

After the #166 fix for #165
the bump is still failing: https://apm-ci.elastic.co/job/apm-agent-nodejs/job/bump-opbeans-node-mbp/job/main/3/console

18:22:51  [Pipeline] sh (Git push)
18:22:51  + git push https://****:****@github.com/null/null.git
18:22:51  remote: Repository not found.
18:22:51  fatal: repository 'https://****:****@github.com/null/null.git/' not found
18:22:51  [Pipeline] }

Fixing a Jenkins pipeline that only runs on main is challenging.

"Integration Tests" check on master branch is never reported to GitHub

For some reason the "Integration tests" check on commits to master is never reported:
https://github.com/elastic/opbeans-node/commits/master

For example for this commit: 3d14e47
The "pending" "Integration Tests" check links to https://apm-ci.elastic.co/job/apm-integration-tests-selector-mbp/job/master/ which doesn't indicate which build it was. Clicking around, that opbeans-node commit's build trigger this integration test build: https://apm-ci.elastic.co/job/apm-integration-tests-selector-mbp/job/master/15957/
That completed, but the check on the opbeans-node commit has not been updated.

Note that I believe Integration Tests checks are being updated for PRs, e.g. this one: #78

Is someone in @elastic/observablt-robots able to help track down why?

[APM-CI][Opbeans] Use correct environment variables for RUM agent config

The environment variables used here to generate RUM agent config are not the ones documented in the README.
The variables should be:

  • ELASTIC_APM_JS_BASE_SERVER_URL - Elastic APM Server URL for the
    client app (default: http://localhost:3000)
  • ELASTIC_APM_JS_BASE_SERVICE_NAME - Elastic APM App Name for the
    client app (defaults to name from opbeans-frontend package.json
    file
  • ELASTIC_APM_JS_BASE_SERVICE_VERSION - Elastic APM App Name for the
    client app (defaults to version from opbeans-frontend package.json
    file

cc @watson @Qard

opbeans CI should handle updating its elastic-apm-node dep

Currently, when elastic-apm-node does a release, part of the Jenkins "Release" pipeline is an "Opbeans" stage that attempts to do the following to this (opbeans-node.git) repo:

  1. update the elastic-apm-node dep to the new release
  2. tag this repo with the new elastic-apm-node version, e.g. "v1.2.3".

Of late (since the elastic-apm-node release pipeline started handling the npm publish step), this "Opbeans" stage fails because there isn't enough time between the npm publish and attempting to use it for the dep update in this repo. In discussion on elastic/apm-agent-nodejs#2728 it was decided to attempt to move responsibility for updating the elastic-apm-node dep in opbeans-node.git to this repo.

#163 is a starter PR that is playing with adding a stage('Update Agent Dep') { to the opbeans pipeline to handle this. Ultimately it will require an update to the shared opbeansPipeline() var defined in apm-pipeline-library.git (https://github.com/elastic/apm-pipeline-library/blob/main/vars/opbeansPipeline.groovy) and used by all the opbeans-FOO.git Jenkinsfiles.

Database initialization fails : SCRAM authentication requires libpq version 10 or above

Description

When cloning the project as is and building the docker container, the database cannot be initialised as SCRAM authentication fails on my M1 Mac.

Screenshots

image
image

To Reproduce (Tested on a M1 Mac and a x86_64 Ubuntu)

  • Clone the repo locally
  • Build the docker container using docker-compose up
  • The container loadPgData exits with the following error : psql: SCRAM authentication requires libpq version 10 or above
  • An error is displayed when accessing the app running locally.

Possible solutions

The container use to initialize the database (LoadPgData) uses node:12, which is based on Debian Stretch. The default version of postgres-client is then 9.6, which does not satisfy the requirements for SCRAM authentication with Postgres 14.

I have tested two solutions locally that allow the project to work "out of the box" again :

  • Force the Postgres version in the Docker-compose file to 13.5 in order to fetch the most recent version supporting SCRAM authentication from libpq < 10.
  • Use a Node image based on a more recent Debian version, such as node:12-bullseye. The default postgresql-client downloaded is then postgresql-client-13, which satisfies the requirements for SCRAM auth with Postgres 14.

Check if the bootstrap instructions still work

The bootstrap instructions in the README are very old and have not been tested for ages. We should consider if we should just remove them and add notes to the docs about how to run this with Docker instead maybe

drop node 12 support and bump node version used in containers

Node v12 goes out of maint at the end of Apr 2022. Should we drop support for it? Should we bump the uses of node v12? Some relevant hits in the current source code:

package.json
22:    "node": ">=12"

.github/workflows/lint.yml
20:        node-version: '14'

docker-compose.yml
160:    image: node:12-bullseye

docker-compose-elastic-cloud.yml
110:    image: node:12-bullseye

.ci/bump-version.sh
13:  node:12-alpine /bin/sh -c "set -x

Makefile
4:LTS_ALPINE ?= 12-alpine

See also:

  • #129 brings up potential dependency issues if the docker-compose files are bumped to node 16 or later for the postgres database load container
  • #153 is bumping the default Dockerfile to use node-18 for the app

Upgrade to run on Node 8

Currently the Opbeans test app runs on Node 6 as this was set up before we had support for Node 8. Now that we supported Node 8 for a while, we should bump the Node version dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.