Skip to content

Commit 0b3599b

Browse files
Merge pull request #461 from gliderlabs/master
release 3.2.7
2 parents 591787f + 0d368f9 commit 0b3599b

35 files changed

+354
-263
lines changed

.golangci.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
linters-settings:
2+
errcheck:
3+
# ignore cases where we truly don't care about the returned error
4+
ignore: net/http:^Write$,io:^WriteString$
5+
govet:
6+
check-shadowing: true
7+
settings:
8+
printf:
9+
funcs:
10+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
11+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
12+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
13+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
14+
golint:
15+
min-confidence: 0
16+
gocyclo:
17+
min-complexity: 12
18+
maligned:
19+
suggest-new: true
20+
dupl:
21+
threshold: 100
22+
goconst:
23+
min-len: 2
24+
min-occurrences: 2
25+
depguard:
26+
list-type: blacklist
27+
misspell:
28+
locale: US
29+
lll:
30+
line-length: 160
31+
goimports:
32+
local-prefixes: github.com/gliderlabs/logspout
33+
gocritic:
34+
settings:
35+
hugeParam:
36+
sizeThreshold: 160
37+
enabled-tags:
38+
- performance
39+
nakedret:
40+
max-func-lines: 65
41+
42+
linters:
43+
enable-all: true
44+
disable:
45+
- maligned
46+
- prealloc
47+
- gochecknoglobals
48+
- funlen
49+
- gochecknoinits
50+
51+
issues:
52+
# Excluding configuration per-path, per-linter, per-text and per-source
53+
exclude-rules:
54+
# Exclude some linters from running on tests files.
55+
- path: _test\.go
56+
linters:
57+
- dupl
58+
- errcheck
59+
- goconst
60+
- gocyclo
61+
- gosec
62+
- lll
63+
- nakedret
64+
- unparam
65+
- funlen
66+
67+
run:
68+
deadline: 2m
69+
issues-exit-code: 1
70+
71+
# golangci.com configuration
72+
# https://github.com/golangci/golangci/wiki/Configuration
73+
service:
74+
golangci-lint-version: 1.18.x # use the fixed version to not introduce new linters unexpectedly
75+
prepare:
76+
- echo "here I can run custom commands, but no preparation needed for this repo"
77+

CHANGELOG.md

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

1111
### Changed
1212

13+
## [v3.2.7] - 2020-04-03
14+
### Fixed
15+
- @CodeLingoBot @gbolo Fix function comments based on best practices from Effective Go
16+
17+
### Changed
18+
- @michaelshobbs update alpine to 3.10/go 1.12.12-r0 and fix linting
19+
- @whoisteri DOC Document accessible data in RAW_FORMAT template
20+
- @tiagorlampert DOC typos
21+
- @michaelshobbs DOC CHANGLELOG formatting
22+
- @tomlankhorst DOC Suggest to disable userns-remap for logspout
23+
- @StudioEtrange DOC add link to logspout-fluentd
24+
1325
## [v3.2.6] - 2018-10-04
1426
### Fixed
1527
- @jdgiotta Spelling corrections and fixed stack compose formatting in example
@@ -28,13 +40,12 @@ All notable changes to this project will be documented in this file.
2840
- @gbolo enforced the use of `go 1.8+` in order to accommodate some TLS settings
2941

3042
## [v3.2.5] - 2018-06-05
43+
### Fixed
44+
- @michaelshobbs fix working_directory so we don't duplicate test runs
3145
- @gmelika panic if reconnect fails
3246
- @masterada Added multiline adapter
3347
- @billimek sleeping and syncing to fix issues with docker hub builds
3448

35-
### Fixed
36-
- @michaelshobbs fix working_directory so we don't duplicate test runs
37-
3849
### Added
3950
- @chris7444 take the hostname from /etc/host_hostname if the file is there
4051
- @chris7444 update README.md for swarm deployments PR #329
@@ -199,7 +210,8 @@ All notable changes to this project will be documented in this file.
199210
- Base container is now Alpine
200211
- Moved to gliderlabs organization
201212

