moleculerjs / moleculer-repl

REPL module for Moleculer framework
http://moleculer.services/docs/moleculer-repl.html
MIT License
27 stars 25 forks source link

Feature: `dcall` local node #65

Closed ccampanale closed 2 years ago

ccampanale commented 2 years ago

Description: Frequently, rather than roll out entirely new service versions, I and my team tend to address bugs or certain changes in existing services which are subsequently built and deployed. When developing locally, we have the ability to connect into a pre-production running system (with all of our microservices running) to run our modified services locally. To test changes, for example to an action, we would simply perform a directed call to the local node for the service/action. I find myself needing to do a lot of repetitive copy & pasting in order to dcall the local node rather than the older instances of similarly named services running in the system.

User story: As a developer using the Moleculer REPL console, I should be able to easily call the local node on which I am working without needing to copy and paste the node ID.

Examples: I can think of a few ways this could be done, assuming this is a feature you believe is worth implementing.

Example 1 - <nodeId> keywords:

One or more keywords (such as local or mlocal) could be provided as the <nodeId> for dcall and when detected, the broker instance provided to the REPL command would be used to determine the target node ID.

dcall local v1.service.action --param1 value

Pros: simple Cons: potential for overlap if a node in the system is already named "local".

Example 2 - --local option

An additional flag could be used which, when set, would allow for the <nodeId> argument to be undefined and would instead use the broker instance provided to the REPL command to determine the target node ID.

Pros: simple and avoid potential overlaps with node names in the system (from example 1) Cons: May introduce complexity with arguments and differentiating between the <nodeID> and <service/action> arguments since an option flag would be set but the <nodeId> argument not provided.


There may be other options to which I have not highlighted but ultimately something which simplifies dcalls to local nodes would be very helpful, I think.

I see pretty clearly where/how this change could be incorporated into the code, but didn't want to bother with a PR yet until I was sure this was both something you'd be willing to incorporate and got feedback on a desired approach.

Please let me know what you think.

AndreMaz commented 2 years ago

Hi @ccampanale

What's the REPL version that you're using?

we have the ability to connect into a pre-production running system (with all of our microservices running) to run our modified services locally.

I should be able to easily call the local node on which I am working without needing to copy and paste the node ID.

Can you please clarify how do you enter into REPL mode? Do you start (e.g., npm run dev) a ServiceBroker instance, with the services that you're working on, with REPL mode enabled? Or do you connect to the entire system via CLI (e.g., moleculer connect)?

ccampanale commented 2 years ago

Hey @AndreMaz

We are currently on moleculer-repl@0.7.0.

We have a highly customized startup process but it works a lot like the Moleculer runner; ultimately, if the right flags are set, etc. broker.repl(); is called in much the same way.

I'm mostly just curious if this is something you would be interested in as a feature of the dcall command and if you have any preferences on approach. I would't mind writing a PR when I get a chance.

ccampanale commented 2 years ago

Sorry, to better answer your questions:

AndreMaz commented 2 years ago

But often, the service instances locally, while sharing the same name as instances available on other nodes in the running system, is different do to local changes. This is where it would be convenient to be able to dcall local or dcall --local without needing to copy and paste the current Node ID (which changes with each new run).

Sorry, I’m a bit tired (and slow) at the moment.

What if you set the preferLocal to true in registry opts of the ServiceBroker that contains local services and runs your REPL instance? With this option the call command should call local actions (the ones that you want to trigger).

Again, sorry if I misunderstood your scenario.

ccampanale commented 2 years ago

No worries - this is not urgent so pleas take your time.

That's a great point and could certainly be done of the fly if needed.

I could always leverage preferLocal with something custom too if need be. I was originally going to shoe-horn the feature in via our custom work (possibly a custom REPL command, of which we have a few already) but figured I'd touch base with the maintainers first.

That said, I do believe that flexibility in the REPL CLI commands would be a great UX. But perhaps this doesn't align well with the intentions of the maintainers.

icebob commented 2 years ago

I think in dcall the nodeID can't be optional because actionName is followed which is required. So I think the --local option can be good. Could you create a PR?

ccampanale commented 2 years ago

@icebob

I agree - I think the complexity in trying to support nodeID as an optional argument is reason enough to avoid that path.

That being said, it sounds like adding --local to call might make more sense than adding to dcall as --local would be confusing while still needing to provide something for nodeID.

I can create a PR and send it over as soon as I get a chance to write it up and we can take it from there. Thanks!

icebob commented 2 years ago

I agree, thanks!

AndreMaz commented 2 years ago

Fixed https://github.com/moleculerjs/moleculer-repl/pull/66