Giter Site home page Giter Site logo

zalando / friboo Goto Github PK

View Code? Open in Web Editor NEW
117.0 117.0 16.0 604 KB

Utility library for writing microservices in Clojure, with support for Swagger and OAuth

License: Apache License 2.0

Clojure 52.04% CSS 11.45% JavaScript 22.95% HTML 12.87% Shell 0.69%
clojure microservices swagger swagger-api

friboo's People

Contributors

dixel avatar dryewo avatar hjacobs avatar immoh avatar jvtrigueros avatar oporkka avatar prayerslayer avatar sarnowski avatar sebastianpoeplau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

friboo's Issues

Something's not right with 1.4.0 artifact

Reproducible by:

  • Delete ~/.m2/repository to wipe maven cache
  • lein new app wtf
  • Put this in wtf.core-test:
(ns wtf.core-test
  (:require [clojure.test :refer :all]
            [wtf.core :refer :all]
            [clj-time.core :as t]
            [amazonica.aws.s3 :as s3]
            [org.zalando.stups.friboo.system.audit-log :as audit]))

(def mock-log
  {:status 200
   :logged-on (t/now)
   :tokeninfo {"uid" "test"}})

(deftest test-audit-log
  (with-redefs [s3/put-object (constantly "OK")]
    (audit/store-audit-logs! (ref [mock-log]) "bucket")))

Yields:

lein test wtf.core-test
WARN  [main] o.z.s.f.s.audit-log - Could not store audit logs because of ["clojure.lang.ArityException: Wrong number of args (1) passed to: format/unparse"].

Ran 1 tests containing 0 assertions.
0 failures, 0 errors.

This should not happen. If you take a look at store-audit-logs! you'll see that the line containing unparse wasnโ€™t modified since July. Also the line is hit by unit tests without problems.

Maybe just rebuild and rerelease?

Log warning if handler function returns no status code

Improvement, additional validation. If handler returns empty response (e.g. nil) no response status is available for statistic's metrics. This causes confusing statistic's metrics like 'some.id..POST' while ''some.id.200.POST'' is expected. I suggest log a warning in this case to help with diagnostics.

Probably this can be implemented as separate middleware but I think simplest ways is just to check this directly in add-metrics-filter inside (swap! status (fn [_] (.getStatus (cast HttpServletResponse response))))

Log modifying REST calls to S3 bucket

Optional feature for HTTP servers:

All successfully executed, modifying HTTP requests (PUT, POST, PATCH, DELETE, ....) should be logged to an S3 bucket.

The bucket name, file prefix and flush interval should be configurable by environment variables.

Provide dependencies as a map

A suggestion:
Instead of providing dependencies as independent parameters:

(defn get-status [params request db tokens]
  ...)

Provide them as a map:

(defn get-status [params request {:keys [db tokens] :as deps}]
  ...)

Not all the dependencies are relevant for every handler function, having to maintain dependency additions and removals is annoying.
Order of dependencies does not matter.

Use namespaced keywords for system map components

In the org.zalando.stups.friboo.system/http-system-map some components are provided by default. They use keyword names that can collide with components defined by the framework user.
It would make sense to use less popular names (:org.zalando.stups.friboo.system/api instead of :api) for them.

Unzip Clair messages

Look at CLAIR.CONTENTTYPE MessageAttribute, if it's "application/base64gzip", then unbase64 and ungzip the Message.

Sensitive information should be masked out when logging the configuration