202-
[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.2.6...HEAD
213+
[unreleased]: https://github.com/gliderlabs/logspout/compare/v3.2.7...HEAD
214+
[v3.2.7]: https://github.com/gliderlabs/logspout/compare/v3.2.6...v3.2.7
203215
[v3.2.6]: https://github.com/gliderlabs/logspout/compare/v3.2.5...v3.2.6
204216
[v3.2.5]: https://github.com/gliderlabs/logspout/compare/v3.2.4...v3.2.5
205217
[v3.2.4]: https://github.com/gliderlabs/logspout/compare/v3.2.3...v3.2.4

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.8
1+
FROM alpine:3.10
22
ENTRYPOINT ["/bin/logspout"]
33
VOLUME /mnt/routes
44
EXPOSE 80

Dockerfile.dev

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
FROM alpine:3.8
1+
FROM alpine:3.10
22
VOLUME /mnt/routes
33
EXPOSE 80
44

5-
ENV GOPATH /go
6-
RUN apk --no-cache add go build-base git mercurial ca-certificates
7-
COPY . /go/src/github.com/gliderlabs/logspout
8-
WORKDIR /go/src/github.com/gliderlabs/logspout
9-
RUN go get
10-
CMD go get \
11-
&& go build -ldflags "-X main.Version=dev" -o /bin/logspout \
12-
&& exec /bin/logspout
5+
RUN apk --no-cache add go build-base git mercurial ca-certificates curl
6+
COPY . /src
7+
WORKDIR /src
8+
CMD go build -ldflags "-X main.Version=dev" -o /bin/logspout \
9+
&& exec /bin/logspout

Makefile

+20-9
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ VERSION=$(shell cat VERSION)
55
# max image size of 40MB
66
MAX_IMAGE_SIZE := 40000000
77

8+
GOBIN := $(shell go env GOPATH | awk -F ":" '{ print $$1 }')/bin
9+
GOLANGCI_LINT_VERSION := v1.18.0
10+
811
ifeq ($(shell uname), Darwin)
912
XARGS_ARG="-L1"
1013
endif
1114
GOPACKAGES ?= $(shell go list ./... | egrep -v 'custom|vendor')
12-
GOLINT := go list ./... | egrep -v '/custom/|/vendor/' | xargs $(XARGS_ARG) golint | egrep -v 'extpoints.go|types.go'
1315
TEST_ARGS ?= -race
1416

1517
ifdef TEST_RUN
@@ -37,12 +39,21 @@ build-custom:
3739
docker tag $(NAME):$(VERSION) gliderlabs/$(NAME):master
3840
cd custom && docker build -t $(NAME):custom .
3941

40-
lint:
41-
test -x $(GOPATH)/bin/golint || go get github.com/golang/lint/golint
42-
go get \
43-
&& go install $(GOPACKAGES) \
44-
&& go tool vet -v $(shell ls -d */ | egrep -v 'custom|vendor/' | xargs $(XARGS_ARG))
45-
@if [ -n "$(shell $(GOLINT) | cut -d ':' -f 1)" ]; then $(GOLINT) && exit 1 ; fi
42+
lint-requirements:
43+
ifeq ($(shell which golangci-lint), )
44+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION)
45+
endif
46+
47+
lint: lint-requirements
48+
$(GOBIN)/golangci-lint run
49+
50+
lint-ci-direct: lint-requirements
51+
$(GOBIN)/golangci-lint --verbose run
52+
53+
lint-ci: build-dev
54+
docker run \
55+
-v $(PWD):/go/src/github.com/gliderlabs/logspout \
56+
$(NAME):dev make -e lint-ci-direct
4657

4758
test: build-dev
4859
docker run \
@@ -76,7 +87,7 @@ test-healthcheck:
7687
-p 8000:80 \
7788
-v /var/run/docker.sock:/var/run/docker.sock \
7889
$(NAME):$(VERSION)
79-
sleep 2
90+
sleep 5
8091
docker logs $(NAME)-healthcheck
8192
docker inspect --format='{{ .State.Running }}' $(NAME)-healthcheck | grep true
8293
curl --head --silent localhost:8000/health | grep "200 OK"
@@ -85,7 +96,7 @@ test-healthcheck:
8596

8697
test-custom:
8798
docker run --name $(NAME)-custom $(NAME):custom || true
88-
docker logs $(NAME)-custom | grep -q logstash
99+
docker logs $(NAME)-custom 2>&1 | grep -q logstash
89100
docker rmi gliderlabs/$(NAME):master || true
90101
docker rm $(NAME)-custom || true
91102

