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

Prometheus integration breaks React App #361

Closed
tavogel opened this issue Aug 1, 2019 · 5 comments
Closed

Prometheus integration breaks React App #361

tavogel opened this issue Aug 1, 2019 · 5 comments

Comments

@tavogel
Copy link
Contributor

tavogel commented Aug 1, 2019

Hello again Nodeshift team!

I'd eagerly like to set your Opossum loose on my code. So far so good in Node.js land, but I am experiencing issues on the Browser side, particularly with sites generated using Create React App.

I noticed you have the following example here:
https://github.com/nodeshift-starters/opossum-examples/tree/master/react

This example uses 1.9, which does work. I am able to replicate this issue in your example code with both 2.3 and 3.0 releases, since the addition of Prometheus.

When trying to build or run the library I get the following error:

$ npm run build

> react-opossum@0.1.0 build /Users/tvogel/src/default/opossum-examples/react/client
> react-scripts build

Creating an optimized production build...
Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
Failed to compile.

./node_modules/prom-client/lib/cluster.js
Cannot find module: 'cluster'. Make sure this package is installed.

You can install this package by running: npm install cluster.

Opossum has an optional dependency on prom-client so it can export Prometheus metrics. Prometheus requires cluster, which is only available server-side:
https://nodejs.org/api/cluster.html

This dependency gets required depending on an environment variable WEB not being set:
https://github.com/nodeshift/opossum/blob/master/lib/circuit.js#L8-L10

Ideally we would just set this environment variable at build time, or on startup. But React App does not allow this:
facebook/create-react-app#6223

I also tried modifying the code to use process.env.REACT_APP_OPOSSUM and passing that in REACT_APP_OPOSSUM=true npm run build, but no luck... it might not accept environment variables at this stage, at all. Removing the import line seems to make it work again.

Not sure if there is another way to decouple the Prometheus concern from the Circuit Breaker, e.g. by using a wrapper object or something. Might also help to keep bundle sizes down... but that would definitely change your API quite a bit.

Any ideas?

Node.js Version: 10

Operating System: Mac OS

Steps to Produce Error:

git clone git@github.com:nodeshift-starters/opossum-examples.git
cd opossum-examples/react/client
npm install opossum@^3.0.0
npm run build
@alexstojda
Copy link

Thanks for that issue @tavogel, I am also experiencing this issue

@helio-frota
Copy link
Member

@tavogel thanks for report the issue.

This has relation with semver-major PR #350.

The Jquery example was updated to use opossum 3.0.0
It is using opossum.js directly from node_modules, I'm not sure but since jquery example don't have a build step maybe because that the example works.

I think that issues with browser will be fixed after #350 if a solution does not come before for the particular case of react usage.

@helio-frota
Copy link
Member

@tavogel @alexstojda The react example on opossum-examples is working with opossum 3.0.0

By using this way import circuitBreaker from 'opossum/dist/opossum';

https://github.com/nodeshift-starters/opossum-examples/blob/master/react/client/src/App.js#L2

Please let met know if it work for you

@lance
Copy link
Member

lance commented Aug 8, 2019

In my use, I have also added this to my webpack.config.json.

  externals: {
    'prom-client': 'prom-client'
  }

This will ensure that webpack ignores the prom-client imports.

@lance
Copy link
Member

lance commented Aug 13, 2019

@tavogel my PR #350 should land soon, externalizing these metrics, with a 4.0 release shortly after. I'm going to close this issue for now. Feel free to reopen if you are still having problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants