Giter VIP home page Giter VIP logo

vaslabs / talos Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 5.0 32.29 MB

Lawful circuit breakers for Scala. Akka and monix circuit breaker implementations with monitoring.

Home Page: https://talos.vaslabs.org/index.html

License: MIT License

Scala 99.65% CSS 0.04% Dockerfile 0.15% Shell 0.17%
scala akka-circuit-breaker akka monitoring kamon monix gateway bulkhead circuit-breaker monix-circuit-breaker circuitbreaker

talos's Introduction

talos Build Status Maven Central Codacy Badge Codacy Badge Docker hub Scala Steward badge

Talos is enforcing some theory from literature concerning circuit breakers in the form of typeclasses and laws.

Read more around the theory here

The main deliverable of Talos is fine grained monitoring.

Usage

Talos is modularised. You can twist it and pick the dependencies that fit your need. But let's go step by step.

libraryDependencies += "org.vaslabs.talos" %% "taloscore" % "2.1.0"
libraryDependencies += "org.vaslabs.talos" %% "talosakkasupport" % "2.1.0"
libraryDependencies += "org.vaslabs.talos" %% "taloskamon" % "2.1.0"

The events library provides a way to stream events on what's happening in the circuit breakers. E.g. combining with the talosakkasupport you can do:

import akka.actor.typed.{ActorSystem, ActorRef}
import akka.actor.typed.scaladsl.adapter._
import akka.pattern.CircuitBreaker
import cats.effect.IO
import talos.circuitbreakers.TalosCircuitBreaker
import talos.circuitbreakers.akka._

import scala.concurrent.duration._

def createCircuitBreaker(name: String = "testCircuitBreaker")
                      (implicit system: ActorSystem[_]): AkkaCircuitBreaker.Instance = {
    AkkaCircuitBreaker(
      name,
      CircuitBreaker(
        system.scheduler.toClassic,
        5,
        2 seconds,
        5 seconds
      )
    )
}

If you have an existing solution based on Akka circuit breaker and you can extract the circuit breaker like this.

    val akkaCB: CircuitBreaker = talosCircuitBreaker.circuitBreaker.unsafeRunSync()

Otherwise you can use the TalosCircuitBreaker typeclass directly

    val action: IO[Unit] = talosCircuitBreaker.protect(IO(println("Running inside the circuit breaker")))
    action.unsafeRunSync()

Talos also supports the CircuitBreaker from monix

Complete usage example

How to code can be found here: https://github.com/vaslabs/talos/blob/master/examples/src/main/scala/talos/examples/ExampleApp.scala

Laws

If you wish to implement your own TalosCircuitBreaker typeclasses you can test them against the laws library:

libraryDependencies += "org.vaslabs.talos" %% "taloslaws" % "2.1.0" % Test

Run the demo

  • Spin up the docker images provided:
cd examples
docker-compose up

You can see the kamon status here and the prometheus metrics are exposed here .

How Tos

  1. Setup docker to work with Kamon: Look at build.sbt, find dockerCommonSettings
  2. Setup logging: Look in the example module in the resources for the logback.xml file.

Architecture

alt text

Note: The hystrix reporter is no longer supported (last supported version 1.0.0)

talos's People

Contributors

codacy-badger avatar scala-steward avatar vaslabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

talos's Issues

Create a new UI

Maybe fork the hystrix dashboard but remove all unrelated to akka stuff.

Create talos gateway

Akka based gateway to protect microservices with bulkheading and circuit breakers

Enforce circuit breaker fallbacks with a talos law

  • On a command failure execute fallback

it is essential to involve the system’s stakeholders when deciding how to handle calls made when the circuit is open."
Michael T. Nygard. Release It!: Design and Deploy Production-Ready Software (Pragmatic Programmers). Pragmatic Bookshelf, 2007.

  • Fallbacks must be executed in a very short time - consider maximum timeout to be 100ms
    One of the reasons for failure is that systems may lack necessary resources to complete calls. By not constraining the fallback we are endangering the system in the same way of not having circuit breakers.

Add monitoring for "thread pools"

This will be an interesting challenge as we need to monitor the dispatcher used under the hood. Somehow.
And then get the kamon stats and convert them to meaningful stats for the circuit breaker dashboard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.