Skip to content

Commit

Permalink
Merge pull request #495 from gliderlabs/mh/chore/bump-linter
Browse files Browse the repository at this point in the history
bump golangci-lint to 1.27 and fix lintballs
  • Loading branch information
michaelshobbs authored Nov 26, 2020
2 parents 4e88b84 + d42a095 commit ae55b89
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 10 additions & 9 deletions adapters/multiline/multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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")
}

Expand All @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions httpstream/httpstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/gliderlabs/logspout/router"
)

const maxRouteIDLen = 12

func init() {
router.HTTPHandlers.Register(LogStreamer, "logs")
}
Expand All @@ -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"]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion router/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions router/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
pumpEventStatusRenameName = "rename"
pumpEventStatusDieName = "die"
trueString = "true"
pumpMaxIDLen = 12
)

var (
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion transports/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions transports/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ae55b89

Please sign in to comment.