Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

nodejs-express: new template #698

Merged
merged 1 commit into from
Apr 30, 2020
Merged

nodejs-express: new template #698

merged 1 commit into from
Apr 30, 2020

Conversation

sam-github
Copy link
Contributor

Fixes: #692
Related: #695

Checklist:

Modifying an existing stack:

  • Updated the stack version in stack.yaml

Contributing a new stack:

  • Describe how application dependencies are managed:

  • Explain how Appsody file watcher is utilized:

  • Describe other Appsody environment variables defined by the stack image:

  • Describe any limitations and known issues:

Related Issues:

@sam-github sam-github changed the title nodejs-kafka: (WIP) new stack nodejs-kafka: new stack Mar 4, 2020
@sam-github sam-github marked this pull request as ready for review March 5, 2020 00:02
@sam-github
Copy link
Contributor Author

@ianpartridge PTAL

Copy link
Contributor

@ianpartridge ianpartridge 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 awesome :) A few comments inline...

incubator/nodejs-express/image/project/Dockerfile Outdated Show resolved Hide resolved
incubator/nodejs-kafka/README.md Outdated Show resolved Hide resolved
incubator/nodejs-kafka/README.md Outdated Show resolved Hide resolved
incubator/nodejs-kafka/templates/default/app.js Outdated Show resolved Hide resolved
@sam-github
Copy link
Contributor Author

@neeraj-laad Not sure on your prefs -- should this start in experimental so it can be promoted later to incubator?

@sam-github
Copy link
Contributor Author

ping @neeraj-laad : #698 (comment)

@sam-github
Copy link
Contributor Author

Strange, node-rdkafka failed to build after master was merged into this branch. I'll look into it.

@neeraj-laad
Copy link
Contributor

@sam-github just curious to understand why is this stack inheriting from nodejs and not nodejs-express stack as it has node express and kafka?

@neeraj-laad
Copy link
Contributor

Regarding your earlier comment on experimental vs incubator. Appsody does not mandate that all stacks start as experimental. As long as you are willing to maintain and try to get it to stable. However, if we are not 100% sure if this is a good idea or taking shortcuts for some behaviour, then we can put this in experimental too.

@sam-github
Copy link
Contributor Author

just curious to understand why is this stack inheriting from nodejs and not nodejs-express stack as it has node express and kafka?

I'll see if I can slim the stack down via inheritance, but I'm not sure it matters. There don't look to be any layers that are fruitfully inherited. Dockerfiles still have to contain the same contents, the /package gets overwritten and has different contents, the templates are different, the READMEs are self-contained. If there was some way of making the lower-stack layers contain things that inherited stacks could just use, inheritance would be more meaningful, but either because of the nature of node.js apps, or just the nature of stacks that they have a top-level app contained in them that then delegates some things to the template, I don't see a lot of inheriting going on.

Even nodejs-express contains, AFAICT, basically just a verbatim copy of much of the contents of nodejs, even though it inherits from it.

But maybe the stacks weren't written with enough attention towards inheritance. I'll see.

@sam-github
Copy link
Contributor Author

I moved it to experimental because we don't know if we can commit to node-librdkafka for the longer term, even though it is best choice ATM.

I copied the recent changes from the other nodejs stacks to not update system or npm packages.

I'd prefer to leave the inheritance change, if it ends up being useful, to happen as part of a greater cleanup I'm working on.

@sam-github
Copy link
Contributor Author

OK, passing, PTAL @neeraj-laad

Copy link
Contributor

@andrewhughes101 andrewhughes101 left a comment

Choose a reason for hiding this comment

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

Ran through this stack and everything LGTM

Copy link
Collaborator

@Kamran64 Kamran64 left a comment

Choose a reason for hiding this comment

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

A few comments in line. I have very little knowledge of Kafka outside of some background reading done today. Just posted a few observations.

app.use('/live', health.LivenessEndpoint(healthcheck));
app.use('/ready', health.ReadinessEndpoint(healthcheck));
app.use('/health', health.HealthEndpoint(healthcheck));
app.use('/metrics', require('appmetrics-prometheus').endpoint());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spotted a similar bug here with the /metrics endpoint as described in #725, TLDR of the issue: Limited metrics output. Using the changes in #726 fixes the problem.

