• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Clojure
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Common basis for some of otto.de's clojure microservices

tesla-microservice

"If Edison had a needle to find in a haystack, he would proceed at once with the diligence of the bee to examine straw after straw until he found the object of his search." - Nikola Tesla

This is the common basis for some of otto.de's microservices. It is written in clojure using the component framework.

Clojars Project

Build Status Dependencies Status

Breaking changes

tesla-microservice is used for a number of different services now. Still it is a work in progress. See CHANGES.md for instructions on breaking changes.

Features included

  • Load configuration from filesystem.
  • Aggregate a status.
  • Execute functions with a scheduler
  • Reply to a health check.
  • Deliver a json status report.
  • Report to graphite using the metrics library.
  • Manage handlers using ring.
  • Optional auto-hot-reloading of changed source files
  • Shutdown gracefully. If necessary delayed, so load-balancers have time to notice.

Examples

  • A growing set of example applications can be found at tesla-examples.
  • David & Germán created an example application based, among other, on tesla-microservice. They wrote a very instructive blog post about it
  • Moritz created tesla-pubsub-service. It showcases how to connect components via core.async channels. Also the embedded jetty was replaced by immutant.

Scheduler

The scheduler wraps a thread-pool which can be used for scheduling tasks. It is based on overtones at-at project. To actually use it you have to pass the :scheduler as a dependency to the component in which it should be used. Afterwards you can schedule tasks using the overtone api like this:

(overtone.at-at/every 100 #(println "Hello world") (de.otto.tesla.stateful.scheduler/pool scheduler) :desc "HelloWord Task")

The overtone-pool wrapped by the scheduler can be configured by the config-entry :scheduler. (See overtone.at-at/mk-pool) By default the pool holds no threads.

app-status

The app-status indicates the current status of your microservice. To use it you can register a status function to it.

Here is a simple example for a function that checks if an atom is empty or not.

(de.otto.tesla.stateful.app-status/register-status-fun app-status #(status atom))

The app-status is injected under the keyword :app-status from the base system.

(defn status [atom]
      (let [status (if @atom :error :ok)
            message (if @atom "Atom is empty" "Atom is not empty")]
           (de.otto.status/status-detail :status-id status message)))

For further information and usages take a look at the: status library

Choosing a server

As of version 0.1.15 there is no server included any more directly in tesla-microservice. This gives you the freedom to a) not use any server at all (e.g. for embedded use) b) choose another server e.g. a non-blocking one like httpkit or immutant. The available options are:

Configuring

Applications build with tesla-microservices can be configured via edn-files, that have to be located in the class path.

For backwards compatibility, it is also possible to load config from properties-files. See below for noteworthy differences.

Order of loading and merging

  1. A file named default.edn is loaded as a resource from classpath if present.
  2. A file either named application.edn or overridden by the ENV-variable $CONFIG_FILE is loaded as a resource or, if that is not possible, from the filesystem.
  3. A file name local.edn is loaded from classpath if present.

The configuration hash-map in those files is loaded and merged in the specified order. Which mean configurations for the same key is overridden by the latter occurrence.

ENV-variables

In contrast to former versions of tesla-microservice ENV-variables are not merged into the configuration.

But you can easily specify ENV-variables, that should be accessible in your configuration:

{
 :my-app-secret  #ts/env [:my-env-dep-app-secret "default"]
}

ENV-variables are read with environ. To see which keyword represents which ENV-var have a look in their docs.

Configuring via properties files

For backwards compatibility, it is also possible to load config from properties-files. You'll have to pass {:property-file-preferred true} as a runtime config to the base-system. It is not possible to load individual environment variables when using properties config. Adding :merge-env-to-properties-config true to the runtime config will add all system properties and environment variables, overiding any config from files.

Reporters

Applications utilizing Tesla-Microservice can use iapetos prometheus client for monitoring. Metrics are send by reporters which can be configured using the :metrics keyword. Each configured reporter will start at system startup automatically.

See example configuration below for all supported reporters.

:metrics {:graphite            {:host             "localhost"
                                :port             "2003"
                                :prefix           "my.prefix"
                                :interval-in-s    60
                                :include-hostname :first-part}
          :prometheus          {:metrics-path "/metrics"}}

Automatic hot-reloading of changed source files

Restarting the whole system after a small change can be cumbersome. A tesla-microservice can detect changes to your source files and load them into a running server. Add this to your config, to check for changes on each request to your system:

{:handler {:hot-reload? true}}

Note: This should only be enabled in development mode. Use your local.edn to enable this feature safely. You can add a private.edn as well for personal configurations. This file should be added to your .gitignore.

Securing internal info endpoints

The Tesla-Microservice comes with endpoints that hold information about the internal state of your application. Those endpoints can be the app-status or even metrics (Prometheus, see above). To secure those endpoints you can provide an authentication-middleware to the base-system.

E.g.:

(defn auth-middleware [config handler-fn]
  (fn [request] (if (authenticated? config request) 
                  (handler-fn request)
                  {:status 401 :body "access denied"})))

(defn example-system [runtime-config]
  (-> (de.otto.tesla.system/base-system runtime-config auth-middleware))) 

