Skip to content

Commit e1467ec

Browse files
Merge pull request #497 from gliderlabs/master
release 3.2.13
2 parents fdc00f0 + 99f410a commit e1467ec

File tree

12 files changed

+67
-31
lines changed

12 files changed

+67
-31
lines changed

.golangci.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ linters:
4747
- gochecknoglobals
4848
- funlen
4949
- gochecknoinits
50+
- godot
51+
- wsl
52+
- nolintlint
53+
- testpackage
54+
- dupl
55+
- goerr113
5056

5157
issues:
5258
# Excluding configuration per-path, per-linter, per-text and per-source
@@ -71,7 +77,7 @@ run:
7177
# golangci.com configuration
7278
# https://github.com/golangci/golangci/wiki/Configuration
7379
service:
74-
golangci-lint-version: 1.18.x # use the fixed version to not introduce new linters unexpectedly
80+
golangci-lint-version: 1.27.x # use the fixed version to not introduce new linters unexpectedly
7581
prepare:
7682
- echo "here I can run custom commands, but no preparation needed for this repo"
7783

CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ All notable changes to this project will be documented in this file.
1010

1111
### Changed
1212

13+
14+
## [v3.2.13] - 2020-11-26
15+
### Changed
16+
- @michaelshobbs bump golangci-lint to 1.27 and fix lintballs
17+
18+
### Fixed
19+
- @michaelshobbs fix backlog() logic and add tests
20+
1321
## [v3.2.12] - 2020-10-22
1422
### Changed
1523
- @michaelshobbs bump alpine to 3.12
@@ -247,7 +255,8 @@ All notable changes to this project will be documented in this file.
247255
- Base container is now Alpine
248256
- Moved to gliderlabs organization
249257

