msuite

package module
v0.0.0-...-b7c645d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: MIT Imports: 7 Imported by: 3

README

go-msuite Go Go Reference Coverage Status DeepSource

Modular microservices framework in golang

Introduction

go-msuite aims to help bootstrap development of distributed applications in go. It does not add too many new components, but it a collection of a bunch of useful software already built and battle-tested. There are a bunch of defaults already present, however the library is built in such a way that we can plug-n-play different subsystems.

Features are mostly similar to other popular frameworks. The only difference is go-msuite uses libp2p underneath. Libp2p is a modular networking stack built for p2p applications. With Libp2p, we have the ability to add more transports underneath like QUIC, websockets etc. Apart from this, we get access to the DHT, which provides routing, discovery and even pubsub functionality.

For the public API please go through the core package

Features

  • Service lifecycle

    • go-msuite uses uber/fx for dependency injection and lifecycle management. This provides a simple Start/Stop type interface to developers to manage their apps
  • HTTP and gRPC endpoint

    • Most of the applications today use HTTP or RPC interface. gRPC being very popular and having a very broad ecosystem. go-msuite takes care of the lifecycle of your HTTP and gRPC servers, which can be used to register services/endpoints.
    • Naturally, a bunch of middlewares are implemented to take care of auth, tracing, metrics etc. This is again common stuff which needs to be re-implemented each time an application is built.
  • Libp2p and IPFS

    • A libp2p host is instantiated by go-msuite. It is possible to use existing keys or create new ones. Each application has access to libp2p-host and hence all the functionality that goes with it.
    • ipfs-lite is instantiated using the above libp2p host and the repository storage. This can be used to share data between different services in the form of files.
    • Pubsub and Discovery are also supported using libp2p.
  • RPC Transport

    • There are multiple transports available. Users can start go-msuite using just TCP/UDS transport as well, libp2p is completely optional. That said, gRPC services registered on go-msuite are available on all the transports that are configured.
    • Users can configure ports for different transports
  • Authentication

    • Authentication is added as first-class citizen. Currently a JWT-based implementation exists. User can enable it by providing a secret phase.
    • Access control is also present. Users can configure their APIs/Services to start using ACLs. These can be updated/removed etc.
  • Storage and SharedStorage

    • Currently a simple key-value store is available to all the services. This store uses a very generic K-V store interface gkvstore which allows users to define how they want to store the objects into the store. Different implementations can be added here in future.
    • Using IPFS and the above storage, we can use ants-db to have a distributed CRDT store across all the go-msuite instances. This is particularly useful to share state across all the instances running. Also it piggy-backs on the existing libp2p and IPFS instances that we already configure.
  • Taskmanager

    • This is a simple worker pool which can be used to run tasks asynchronously. taskmanager can be configured to have dedicated go-routines which handle tasks created by users. Tasks can be short/long. All the tasks are stopped on app close. Also there is way to show task progress on the diagnostic endpoint
  • Distributed locking

    • Distributed locking is useful when you have multiple instances of your services running. This way we can synchronize services across different machines. This component currently uses zookeeper/redis implementations which need to be managed separately.
  • Events

    • Simple event framework over libp2p Pubsub. This can be used inside apps to create and react to events and is configurable by users. It provides an easier message-based interface to send/react to things. The events should be idempotent as they can be fired on multiple receivers.
  • Protocols

    • Protocols service can be used to write request-response schemes over libp2p. This allows users to write libp2p protocols with a simple message-passing model. There is a protocol internally implemented to provide a naive service mesh functionality.
  • Diagnostics

    • HTTP endpoint for showing diagnostic information of go-msuite. This shows status of different servers and routines started by the user. Users can add information to this and observe it from the HTTP interface. If the routines are created using taskmanager, the Status interface of taskmanager can be used to print status of the workers on the HTTP endpoints.
    • pprof HTTP handlers can be enabled for debugging
    • prometheus HTTP handler can also be enabled if metrics is enabled. It should be possible to use the same registry to add metrics in user apps.
    • opentracing-tracer can be configured. Both the gRPC services and HTTP services will be able to use this. Additionally user can access the tracer to add more custom traces.
  • Service discovery

    • Each go-msuite instance or individual service can be started with a particular name. This name can be then used to connect to it from other go-msuite nodes. Currently, it uses libp2p discovery underneath as mentioned above.
    • A static configuration is also possible of the nodes and IP addresses are known in advance and libp2p is not configured.

Install

go-msuite works like a regular golang library. You can import it using go get. Currently there is no versioning, so you can get the master. Versioning will be added later if required.

go get github.com/plexsysio/go-msuite@master

Quickstart

	import github.com/plexsysio/go-msuite

	svc, err := msuite.New(
		msuite.WithServices("Hello", "World"),
		msuite.WithHTTP(8080),
		msuite.WithP2P(10000),
		msuite.WithGRPC("tcp", 10001),
		msuite.WithGRPC("p2p", nil),
	)

	// write your app which uses the different subsystems from svc
	err = yourApp.NewService(svc)
	if err != nil {
		fmt.Println("failed creating new service", err.Error())
		return
	}
	err = svc.Start(context.Background())
	if err != nil {
		fmt.Println("failed starting service", err.Error())
		return
	}
	<-svc.Done()
	svc.Stop(context.Background())

Examples

There is a separate repository which contains different services built using go-msuite.

Drawbacks and future work

  • Currently there are a LOT of dependencies. However, this is by design, as the project was designed to be like a kitchen-sink for building distributed applications. If there are adopters, we could converge on the features which are more important and others which could potentially be removed. There are multiple ways to reduce binary sizes, so this is not considered a deal-breaker at the moment.
  • Some of the libraries can be instantiated using plugins. This should only add them to the binaries if they are being used. Again, this is not a priority. But this would give a lot of benefits in some cases. For eg the redis/v8 client library adds about 19MB weight to the binary. This can be solved using the plugin approach.

License

MIT licensed

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) (core.Service, error)

Types

type BuildCfg

type BuildCfg struct {
	// contains filtered or unexported fields
}

type Option

type Option func(c *BuildCfg)

func WithAuth

func WithAuth(secret string) Option

func WithBootstrapNodes

func WithBootstrapNodes(addrs ...string) Option

func WithDebug

func WithDebug() Option

func WithFiles

func WithFiles() Option

func WithGRPC

func WithGRPC(nw string, id interface{}) Option

func WithHTTP

func WithHTTP(port int) Option

func WithLocker

func WithLocker(lkr string, cfg map[string]string) Option

func WithP2P

func WithP2P(port int) Option

func WithP2PPrivateKey

func WithP2PPrivateKey(key crypto.PrivKey) Option

func WithPrometheus

func WithPrometheus(useLatency bool) Option

func WithRepositoryRoot

func WithRepositoryRoot(path string) Option

func WithServiceACL

func WithServiceACL(acl map[string]string) Option

func WithServices

func WithServices(services ...string) Option

func WithStaticDiscovery

func WithStaticDiscovery(svcAddrs map[string]string) Option

func WithTaskManager

func WithTaskManager(min, max int) Option

func WithTracing

func WithTracing(name, host string) Option

Directories

Path Synopsis
Package core defines the core abstractions provided by msuite library
Package core defines the core abstractions provided by msuite library
modules

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL