From 9e6cfdf9668157ec7ff566c670ce293b18d2bc83 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 May 2018 20:26:39 -0700 Subject: basic sentry; middleware; clacks-overhead --- golang/Gopkg.lock | 53 +++++++++++++++++++++++++++++++++++++- golang/cmd/fatcatd/main.go | 17 +++++++----- golang/restapi/configure_fatcat.go | 23 ++++++++++++++++- golang/restapi/doc.go | 1 - golang/restapi/embedded_spec.go | 6 ++--- golang/restapi/server.go | 3 +-- 6 files changed, 88 insertions(+), 15 deletions(-) diff --git a/golang/Gopkg.lock b/golang/Gopkg.lock index b35747f0..cf86e7aa 100644 --- a/golang/Gopkg.lock +++ b/golang/Gopkg.lock @@ -19,6 +19,27 @@ revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f" version = "v9" +[[projects]] + branch = "master" + name = "github.com/carbocation/interpose" + packages = [ + ".", + "adaptors" + ] + revision = "723534742ba3bbda66268b735aaa41634468acc6" + +[[projects]] + name = "github.com/certifi/gocertifi" + packages = ["."] + revision = "deb3ae2ef2610fde3330947281941c562861188b" + version = "2018.01.18" + +[[projects]] + name = "github.com/codegangsta/inject" + packages = ["."] + revision = "37d7f8432a3e684eef9b2edece76bdfa6ac85b39" + version = "v1.0-rc1" + [[projects]] name = "github.com/docker/go-units" packages = ["."] @@ -31,6 +52,18 @@ revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" version = "v1.4.7" +[[projects]] + branch = "master" + name = "github.com/getsentry/raven-go" + packages = ["."] + revision = "263040ce1a362270b5897a5982572ddc1fe807be" + +[[projects]] + name = "github.com/go-martini/martini" + packages = ["."] + revision = "49411a5b646861ad29a6ddd5351717a0a9c49b94" + version = "v1.0" + [[projects]] branch = "master" name = "github.com/go-openapi/analysis" @@ -139,6 +172,12 @@ ] revision = "8b799c424f57fa123fc63a99d6383bc6e4c02578" +[[projects]] + branch = "master" + name = "github.com/meatballhat/negroni-logrus" + packages = ["."] + revision = "31067281800f66f57548a7a32d9c6c5f963fef83" + [[projects]] branch = "master" name = "github.com/mitchellh/mapstructure" @@ -151,6 +190,12 @@ revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8" version = "v1.1.0" +[[projects]] + name = "github.com/pkg/errors" + packages = ["."] + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" + [[projects]] name = "github.com/sirupsen/logrus" packages = ["."] @@ -196,6 +241,12 @@ revision = "4654dfbb6ad53cb5e27f37d99b02e16c1872fbbb" version = "v1.2.15" +[[projects]] + name = "github.com/urfave/negroni" + packages = ["."] + revision = "5dbbc83f748fc3ad38585842b0aedab546d0ea1e" + version = "v0.3.0" + [[projects]] branch = "master" name = "golang.org/x/crypto" @@ -260,6 +311,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "807f92b935a836e9a4ad4bd98cfad104e6dda33965a78bde4cb6b822c4e6d135" + inputs-digest = "ca575bc9f4c9011b152d7815b930a1765b8e0da49ca551b346a1a2b4065516c4" solver-name = "gps-cdcl" solver-version = 1 diff --git a/golang/cmd/fatcatd/main.go b/golang/cmd/fatcatd/main.go index e98e0f79..c0b9a2e5 100644 --- a/golang/cmd/fatcatd/main.go +++ b/golang/cmd/fatcatd/main.go @@ -8,6 +8,7 @@ import ( loads "github.com/go-openapi/loads" flags "github.com/jessevdk/go-flags" "github.com/spf13/viper" + "github.com/getsentry/raven-go" "git.archive.org/bnewbold/fatcat/golang/restapi" "git.archive.org/bnewbold/fatcat/golang/restapi/operations" @@ -15,21 +16,25 @@ import ( func init() { + viper.SetDefault("port", 9411) + viper.SetDefault("verbose", true) + viper.SetEnvPrefix("FATCAT") viper.AutomaticEnv() - viper.SetDefault("Port", 9411) - viper.SetDefault("Verbose", true) + viper.SetConfigType("toml") viper.SetConfigName("fatcatd.toml") viper.AddConfigPath(".") - err := viper.ReadInConfig() - if err != nil { - log.Fatalf("Fatal error config file: %s \n", err) - } + //err := viper.ReadInConfig() + //if err != nil { + // log.Fatalf("Error loading config: %s \n", err) + //} // not default of stderr log.SetOutput(os.Stdout); + raven.SetDSN(viper.GetString("sentry_dsn")); + } func main() { diff --git a/golang/restapi/configure_fatcat.go b/golang/restapi/configure_fatcat.go index 418400fc..7398ad26 100644 --- a/golang/restapi/configure_fatcat.go +++ b/golang/restapi/configure_fatcat.go @@ -10,6 +10,10 @@ import ( runtime "github.com/go-openapi/runtime" middleware "github.com/go-openapi/runtime/middleware" graceful "github.com/tylerb/graceful" + "github.com/carbocation/interpose" + "github.com/carbocation/interpose/adaptors" + //"github.com/getsentry/raven-go" + "github.com/meatballhat/negroni-logrus" "git.archive.org/bnewbold/fatcat/golang/restapi/operations" ) @@ -67,5 +71,22 @@ func setupMiddlewares(handler http.Handler) http.Handler { // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. // So this is a good place to plug in a panic handling middleware, logging and metrics func setupGlobalMiddleware(handler http.Handler) http.Handler { - return handler + + middle := interpose.New() + + // sentry and upstream + //middle.UseHandler(sentry.Recovery(raven.DefaultClient, false)) + + // logging + negroniMiddleware := negronilogrus.NewMiddleware() + middle.Use(adaptors.FromNegroni(negroniMiddleware)) + + // add clacks + middle.UseHandler(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + rw.Header().Set("X-Clacks-Overhead:", "GNU Aaron Swartz, John Perry Barlow") + })) + + middle.UseHandler(handler) + + return middle } diff --git a/golang/restapi/doc.go b/golang/restapi/doc.go index 9896c2da..e18461a8 100644 --- a/golang/restapi/doc.go +++ b/golang/restapi/doc.go @@ -7,7 +7,6 @@ A scalable, versioned, API-oriented catalog of bibliographic entities and file m Schemes: http - https Host: api.fatcat.wiki BasePath: /v0 Version: 0.1.0 diff --git a/golang/restapi/embedded_spec.go b/golang/restapi/embedded_spec.go index 1b193eb9..6a6cf356 100644 --- a/golang/restapi/embedded_spec.go +++ b/golang/restapi/embedded_spec.go @@ -25,8 +25,7 @@ func init() { "application/json" ], "schemes": [ - "http", - "https" + "http" ], "swagger": "2.0", "info": { @@ -140,8 +139,7 @@ func init() { "application/json" ], "schemes": [ - "http", - "https" + "http" ], "swagger": "2.0", "info": { diff --git a/golang/restapi/server.go b/golang/restapi/server.go index a11c94c6..6fb4f3b9 100644 --- a/golang/restapi/server.go +++ b/golang/restapi/server.go @@ -15,11 +15,11 @@ import ( "sync/atomic" "time" - log "github.com/sirupsen/logrus" "github.com/go-openapi/runtime/flagext" "github.com/go-openapi/swag" flags "github.com/jessevdk/go-flags" graceful "github.com/tylerb/graceful" + log "github.com/sirupsen/logrus" // manual hack for now (bnewbold) "git.archive.org/bnewbold/fatcat/golang/restapi/operations" ) @@ -35,7 +35,6 @@ var defaultSchemes []string func init() { defaultSchemes = []string{ schemeHTTP, - schemeHTTPS, } } -- cgit v1.2.3