Addons

The basis included is stripped to the very minimum. Additional functionality is available as addons:

More features will be released at a later time as separate addons.

FAQ

Q: Is it any good? A: Yes.

Q: Why tesla? A: It's a reference to the ingenious scientist and inventor.

Q: Are there alternatives? A: Yes. You might want to look at modularity.org, system and duct.

Initial Contributors

Christian Stamm, Felix Bechstein, Ralf Sigmund, Kai Brandes, Florian Weyandt

License

Released under Apache License 2.0 license.

More Repositories

1

recsys-dataset

🛍 A real-world e-commerce dataset for session-based recommender systems research.
Python
307
star
2

edison-microservice

Collection of independent libraries on top of Spring Boot to provide a faster setup of jvm microservices
Java
123
star
3

gitactionboard

GitactionBoard - Ultimate Dashboard for GithubActions.
Java
112
star
4

jlineup

An easy-to-use visual acceptance test tool to automatically detect design changes of your website. Works on the command line or as a web service.
Java
76
star
5

TRON

⚡️ Implementation of TRON: Transformer Recommender using Optimized Negative-sampling, accepted at ACM RecSys 2023.
Python
61
star
6

flummi

Flummi Elastic Search HTTP REST Client
Java
56
star
7

hmac-auth

HMAC authentication for RESTful web applications
Java
53
star
8

api-guidelines

A set of rules to build consistent and high quality REST and Async APIs at OTTO.
TypeScript
46
star
9

tech_manifest

OTTOs Tech Manifest
41
star
10

edison-hal

A library to parse and render application/hal+json documents in Java
Java
40
star
11

PyPruningRadixTrie

PyPruningRadixTrie - Python version of super fast Radix trie for prefix search & auto-complete
Python
36
star
12

TeamDojo

UI für verschiedene Reifegrad-Dimensionen
Java
31
star
13

nom

Tools for ignoring anomalies
Clojure
30
star
14

logsmith

trayicon to assume your favorite aws roles
Python
23
star
15

MultiTRON

🤹 MultiTRON: Pareto Front Approximation for Multi-Objective Session-Based Recommender Systems, accepted at ACM RecSys 2024.
Python
23
star
16

traefik-config-validator

Validator for your Traefik Proxy (https://doc.traefik.io/traefik/) configuration
Go
22
star
17

gatekeeper

Manages environments, regulates deploys, advises pipelines and facilitates communication.
JavaScript
16
star
18

synapse

A library to implement event-sourcing microservices
Java
15
star
19

threatmodeling-resources

14
star
20

enhanced-wickettester

Framework for comfortable testing of wicket pages and components.
Java
14
star
21

rstash

r[emote]stash: cli tool to stash your local changes in a temporary remote branch
Shell
14
star
22

tesla-examples

Examples for tesla-microservice
Clojure
12
star
23

b2b-design-system

Otto B2B Design System
TypeScript
11
star
24

trackrdrd

The Tracking Log Reader demon reads from the shared memory log of a running instance of Varnish, aggregates data logged in a specific format for requests and ESI subrequests, and forwards the data to a messaging system (such as ActiveMQ or Kafka).
C
8
star
25

github-actions-wait

github-actions-wait
Shell
8
star
26

leinsync

Plugin to synchronize the shared codebase between clojure projects
Clojure
8
star
27

tesla-xray

Clojure
7
star
28

kafka-messaging-e2ee

Java
6
star
29

esi-include-thymeleaf3-dialect

A Thymeleaf 3 Dialect for ESI Includes
Java
6
star
30

edison-jobtrigger

An application to trigger jobs in 'Edison' Microservices.
Java
6
star
31

edison-aws

Java
6
star
32

goo

A wrapper to the Iapetos clojure binding for the prometheus client
Clojure
5
star
33

terraform-provider-galapagos

Terraform Provider especially for OTTO Galapagos variant
Go
5
star
34

gradle-projectversion

Groovy
4
star
35

dr-test

Dr. Test helps you to generate random test data that satisfy your schema definitions
Go
4
star
36

marketplace-php-sdk

A PHP SDK for the OTTO marketplace APIs
PHP
4
star
37

lein-files-hash

Clojure
3
star
38

status

Simple clojure lib to aggregate status.
Clojure
3
star
39

oauth-token-filter

Java
3
star
40

retail-api-hub-documentation

3
star
41

tesla-httpkit

embedded httpkit server for tesla microservice
Clojure
3
star
42

babbage-microservice

Basic modules that are useful for JVM microservices on top of Spring Boot Webflux
Kotlin
2
star
43

jlineup-action

Dockerfile
2
star
44

purge-deprecated-workflow-runs

Remove github workflow runs from current repository
JavaScript
2
star
45

queuemock

This is a tool to help mocking services that listen to incoming messages and sending a response via SQS.
JavaScript
2
star
46

tesla-jetty

embedded jetty server for tesla-microservice
Clojure
2
star
47

datatables_php_tools

1
star
48

hal-odyssey

Embeddable HAL+JSON browser for Spring Boot applications
Java
1
star
49

gradle-plugin-classycle

A gradle plugin for the classycle dependency checker
Java
1
star