250-
[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.2.12...HEAD
258+
[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.2.13...HEAD
259+
[v3.2.13]: https://github.com/gliderlabs/logspout/compare/v3.2.12...v3.2.13
251260
[v3.2.12]: https://github.com/gliderlabs/logspout/compare/v3.2.11...v3.2.12
252261
[v3.2.11]: https://github.com/gliderlabs/logspout/compare/v3.2.10...v3.2.11
253262
[v3.2.10]: https://github.com/gliderlabs/logspout/compare/v3.2.9...v3.2.10

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ VERSION=$(shell cat VERSION)
66
MAX_IMAGE_SIZE := 40000000
77

88
GOBIN := $(shell go env GOPATH | awk -F ":" '{ print $$1 }')/bin
9-
GOLANGCI_LINT_VERSION := v1.18.0
9+
GOLANGCI_LINT_VERSION := v1.27.0
1010

1111
ifeq ($(shell uname), Darwin)
1212
XARGS_ARG="-L1"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ The standard distribution of logspout comes with all modules defined in this rep
368368
* [logspout-redis-logstash](https://github.com/rtoma/logspout-redis-logstash)
369369
* [logspout-gelf](https://github.com/micahhausler/logspout-gelf) for Graylog
370370
* [logspout-fluentd](https://github.com/dsouzajude/logspout-fluentd) for fluentd or fluent-bit - instead of using fluentd log driver
371-
371+
* [logspout-slack](https://github.com/kalisio/logspout-slack) for [Slack](https://slack.com/) notifications
372372

373373
### Loggly support
374374

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.2.12
1+
v3.2.13

adapters/multiline/multiline.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515
)
1616

1717
const (
18-
matchFirst = "first"
19-
matchLast = "last"
20-
matchNonFirst = "nonfirst"
21-
matchNonLast = "nonlast"
18+
matchFirst = "first"
19+
matchLast = "last"
20+
matchNonFirst = "nonfirst"
21+
matchNonLast = "nonlast"
22+
defaultFlushAfter = 500 * time.Millisecond
2223
)
2324

2425
func init() {
@@ -89,7 +90,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
8990
return nil, errors.New("multiline: invalid value for MULTILINE_MATCH (must be one of first|last|nonfirst|nonlast): " + matchType)
9091
}
9192

92-
flushAfter := 500 * time.Millisecond
93+
flushAfter := defaultFlushAfter
9394
flushAfterStr := os.Getenv("MULTILINE_FLUSH_AFTER")
9495
if flushAfterStr != "" {
9596
timeoutMS, errConv := strconv.Atoi(flushAfterStr)
@@ -100,7 +101,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
100101
}
101102

102103
parts := strings.SplitN(route.Adapter, "+", 2)
103-
if len(parts) != 2 {
104+
if len(parts) != 2 { //nolint:gomnd
104105
return nil, errors.New("multiline: adapter must have a sub-adapter, eg: multiline+raw+tcp")
105106
}
106107

@@ -117,7 +118,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
117118
route.Adapter = originalAdapter
118119

119120
out := make(chan *router.Message)
120-
checkInterval := flushAfter / 2
121+
checkInterval := flushAfter / 2 //nolint:gomnd
121122

122123
return &Adapter{
123124
out: out,
@@ -135,7 +136,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
135136
}
136137

137138
// Stream sends log data to the next adapter
138-
func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo
139+
func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo,gocognit
139140
wg := sync.WaitGroup{}
140141
wg.Add(1)
141142
go func() {
@@ -165,7 +166,7 @@ func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo
165166

166167
cID := message.Container.ID
167168
old, oldExists := a.buffers[cID]
168-
if a.isFirstLine(message) {
169+
if a.isFirstLine(message) { //nolint:nestif
169170
if oldExists {
170171
a.out <- old
171172
}

httpstream/httpstream.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/gliderlabs/logspout/router"
1515
)
1616

17+
const maxRouteIDLen = 12
18+
1719
func init() {
1820
router.HTTPHandlers.Register(LogStreamer, "logs")
1921
}
@@ -35,8 +37,8 @@ func LogStreamer() http.Handler {
3537
switch params["predicate"] {
3638
case "id":
3739
route.FilterID = params["value"]
38-
if len(route.ID) > 12 {
39-
route.FilterID = route.FilterID[:12]
40+
if len(route.ID) > maxRouteIDLen {
41+
route.FilterID = route.FilterID[:maxRouteIDLen]
4042
}
4143
case "name":
4244
route.FilterName = params["value"]
@@ -83,10 +85,10 @@ func (c Colorizer) Get(key string) string {
8385
i = c[key]
8486
}
8587
bright := "1;"
86-
if i%14 > 6 {
88+
if i%14 > 6 { //nolint:gomnd
8789
bright = ""
8890
}
89-
return "\x1b[" + bright + "3" + strconv.Itoa(7-(i%7)) + "m"
91+
return "\x1b[" + bright + "3" + strconv.Itoa(7-(i%7)) + "m" //nolint:gomnd
9092
}
9193

9294
func marshal(obj interface{}) []byte {
@@ -134,7 +136,7 @@ func httpStreamer(w http.ResponseWriter, req *http.Request, logstream chan *rout
134136
if req.URL.Query().Get("sources") != "" && logline.Source != req.URL.Query().Get("sources") {
135137
continue
136138
}
137-
if usejson {
139+
if usejson { //nolint:nestif
138140
w.Write(append(marshal(logline), '\n'))
139141
} else {
140142
if multi {

router/persist.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (fs RouteFileStore) GetAll() ([]*Route, error) {
5151

5252
// Add writes a marshaled *Route to the RouteFileStore
5353
func (fs RouteFileStore) Add(route *Route) error {
54-
return ioutil.WriteFile(fs.Filename(route.ID), marshal(route), 0644)
54+
return ioutil.WriteFile(fs.Filename(route.ID), marshal(route), 0600)
5555
}
5656

5757
// Remove removes route from the RouteFileStore based on id

router/pump.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
pumpEventStatusRenameName = "rename"
2323
pumpEventStatusDieName = "die"
2424
trueString = "true"
25+
pumpMaxIDLen = 12
2526
)
2627

2728
var (
@@ -45,7 +46,7 @@ func debug(v ...interface{}) {
4546
}
4647

4748
func backlog() bool {
48-
return os.Getenv("BACKLOG") == "false"
49+
return os.Getenv("BACKLOG") == trueString
4950
}
5051

5152
func setAllowTTY() {
@@ -66,8 +67,8 @@ func normalName(name string) string {
6667
}
6768

6869
func normalID(id string) string {
69-
if len(id) > 12 {
70-
return id[:12]
70+
if len(id) > pumpMaxIDLen {
71+
return id[:pumpMaxIDLen]
7172
}
7273
return id
7374
}
@@ -101,7 +102,7 @@ func ignoreContainer(container *docker.Container) bool {
101102
for _, label := range excludeLabelArr {
102103
labelParts := strings.Split(label, ":")
103104

104-
if len(labelParts) == 2 {
105+
if len(labelParts) == 2 { //nolint:gomnd
105106
excludeLabel = labelParts[0]
106107
excludeValue = labelParts[1]
107108
}
@@ -321,8 +322,8 @@ func (p *LogsPump) Route(route *Route, logstream chan *Message) {
321322
if route.MatchContainer(
322323
normalID(pump.container.ID),
323324
normalName(pump.container.Name),
324-
pump.container.Config.Labels) {
325-
325+
pump.container.Config.Labels,
326+
) {
326327
pump.add(logstream, route)
327328
defer pump.remove(logstream)
328329
}
@@ -344,8 +345,8 @@ func (p *LogsPump) Route(route *Route, logstream chan *Message) {
344345
if route.MatchContainer(
345346
normalID(event.pump.container.ID),
346347
normalName(event.pump.container.Name),
347-
event.pump.container.Config.Labels) {
348-
348+
event.pump.container.Config.Labels,
349+
) {
349350
event.pump.add(logstream, route)
350351
defer event.pump.remove(logstream)
351352
}

router/pump_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,22 @@ func TestPumpRoutingFrom(t *testing.T) {
268268
t.Errorf("expected RoutingFrom to return 'false'")
269269
}
270270
}
271+
272+
func TestPumpBacklog(t *testing.T) {
273+
os.Unsetenv("BACKLOG")
274+
if backlog() != false {
275+
t.Errorf("expected backlog() to return 'false'")
276+
}
277+
os.Setenv("BACKLOG", "false")
278+
if backlog() != false {
279+
t.Errorf("expected backlog() to return 'false'")
280+
}
281+
os.Setenv("BACKLOG", "true")
282+
if backlog() != true {
283+
t.Errorf("expected backlog() to return 'true'")
284+
}
285+
os.Unsetenv("BACKLOG")
286+
if backlog() != false {
287+
t.Errorf("expected backlog() to return 'false'")
288+
}
289+
}

transports/tls/tls.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func createTLSConfig() (tlsConfig *tls.Config, err error) {
9797
tlsConfig = &tls.Config{}
9898

9999
// use stronger TLS settings if enabled
100-
// TODO: perhaps this should be default setting
100+
// perhaps this should be default setting @gbolo
101101
if os.Getenv(envTLSHardening) == trueString {
102102
tlsConfig.InsecureSkipVerify = false
103103
tlsConfig.MinVersion = hardenedMinVersion

transports/tls/tls_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func TestEmptyTrustStore(t *testing.T) {
3838
if numOfTrustedCerts != 0 {
3939
t.Fatalf("expected 0 RootCAs but got: %d", numOfTrustedCerts)
4040
}
41-
4241
}
4342

4443
// TestSingleCustomCA should test the behavior of loading
@@ -52,7 +51,6 @@ func TestSingleCustomCA(t *testing.T) {
5251
if !bytes.Contains(testTLSConfig.RootCAs.Subjects()[0], []byte(caRootCertSubjectCN)) {
5352
t.Errorf("failed to load custom root CA into trust store: %s", caRootCertFileLocation)
5453
}
55-
5654
}
5755

5856
// TestMultipleCustomCAs should test the behavior of loading

0 commit comments

Comments
 (0)