README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ logspout will gather logs from other containers that are started **without the `
3737

3838
To see what data is used for syslog messages, see the [syslog adapter](http://github.com/gliderlabs/logspout/blob/master/adapters) docs.
3939

40+
The container must be able to access the Docker Unix socket to mount it. This is typically a problem when [namespace remapping](https://docs.docker.com/engine/security/userns-remap/) is enabled. To disable remapping for the logspout container, pass the `--userns=host` flag to `docker run`, `.. create`, etc.
41+
4042
#### Ignoring specific containers
4143

4244
You can tell logspout to ignore specific containers by setting an environment variable when starting your container, like so:-
@@ -192,6 +194,14 @@ If you use multiline logging with raw, it's recommended to json encode the Data
192194

193195
The raw adapter has a function `toJSON` that can be used to format the message/fields to generate JSON-like output in a simple way, or full JSON output.
194196

197+
The RAW_FORMAT env variable is used as a [Go template](https://golang.org/pkg/text/template/) with a [`Message` struct](https://github.com/gliderlabs/logspout/blob/master/router/types.go#L52) passed as data. You can access the following fields
198+
199+
* `Source` - source stream name ("stdout", "stderr", ...)
200+
* `Data` - original log message
201+
* `Time` - a Go [`Time` struct](https://golang.org/pkg/time/#Time)
202+
* `Container` - a [go-dockerclient](https://github.com/fsouza/go-dockerclient) `Container` struct (see [container.go](https://github.com/fsouza/go-dockerclient/blob/master/container.go#L443) source file for accessible fields)
203+
204+
195205
Use examples:
196206

197207
##### Mixed JSON + generic:
@@ -273,9 +283,9 @@ logspout supports modification of the client TLS settings via environment variab
273283
| Environment Variable | Description |
274284
| :--- | :--- |
275285
| `LOGSPOUT_TLS_DISABLE_SYSTEM_ROOTS` | when set to `true` it disables loading the system trust store into the trust store of logspout |
276-
| `LOGSPOUT_TLS_CA_CERTS` | a comma seperated list of filesystem paths to pem encoded CA certificates that should be added to logsput's TLS trust store. Each pem file can contain more than one certificate |
277-
| `LOGSPOUT_TLS_CLIENT_CERT` | filesytem path to pem encoded x509 client certificate to load when TLS mutual authentication is desired |
278-
| `LOGSPOUT_TLS_CLIENT_KEY` | filesytem path to pem encoded client private key to load when TLS mutual authentication is desired |
286+
| `LOGSPOUT_TLS_CA_CERTS` | a comma separated list of filesystem paths to pem encoded CA certificates that should be added to logsput's TLS trust store. Each pem file can contain more than one certificate |
287+
| `LOGSPOUT_TLS_CLIENT_CERT` | filesystem path to pem encoded x509 client certificate to load when TLS mutual authentication is desired |
288+
| `LOGSPOUT_TLS_CLIENT_KEY` | filesystem path to pem encoded client private key to load when TLS mutual authentication is desired |
279289
| `LOGSPOUT_TLS_HARDENING` | when set to `true` it enables stricter client TLS settings designed to mitigate some known TLS vulnerabilities |
280290

281291
#### Example TLS settings
@@ -329,6 +339,8 @@ The standard distribution of logspout comes with all modules defined in this rep
329339
* [logspout-logstash](https://github.com/looplab/logspout-logstash)
330340
* [logspout-redis-logstash](https://github.com/rtoma/logspout-redis-logstash)
331341
* [logspout-gelf](https://github.com/micahhausler/logspout-gelf) for Graylog
342+
* [logspout-fluentd](https://github.com/dsouzajude/logspout-fluentd) for fluentd or fluent-bit - instead of using fluentd log driver
343+
332344

333345
### Loggly support
334346

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.2.6
1+
v3.2.7

adapters/multiline/multiline.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"sync"
1010
"time"
1111

12-
"github.com/fsouza/go-dockerclient"
12+
docker "github.com/fsouza/go-dockerclient"
13+
1314
"github.com/gliderlabs/logspout/router"
1415
)
1516

@@ -40,11 +41,10 @@ type Adapter struct {
4041
}
4142

4243
// NewMultilineAdapter returns a configured multiline.Adapter
43-
func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
44+
func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) { //nolint:gocyclo
4445
enableByDefault := true
4546
enableStr := os.Getenv("MULTILINE_ENABLE_DEFAULT")
4647
if enableStr != "" {
47-
var err error
4848
enableByDefault, err = strconv.ParseBool(enableStr)
4949
if err != nil {
5050
return nil, errors.New("multiline: invalid value for MULTILINE_ENABLE_DEFAULT (must be true|false): " + enableStr)
@@ -92,8 +92,8 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
9292
flushAfter := 500 * time.Millisecond
9393
flushAfterStr := os.Getenv("MULTILINE_FLUSH_AFTER")
9494
if flushAfterStr != "" {
95-
timeoutMS, err := strconv.Atoi(flushAfterStr)
96-
if err != nil {
95+
timeoutMS, errConv := strconv.Atoi(flushAfterStr)
96+
if errConv != nil {
9797
return nil, errors.New("multiline: invalid value for multiline_timeout (must be number): " + flushAfterStr)
9898
}
9999
flushAfter = time.Duration(timeoutMS) * time.Millisecond
@@ -135,7 +135,7 @@ func NewMultilineAdapter(route *router.Route) (a router.LogAdapter, err error) {
135135
}
136136

137137
// Stream sends log data to the next adapter
138-
func (a *Adapter) Stream(logstream chan *router.Message) {
138+
func (a *Adapter) Stream(logstream chan *router.Message) { //nolint:gocyclo
139139
wg := sync.WaitGroup{}
140140
wg.Add(1)
141141
go func() {
@@ -173,7 +173,7 @@ func (a *Adapter) Stream(logstream chan *router.Message) {
173173
a.buffers[cID] = message
174174
} else {
175175
isLastLine := a.isLastLine(message)
176-
176+
177177
if oldExists {
178178
old.Data += a.separator + message.Data
179179
message = old

adapters/multiline/multiline_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/fsouza/go-dockerclient"
10+
docker "github.com/fsouza/go-dockerclient"
11+
1112
"github.com/gliderlabs/logspout/router"
1213
)
1314

adapters/raw/raw.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var funcs = template.FuncMap{
2121
"toJSON": func(value interface{}) string {
2222
bytes, err := json.Marshal(value)
2323
if err != nil {
24-
log.Println("error marshalling to JSON: ", err)
24+
log.Println("error marshaling to JSON: ", err)
2525
return "null"
2626
}
2727
return string(bytes)

adapters/syslog/syslog.go

+10-17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"text/template"
1616
"time"
1717

18+
"github.com/gliderlabs/logspout/cfg"
1819
"github.com/gliderlabs/logspout/router"
1920
)
2021

@@ -34,22 +35,14 @@ func init() {
3435
}
3536

3637
func setRetryCount() {
37-
if count, err := strconv.Atoi(getopt("RETRY_COUNT", strconv.Itoa(defaultRetryCount))); err != nil {
38+
if count, err := strconv.Atoi(cfg.GetEnvDefault("RETRY_COUNT", strconv.Itoa(defaultRetryCount))); err != nil {
3839
retryCount = uint(defaultRetryCount)
3940
} else {
4041
retryCount = uint(count)
4142
}
4243
debug("setting retryCount to:", retryCount)
4344
}
4445

45-
func getopt(name, dfault string) string {
46-
value := os.Getenv(name)
47-
if value == "" {
48-
value = dfault
49-
}
50-
return value
51-
}
52-
5346
func debug(v ...interface{}) {
5447
if os.Getenv("DEBUG") != "" {
5548
log.Println(v...)
@@ -61,7 +54,7 @@ func getHostname() string {
6154
if err == nil && len(content) > 0 {
6255
hostname = strings.TrimRight(string(content), "\r\n")
6356
} else {
64-
hostname = getopt("SYSLOG_HOSTNAME", "{{.Container.Config.Hostname}}")
57+
hostname = cfg.GetEnvDefault("SYSLOG_HOSTNAME", "{{.Container.Config.Hostname}}")
6558
}
6659
return hostname
6760
}
@@ -77,18 +70,18 @@ func NewSyslogAdapter(route *router.Route) (router.LogAdapter, error) {
7770
return nil, err
7871
}
7972

80-
format := getopt("SYSLOG_FORMAT", "rfc5424")
81-
priority := getopt("SYSLOG_PRIORITY", "{{.Priority}}")
82-
pid := getopt("SYSLOG_PID", "{{.Container.State.Pid}}")
73+
format := cfg.GetEnvDefault("SYSLOG_FORMAT", "rfc5424")
74+
priority := cfg.GetEnvDefault("SYSLOG_PRIORITY", "{{.Priority}}")
75+
pid := cfg.GetEnvDefault("SYSLOG_PID", "{{.Container.State.Pid}}")
8376
hostname = getHostname()
8477

85-
tag := getopt("SYSLOG_TAG", "{{.ContainerName}}"+route.Options["append_tag"])
86-
structuredData := getopt("SYSLOG_STRUCTURED_DATA", "")
78+
tag := cfg.GetEnvDefault("SYSLOG_TAG", "{{.ContainerName}}"+route.Options["append_tag"])
79+
structuredData := cfg.GetEnvDefault("SYSLOG_STRUCTURED_DATA", "")
8780
if route.Options["structured_data"] != "" {
8881
structuredData = route.Options["structured_data"]
8982
}
90-
data := getopt("SYSLOG_DATA", "{{.Data}}")
91-
timestamp := getopt("SYSLOG_TIMESTAMP", "{{.Timestamp}}")
83+
data := cfg.GetEnvDefault("SYSLOG_DATA", "{{.Data}}")
84+
timestamp := cfg.GetEnvDefault("SYSLOG_TIMESTAMP", "{{.Timestamp}}")
9285

9386
if structuredData == "" {
9487
structuredData = "-"

0 commit comments

Comments
 (0)