Sensitive information such as passwords, keys or other credentials should be "masked out" when logging configuration data (e.g. https://github.com/zalando-stups/friboo/blob/master/src/org/zalando/stups/friboo/config.clj#L46). Even when logging only with DEBUG level, it might be better to be on the safe side (any "temporary enabled" log will appear in a central logging service).

Proposed solution:

(defn- is-sensitive-key [k]
  (or (.contains (name k) "pass") (.contains (name k) "private")))

(defn mask [config]
  "Mask sensitive information such as passwords"
  (into {} (for [[k v] config] [k (if (is-sensitive-key k) "MASKED" v)])))

Pull apart HTTP and API

Currently notions of HTTP serving and API handling are complected together in the def-http-component and http-system-map functions. Clearly, there should be separate components:

  • Http component takes care of serving HTTP requests on the configured port. Uses configuration with :http- prefix.
  • Api component takes care of calling the corresponding handler functions according to the API spec. Uses application-specific configuration with :api- prefix.

Docker image building doesn't work out of the box when using project template

There's a problem in building docker image when using project template:

  • lein-scm-source creates scm-source.json in target dir. In project.clj target-path is set to target/%s so the location of the file is something like target/base+system+user+dev/scm-source.json
  • Dockerfile expects scm-source.json to be in the root of the project

I guess the obvious fix is to change lein-scm-source to generate in project root instead, or make it configurable and preconfigure it in the template. I am happy to provide a PR if you think this is the correct fix.

Automate documentation generation

After #91.

During each normal Travis build (when TRAVIS_PULL_REQUEST is false), generate project documentation and publish it with Github Pages under the corresponding branch subfolder.

More flexible audit logging

Hi there!

I'm not completely happy with the audit logging in friboo. The way it currently works is storing all successful (2xx) responses to PUT/POST/PATCH/DELETE requests, which is very unflexible and low-level.

Sometimes your audit logs involve data that's not in a HTTP body, you may want to ship it somewhere else than S3 (file, database, REST API...) and so forth.

I don't have a good idea yet how to do this in a good and simple way. Maybe one could (mis?)use timbre to have already an ecosystem for appenders available and/or easily plug custom ones?

Do not use undocumented Clojure features in template project

Generated project.clj uses undocumented #= reader macro. I would suggest to use enclosing let instead, use hard-code some value or, better yet, make it a template's parameter (since current code makes too many assumptions about environment).

let version would look like

(let [docker-image-name (some-> (str (System/getenv "DEFAULT_DOCKER_REGISTRY") "/")
                                                     "example_team/maratus"))]
  (defproject ...
    ))

BTW, why (str "/") is needed in generated project.clj file?

When an exception is thrown during system start, it does not get cleaned up.

This concerns only reloaded workflow.

For example, if I mess something up with the database and run (reset), it throws an exception during DB component startup.
After that, I fix the issue and run (reset) again. Now it refuses to start, because the HTTP port is already taken, previous instance of Http component is still running somewhere. (stop) does not help. The only solution here is to restart the REPL, which takes ~20s.

Would be nice to have roll-back functionality.

Upgrade swagger ui

A new Swagger UI has just been released, but Friboo is still some releases behind.

Dependencies for HTTP component have to be specified twice

First in the component definition:

(def-http-component Http "api.yaml" [db tokens])

Then in the system map:

(system/http-system-map configuration
                        map->Http [:db :tokens]
                        :db (db/make-db (:db configuration))
                        :tokens (oauth2/map->OAUth2TokenRefresher ...))

Maintaining these two places is error-prone and non-beginner-friendly.
This also relates to #48.

Provide more info when no operation found

Currently (as of 1.4.0) it does not report the operation name which is not found. Would be nice to have.

ExceptionInfo no operation found  clojure.core/ex-info (core.clj:4593)

Add zookeeper component

Enables applications to automatically use zookeeper in order to for example do locking or member discovery.

Add cron scheduler component

Add a cron scheduler component with which you can scheduler functions, leveraging dependency injection similar to the http component.

Hint: integrate with #2 in order to allow :local or :global locking of jobs

Provide runtime REPL

During runtime, the application should open a nREPL port and provide REPL access to the running app.

Is it possible to get rid of log messages?

When the code is loaded (even for uberjar building), the following messages appear:

INFO  [main] o.e.j.u.log - Logging initialized @14782ms
WARN  [main] c.n.c.s.URLConfigurationSource - No URLs will be polled as dynamic configuration sources.
INFO  [main] c.n.c.s.URLConfigurationSource - To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
INFO  [main] c.n.c.DynamicPropertyFactory - DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@2f0765f7

Is it possible to make them appear when the system is started, not on class load?

Add /.health endpoint

Add a standard endpoint /.health that returns 200 by default and can optionally be configured with a function, returning a boolean to indicate health (custom application logic).

Audit logging does not work

Log excerpt from a pierone instance:

WARN [pool-2-thread-1] o.z.s.f.s.http - Could not store audit logs because of ["java.lang.Exception: Don't know how to write JSON of class org.eclipse.jetty.server.HttpInput"].

Move Zalando specific components to a separate library

As we are driving Friboo to be generally useful, we should not include components like MgmtHTTP, Metrics, AuditLog or OAuth2TokenRefresher in the default package and of course not in the default system configuration.
Thanks to the component approach, those can easily be moved to a dedicated Zalando specific library.

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.