From ba5c3f4e3758e40e0ab08de7ed19fc6f6329aa25 Mon Sep 17 00:00:00 2001 From: Luc Claustres Date: Fri, 23 Oct 2020 08:59:22 +0200 Subject: [PATCH 1/5] Added link to slack third-party module --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6238f0c7..4f52ae24 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,7 @@ The standard distribution of logspout comes with all modules defined in this rep * [logspout-redis-logstash](https://github.com/rtoma/logspout-redis-logstash) * [logspout-gelf](https://github.com/micahhausler/logspout-gelf) for Graylog * [logspout-fluentd](https://github.com/dsouzajude/logspout-fluentd) for fluentd or fluent-bit - instead of using fluentd log driver - + * [logspout-slack](https://github.com/kalisio/logspout-slack) for [Slack](https://slack.com/) notifications ### Loggly support From d42a095f000fd52aa2f0cfa9f4e0178519be113f Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 26 Nov 2020 12:34:14 -0700 Subject: [PATCH 2/5] bump golangci-lint to 1.27 and fix lintballs --- .golangci.yml | 8 +++++++- Makefile | 2 +- adapters/multiline/multiline.go | 19 ++++++++++--------- httpstream/httpstream.go | 12 +++++++----- router/persist.go | 2 +- router/pump.go | 15 ++++++++------- transports/tls/tls.go | 2 +- transports/tls/tls_test.go | 2 -- 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e97b1d9f..da9f65df 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,6 +47,12 @@ linters: - gochecknoglobals - funlen - gochecknoinits + - godot + - wsl + - nolintlint + - testpackage + - dupl + - goerr113 issues: # Excluding configuration per-path, per-linter, per-text and per-source @@ -71,7 +77,7 @@ run: # golangci.com configuration # https://github.com/golangci/golangci/wiki/Configuration service: - golangci-lint-version: 1.18.x # use the fixed version to not introduce new linters unexpectedly + golangci-lint-version: 1.27.x # use the fixed version to not introduce new linters unexpectedly prepare: - echo "here I can run custom commands, but no preparation needed for this repo" diff --git a/Makefile b/Makefile index 2bf17370..e9ca6e82 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ VERSION=$(shell cat VERSION) MAX_IMAGE_SIZE := 40000000 GOBIN := $(shell go env GOPATH | awk -F ":" '{ print $$1 }')/bin -GOLANGCI_LINT_VERSION := v1.18.0 +GOLANGCI_LINT_VERSION := v1.27.0 ifeq ($(shell uname), Darwin) XARGS_ARG="-L1" diff --git a/adapters/multiline/multiline.go b/adapters/multiline/multiline.go index d2c1d3e3..b24e620b 100644 --- a/adapters/multiline/multiline.go +++ b/adapters/multiline/multiline.go @@ -15,10 +15,11 @@ import ( ) const ( - matchFirst = "first" - matchLast = "last" - matchNonFirst = "nonfirst" - matchNonLast = "nonlast" + matchFirst = "first" + matchLast = "last" + matchNonFirst = "nonfirst" + matchNonLast = "nonlast" + defaultFlushAfter = 500 * time.Millisecond ) func init() { @@ -89,7 +90,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) { return nil, errors.New("multiline: invalid value for MULTILINE_MATCH (must be one of first|last|nonfirst|nonlast): " + matchType) } - flushAfter := 500 * time.Millisecond + flushAfter := defaultFlushAfter flushAfterStr := os.Getenv("MULTILINE_FLUSH_AFTER") if flushAfterStr != "" { timeoutMS, errConv := strconv.Atoi(flushAfterStr) @@ -100,7 +101,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) { } parts := strings.SplitN(route.Adapter, "+", 2) - if len(parts) != 2 { + if len(parts) != 2 { //nolint:gomnd return nil, errors.New("multiline: adapter must have a sub-adapter, eg: multiline+raw+tcp") } @@ -117,7 +118,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) { route.Adapter = originalAdapter out := make(chan *router.Message) - checkInterval := flushAfter / 2 + checkInterval := flushAfter / 2 //nolint:gomnd return &Adapter{ out: out, @@ -135,7 +136,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) { } // Stream sends log data to the next adapter -func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo +func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo,gocognit wg := sync.WaitGroup{} wg.Add(1) go func() { @@ -165,7 +166,7 @@ func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo cID := message.Container.ID old, oldExists := a.buffers[cID] - if a.isFirstLine(message) { + if a.isFirstLine(message) { //nolint:nestif if oldExists { a.out <- old } diff --git a/httpstream/httpstream.go b/httpstream/httpstream.go index dc2fb894..e6af8670 100644 --- a/httpstream/httpstream.go +++ b/httpstream/httpstream.go @@ -14,6 +14,8 @@ import ( "github.com/gliderlabs/logspout/router" ) +const maxRouteIDLen = 12 + func init() { router.HTTPHandlers.Register(LogStreamer, "logs") } @@ -35,8 +37,8 @@ func LogStreamer() http.Handler { switch params["predicate"] { case "id": route.FilterID = params["value"] - if len(route.ID) > 12 { - route.FilterID = route.FilterID[:12] + if len(route.ID) > maxRouteIDLen { + route.FilterID = route.FilterID[:maxRouteIDLen] } case "name": route.FilterName = params["value"] @@ -83,10 +85,10 @@ func (c Colorizer) Get(key string) string { i = c[key] } bright := "1;" - if i%14 > 6 { + if i%14 > 6 { //nolint:gomnd bright = "" } - return "\x1b[" + bright + "3" + strconv.Itoa(7-(i%7)) + "m" + return "\x1b[" + bright + "3" + strconv.Itoa(7-(i%7)) + "m" //nolint:gomnd } func marshal(obj interface{}) []byte { @@ -134,7 +136,7 @@ func httpStreamer(w http.ResponseWriter, req *http.Request, logstream chan *rout if req.URL.Query().Get("sources") != "" && logline.Source != req.URL.Query().Get("sources") { continue } - if usejson { + if usejson { //nolint:nestif w.Write(append(marshal(logline), '\n')) } else { if multi { diff --git a/router/persist.go b/router/persist.go index c86d06e2..59ad5265 100644 --- a/router/persist.go +++ b/router/persist.go @@ -51,7 +51,7 @@ func (fs RouteFileStore) GetAll() ([]*Route, error) { // Add writes a marshaled *Route to the RouteFileStore func (fs RouteFileStore) Add(route *Route) error { - return ioutil.WriteFile(fs.Filename(route.ID), marshal(route), 0644) + return ioutil.WriteFile(fs.Filename(route.ID), marshal(route), 0600) } // Remove removes route from the RouteFileStore based on id diff --git a/router/pump.go b/router/pump.go index d1586493..28e78083 100644 --- a/router/pump.go +++ b/router/pump.go @@ -22,6 +22,7 @@ const ( pumpEventStatusRenameName = "rename" pumpEventStatusDieName = "die" trueString = "true" + pumpMaxIDLen = 12 ) var ( @@ -66,8 +67,8 @@ func normalName(name string) string { } func normalID(id string) string { - if len(id) > 12 { - return id[:12] + if len(id) > pumpMaxIDLen { + return id[:pumpMaxIDLen] } return id } @@ -101,7 +102,7 @@ func ignoreContainer(container *docker.Container) bool { for _, label := range excludeLabelArr { labelParts := strings.Split(label, ":") - if len(labelParts) == 2 { + if len(labelParts) == 2 { //nolint:gomnd excludeLabel = labelParts[0] excludeValue = labelParts[1] } @@ -321,8 +322,8 @@ func (p *LogsPump) Route(route *Route, logstream chan *Message) { if route.MatchContainer( normalID(pump.container.ID), normalName(pump.container.Name), - pump.container.Config.Labels) { - + pump.container.Config.Labels, + ) { pump.add(logstream, route) defer pump.remove(logstream) } @@ -344,8 +345,8 @@ func (p *LogsPump) Route(route *Route, logstream chan *Message) { if route.MatchContainer( normalID(event.pump.container.ID), normalName(event.pump.container.Name), - event.pump.container.Config.Labels) { - + event.pump.container.Config.Labels, + ) { event.pump.add(logstream, route) defer event.pump.remove(logstream) } diff --git a/transports/tls/tls.go b/transports/tls/tls.go index 297dfdc6..d533a956 100644 --- a/transports/tls/tls.go +++ b/transports/tls/tls.go @@ -97,7 +97,7 @@ func createTLSConfig() (tlsConfig *tls.Config, err error) { tlsConfig = &tls.Config{} // use stronger TLS settings if enabled - // TODO: perhaps this should be default setting + // perhaps this should be default setting @gbolo if os.Getenv(envTLSHardening) == trueString { tlsConfig.InsecureSkipVerify = false tlsConfig.MinVersion = hardenedMinVersion diff --git a/transports/tls/tls_test.go b/transports/tls/tls_test.go index 08da2c2f..ec940489 100644 --- a/transports/tls/tls_test.go +++ b/transports/tls/tls_test.go @@ -38,7 +38,6 @@ func TestEmptyTrustStore(t *testing.T) { if numOfTrustedCerts != 0 { t.Fatalf("expected 0 RootCAs but got: %d", numOfTrustedCerts) } - } // TestSingleCustomCA should test the behavior of loading @@ -52,7 +51,6 @@ func TestSingleCustomCA(t *testing.T) { if !bytes.Contains(testTLSConfig.RootCAs.Subjects()[0], []byte(caRootCertSubjectCN)) { t.Errorf("failed to load custom root CA into trust store: %s", caRootCertFileLocation) } - } // TestMultipleCustomCAs should test the behavior of loading From 7282c364d6ebd7866e0d7597a74b9d9e7ba47ce4 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 26 Nov 2020 12:46:02 -0700 Subject: [PATCH 3/5] fix backlog() logic and add tests --- router/pump.go | 2 +- router/pump_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/router/pump.go b/router/pump.go index 28e78083..e5dde683 100644 --- a/router/pump.go +++ b/router/pump.go @@ -46,7 +46,7 @@ func debug(v ...interface{}) { } func backlog() bool { - return os.Getenv("BACKLOG") == "false" + return os.Getenv("BACKLOG") == trueString } func setAllowTTY() { diff --git a/router/pump_test.go b/router/pump_test.go index 73dab44c..4fb14da3 100644 --- a/router/pump_test.go +++ b/router/pump_test.go @@ -268,3 +268,22 @@ func TestPumpRoutingFrom(t *testing.T) { t.Errorf("expected RoutingFrom to return 'false'") } } + +func TestPumpBacklog(t *testing.T) { + os.Unsetenv("BACKLOG") + if backlog() != false { + t.Errorf("expected backlog() to return 'false'") + } + os.Setenv("BACKLOG", "false") + if backlog() != false { + t.Errorf("expected backlog() to return 'false'") + } + os.Setenv("BACKLOG", "true") + if backlog() != true { + t.Errorf("expected backlog() to return 'true'") + } + os.Unsetenv("BACKLOG") + if backlog() != false { + t.Errorf("expected backlog() to return 'false'") + } +} From dd11cfae932d2169d772167a661de56adf325361 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 26 Nov 2020 13:08:59 -0700 Subject: [PATCH 4/5] release 3.2.13 --- CHANGELOG.md | 11 ++++++++++- VERSION | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5639c991..0bc587ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ All notable changes to this project will be documented in this file. ### Changed + +## [v3.2.13] - 2020-11-26 +### Changed +- @michaelshobbs bump golangci-lint to 1.27 and fix lintballs + +### Fixed +- @michaelshobbsfix backlog() logic and add tests + ## [v3.2.12] - 2020-10-22 ### Changed - @michaelshobbs bump alpine to 3.12 @@ -247,7 +255,8 @@ All notable changes to this project will be documented in this file. - Base container is now Alpine - Moved to gliderlabs organization -[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.2.12...HEAD +[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.2.13...HEAD +[v3.2.13]: https://github.com/gliderlabs/logspout/compare/v3.2.12...v3.2.13 [v3.2.12]: https://github.com/gliderlabs/logspout/compare/v3.2.11...v3.2.12 [v3.2.11]: https://github.com/gliderlabs/logspout/compare/v3.2.10...v3.2.11 [v3.2.10]: https://github.com/gliderlabs/logspout/compare/v3.2.9...v3.2.10 diff --git a/VERSION b/VERSION index c5016ea8..b68118d2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.2.12 +v3.2.13 From 99f410a90c92b014a3d1a19c49811951b28d6836 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 26 Nov 2020 13:12:36 -0700 Subject: [PATCH 5/5] fix CHANGELOG typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bc587ff..a070881e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ All notable changes to this project will be documented in this file. - @michaelshobbs bump golangci-lint to 1.27 and fix lintballs ### Fixed -- @michaelshobbsfix backlog() logic and add tests +- @michaelshobbs fix backlog() logic and add tests ## [v3.2.12] - 2020-10-22 ### Changed