experimental/nodejs-kafka/templates/default/app.js Outdated Show resolved Hide resolved

1. A message may be posted into the default skeleton app. This could be done with `curl`:
```bash
curl -v -X POST -H "content-type: application/json" \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Running this command at first succeeds for me although eventually it looks like connection to the producer/consumer is lost:

[Container] {"level":50,"time":1584971907527,"pid":45,"hostname":"f4395b2e3ac3","msg":"error from consumer: Error: broker transport failure","v":1}
[Container] {"level":50,"time":1584971907527,"pid":45,"hostname":"f4395b2e3ac3","msg":"error from consumer: Error: all broker connections are down","v":1}

which then results in failures running this.

Also nit: You could cut out the use of the -X flag. Not a big deal but I get this note when running the command:

Note: Unnecessary use of -X or --request, POST is already inferred.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this problem too. Are you running the https://github.com/lensesio/fast-data-dev image that Sam suggested? I also tried using a docker-compose.yaml for Kafka that I had lying around, but that has the same problem.

@ianpartridge
Copy link
Contributor

Can I suggest we change the README away from the Lenses.io image, and use Docker Compose running Strimzi instead - https://github.com/scholzj/strimzi-compose-up

version: '2'

services:

  zookeeper:
    image: strimzi/kafka:0.15.0-kafka-2.3.1
    command: [
      "sh", "-c",
      "bin/zookeeper-server-start.sh config/zookeeper.properties"
    ]
    ports:
      - "2181:2181"
    environment:
      LOG_DIR: /tmp/logs

  kafka:
    image: strimzi/kafka:0.15.0-kafka-2.3.1
    command: [
      "sh", "-c",
      "bin/kafka-server-start.sh config/server.properties --override listeners=$${KAFKA_LISTENERS} --override advertised.listeners=$${KAFKA_ADVERTISED_LISTENERS} --override zookeeper.connect=$${KAFKA_ZOOKEEPER_CONNECT}"
    ]
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
    environment:
      LOG_DIR: "/tmp/logs"
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

@sam-github
Copy link
Contributor Author

READMEs don't usually describe how to setup the backend services, I think I should remove the note, anyone contemplating using Kafka should already have their favourite way to run it.

@sam-github
Copy link
Contributor Author

I'm still looking at how to fix this, but at this point I've convinced myself its a network config issue, I removed the appsody layer and just ran the scaffolded app.js locally on my host, and it works fine, but doesn't inside appsody run's docker container.

cf. https://www.confluent.io/blog/kafka-listeners-explained/, the 9092 port is reachable, the client connects, then drops the connection. I think we hit a variant of "Why can I connect to the broker, but the client still fails?".

@sam-github
Copy link
Contributor Author

sam-github commented Mar 24, 2020

@Kamran64 So, there are two issues here, the first of which seems a generic problem, how does someone usually run a container in development with appsody run and have it reach a dependent service that is also running in docker-for-desktop? This is kafka, but mysql, etc, would have the same issue AFAICT.

  • the appsody run container can't reach the containers started by docker-compose, they aren't on the same network, and appsody run --docker-options explicitly documents --network as not supported

On Linux, this works, because --net=host runs the container on the host network, but on docker-for-desktop it either does nothing, or runs it on the VM's "host" network, but that doesn't help the mac.

  • once run, the container needs to know its external name, and advertise it, this just needs adding to the kafka env, like this

The general recommendation here seems to be "use docker-compose", which I did, and it works, but not with appsody run. See docker-deploy.yaml, which assumes you've done a mkdir ex; cd ex; appsody init dev.local/nodejs-kafka; appsody build to create the image that will be run by docker-compose. You can curl it from the (mac) host.

The kube approach would be to deploy kafka and zookeeper into kube, create a service for kafka, and use that service name to connect from the appsody nodejs-kafka container (in production) and in dev, do the same, except do a kubectl port-forward to expose the kafka service onto the local host.

@sam-github
Copy link
Contributor Author

@neeraj-laad ^--- see above, what is appsody recommendation for a container run with appsody run on OS X docker-for-desktop to be able to reach a service in another container in docker-for-desktop? General recommendation is to "use docker-compose for local dev", but appsody is going a different direction.

Copy link
Contributor Author

@sam-github sam-github left a comment

Choose a reason for hiding this comment

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

@dalelane As a Kafka expert, could you give the sample code here a look to see if you think its reasonable? The template is loosely based on the event streams sample: https://github.com/ibm-messaging/event-streams-samples/tree/master/kafka-nodejs-console-sample

experimental/nodejs-kafka/templates/default/app.js Outdated Show resolved Hide resolved
experimental/nodejs-kafka/templates/default/app.js Outdated Show resolved Hide resolved
@sam-github
Copy link
Contributor Author

I'm still not a Kafka install expert, but @dalelane of the event team helps maintain https://github.com/strimzi/strimzi-kafka-operator#quickstart, perhaps we should link to it in the README?

@sam-github
Copy link
Contributor Author

https://github.com/appsody/stacks/blob/fc83e6b1722054f9b809337c57da5e41565c4341/incubator/java-spring-boot2/templates/kafka/README.md <--- perhaps this should be aligned with the java kafka stack in its README? And possibly in what it does in the default template?

@sam-github
Copy link
Contributor Author

@ianpartridge I see #742 landed, and they figured out how to use appsody run with kafka, I synced the instructions here with that PR.

PTAL

@sam-github sam-github changed the title nodejs-kafka: new stack nodejs-express: new template Apr 24, 2020
@sam-github
Copy link
Contributor Author

Turns out its become a requirement that all the kafkas be templates, I copied the README from the java-spring-boot2 (basically), and made this a template.

The libssl deps can only be added in the stack's dockerfile, and nodejs-express stack (and likely all of the nodejs stacks) doesn't support the user's app depending on compiled addons (permissions problems on the stack user's home directory, /root), which is why rdkafka was added as a dep of the image/project (fixing this bug in user setup is out of scope for this PR).

to: @ianpartridge

Copy link
Contributor

@ianpartridge ianpartridge left a comment

Choose a reason for hiding this comment

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

Looks good! Just a few notes inline.

Can we ship a sample docker-compose.yaml for Kafka in the template? Like this:

https://github.com/appsody/stacks/pull/775/files#diff-f8c1fd8a01a259e6ef300c40dce4a300

incubator/nodejs-express/templates/kafka/README.md Outdated Show resolved Hide resolved
incubator/nodejs-express/templates/kafka/package.json Outdated Show resolved Hide resolved
incubator/nodejs-express/templates/kafka/package.json Outdated Show resolved Hide resolved
incubator/nodejs-express/templates/kafka/package.json Outdated Show resolved Hide resolved
@sam-github
Copy link
Contributor Author

templates/kafka/package.json made consistent with templates/*/package.json

copied in docker-compose file

PTAL @ianpartridge

@ianpartridge ianpartridge added the stack/nodejs-express Issues related to nodejs-express stack label Apr 29, 2020
ianpartridge
ianpartridge previously approved these changes Apr 29, 2020
Copy link
Contributor

@ianpartridge ianpartridge left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@sam-github
Copy link
Contributor Author

@neeraj-laad Can you land?

Copy link
Collaborator

@Kamran64 Kamran64 left a comment

Choose a reason for hiding this comment

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

Gave it another a quick runthrough. LGTM.

Copy link
Collaborator

@Kamran64 Kamran64 left a comment

Choose a reason for hiding this comment

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

Whoops sorry - this needs a bump in the stack.yaml otherwise travis won't pick it up for release.

@neeraj-laad
Copy link
Contributor

Once we bump the stack version, this is good to go

@sam-github
Copy link
Contributor Author

@Kamran64 done

Copy link
Collaborator

@Kamran64 Kamran64 left a comment

Choose a reason for hiding this comment

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

LGTM - Will merge once the build finishes

@Kamran64 Kamran64 merged commit fc67941 into appsody:master Apr 30, 2020
@sam-github sam-github deleted the nodejs-kafka-stack branch April 30, 2020 15:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stack/nodejs-express Issues related to nodejs-express stack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nodejs: add a stack for Kafka
6 participants