npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trooba-bootstrap

v0.1.1

Published

bootstrap trooba pipeline from json configuration

Downloads

7

Readme

trooba-bootstrap

Greenkeeper badge

Bootstrap Trooba pipeline from configuration file.

codecov Build Status NPM Downloads Known Vulnerabilities

This functionality is important when one needs to scale to 100+ applications.

The idea is it is always easy to inject new configuration than ask applications developers of more than 100+ applications/teams to update their code to meet new service requirements. This also allows to provide default configurations by platform team.

Install

$ npm install trooba-bootstrap -S

Usage

Configuration

Configuration has two main artifacts:

  • Handlers profile definition is where platform team would define all handlers that can be used to build pipelines and their default configuration if any.

  • Service client or endpoint configuration is actual configuration used by application developer to define specific configuration for service clients and/or endpoints.

Handlers profile declaration

The definition specifies a path to the module, execution priority (specifies position priority) and default configuration if needed.

// define profiles for easy reference in pipeline definitions
const profiles = {
    // default profile to be used if no profile specified
    "default": {
        "trace": {
            // Priority defines execution order
            "priority": 10,
            "module": "trooba-opentrace"
        },
        "circuit": {
            "priority": 20,
            // module that provide circuit breaker functionality
            "module": "trooba-hystrix-handler",
            // default configuration
            "config": {
                "timeout": 0,
                "circuitBreakerErrorThresholdPercentage": 50
            }
        },
        "retry": {
            "priority": 30,
            "module": "trooba-retry" // TBD (to be defined/implemented)
        },
        "http-transport": {
            "transport": true,
            "module": "trooba-http-transport"
        }
    },
    // profile for soap service calls
    "soap": {
        "trace": {
            // Priority defines execution order
            "priority": 10,
            "module": "trooba-opentrace"
        },
        "circuit": {
            "priority": 20,
            // module that provide circuit breaker functionality
            "module": "trooba-hystrix-handler",
            // default configuration
            "config": {
                "timeout": 0,
                "circuitBreakerErrorThresholdPercentage": 70
            }
        },
        "retry": {
            "priority": 30,
            "module": "trooba-retry" // TBD (to be defined/implemented)
        },
        // We added new handler that adopts XML request to http request
        "soap": {
            "priority": 40,
            "module": "trooba-soap" // TBD
        }
        "http-transport": {
            "transport": true,
            "module": "trooba-http-transport"
        }
    }
}
Service client or endpoint configuration

This section would declare a configuration for a specific pipeline. For example, we can have one configuration to make service calls to one service 'foo' and other for service 'bar'.

The pipeline configuration can provide specific configurations for every handler if needed. This config will override default configuration properties for the given handler or transport.

const clients = {
    // id of the pipe
    "my-service-rest-client": {
        // since no profile given, it will use default profile
        // "$profile": "default",
        // custom configuration for handlers and pipe overall
        "circuit": {
            "config": {
                // modify circuit breaker property from 50 to 70
                "circuitBreakerErrorThresholdPercentage": 70
            }
        },
        "retry": {
            // change priority
            "priority": 35,
            "config": {
                // set retry to 3
                "retry": 3
            }
        },
        // provide transport service configuration
        // one can also provide this via pipe.context if transport understands it
        "http-transport": {
            "config": {
                "context": "my-app-http-context",
                "hostname": "localhost",
                "port": 8000,
                "protocol": "http:",
                "path": "/view/item",
                "socketTimeout": 2000
            }
        }
    },
    "my-service-soap-client": {
        // uses soap profile
        "$profile": "soap",
        // provide custom configuration for transport
        "http-transport": {
            "config": {
                "context": "my-app-http-context",
                "hostname": "localhost",
                "port": 8000,
                "protocol": "http:",
                "path": "/view/item",
                "socketTimeout": 2000
            }
        }
    },
    // we can extend existing profile for the service
    "my-service-extend-client": {
        // define custom pipeline
        "$profile": "soap",
        // adding custom metrics handler
        "metrics": {
            // want to go as close as possible to the transport in the pipeline
            "priority": 1000,
            "module": "metrics-module"
        },
        // configure transport
        "http-transport": {
            "config": {
                "context": "my-app-http-context",
                "hostname": "localhost",
                "port": 8000,
                "protocol": "http:"
            }
        }
    }
}
Bootstrapping from config
const provider = require('trooba-bootstrap')(profiles, clients);

// Update route: if handler is already there, it will override it
// This can be used to listen to config changes and updating it on the fly
Provider.updateProfiles(profiles);

// if client is already there, it will override it
// This also can be used to listen to config changes and updating it on the fly
Provider.updatePipes(clients);

// Create a client and make a call
Provider.createClient('my-service-rest-client');
    .create({ 'some': 'context' })
    .request({foo:'bar'}, console.log);
Sharing handlers between middleware and service invocation pipelines.

In this case one needs to be aware of a few differences:

  • The handler priorities may need to be different.
  • The transport always goes first and then the handlers in execution order.
  • Client configs become routes for incoming traffic.
  • Some of the handlers may not be needed or new ones needs to be added.

The above requirements may require to re-define priorities for the routes.

Define middleware for the incoming traffic
const profiles = {
    "default": {
        "http-transport": {
            "config": {
                // default ports
                "port": [8000, 8443]
            }
        },
        "router-match": {
            "priority": 0,
            "module": "trooba-http-router/matcher"  // TBD
        },
        "retry": {},
        "router-invoke": {
            "priority": 1000,
            "module": "trooba-http-router/invoker" // TBD
        }
    }
};

const middleware = {
    "my-service": {
        // this will use default profile
        "$profile": "default",
        // pipe handlers
        "http-transport": {
            "config": {
                "context": "my-app-http-context"
            }
        },
        // provide our specific routes
        "router-match": {
            "config": {
                "routes": "./routes.json"
            }
        },
        // adding some of our own middleware
        "jsonParser": {
            "priority": 50
        },
        "cookies": {
            "priority": 60,
            "module": "cookies-module"
        },
        "trace": {
            // turn off tracer
            "enabled": false
        }
    }
};

const provider = require('trooba-bootstrap')(profiles, middleware);

// Create a service instance
// for example, you can look at grpc service: https://github.com/trooba/trooba-grpc-transport#trooba-based-service
const app = Provider.createService('my-service');
// Note: listen method is provided by custom API injected by transport
app.listen(8000, () => {
    console.log('The server is ready');
})