Skip to content

Commit

Permalink
Merge pull request #10 from kushthedude/golangcilint
Browse files Browse the repository at this point in the history
CI: Add golangci-lint github action
  • Loading branch information
kushthedude authored Aug 24, 2020
2 parents e01ca63 + a50aebe commit 59ae7e1
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 570 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Nighthawk-Go
on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v1
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.29

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
with:
fetch-depth: 1
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: ${{ secrets.GO_VERSION }}
- name: Setup Cache
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: GOPROXY=direct GOSUMDB=off GO111MODULE=on go test -tags draft ./...
148 changes: 148 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
exhaustive:
default-signifies-exhaustive: false
funlen:
lines: 100
statements: 50
gci:
local-prefixes: github.com/golangci/golangci-lint
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/golangci/golangci-lint
golint:
min-confidence: 0
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
gosec:
settings:
exclude: -G204
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- dogsled
- dupl
- errcheck
- exhaustive
- funlen
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

# don't enable:
# - asciicheck
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"

run:
skip-dirs:
- test/testdata_etc
- internal/cache
- internal/renameio
- internal/robustio

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.23.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"
38 changes: 18 additions & 20 deletions api/nighthawk.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Package api defines nighthawk runner and config
package api

import (
"fmt"
"net/url"
"os/exec"
"strconv"
"net/url"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

// NighthawkConfig describes the configuration structure for loadtest
type NighthawkConfig struct {
Thread int
DurationInSeconds int
QPS int
URL string
Thread int
DurationInSeconds int
QPS int
URL string
}

// NighthawkRun function runs the nighthawk loadtest
func NighthawkRun (config *NighthawkConfig) ([]byte, error) {

func NighthawkRun(config *NighthawkConfig) ([]byte, error) {
imageName := "envoyproxy/nighthawk-dev"
_, err := exec.Command("docker", "inspect", imageName).Output()
if err != nil {
Expand All @@ -30,10 +30,9 @@ func NighthawkRun (config *NighthawkConfig) ([]byte, error) {
return nil, err
}


rURL, _ := url.Parse(config.URL)
if !rURL.IsAbs() {
err := fmt.Errorf("Please give a valid URL %s", config.URL)
err = fmt.Errorf("please give a valid URL %s", config.URL)
log.Error(err)
return nil, err
}
Expand All @@ -42,18 +41,18 @@ func NighthawkRun (config *NighthawkConfig) ([]byte, error) {
qps := strconv.Itoa(config.QPS)
c := strconv.Itoa(config.Thread)

args := []string{"--rps "+qps, "--concurrency "+c,"--duration "+duration,rURL.String(),"--output-format json"}
args := []string{"--rps " + qps, "--concurrency " + c, "--duration " + duration, rURL.String(), "--output-format json"}

log.Info("Received arguments for run", args)

out, err := exec.Command("docker", "run",
"envoyproxy/nighthawk-dev:latest",
"nighthawk_client",
"--rps "+qps,
"--concurrency "+c,
"--duration "+duration,
rURL.String(),
"--output-format json").Output()
"envoyproxy/nighthawk-dev:latest",
"nighthawk_client",
"--rps "+qps,
"--concurrency "+c,
"--duration "+duration,
rURL.String(),
"--output-format json").Output()

if err != nil {
msg := "Unable to run load-test"
Expand All @@ -63,5 +62,4 @@ func NighthawkRun (config *NighthawkConfig) ([]byte, error) {
}

return out, nil

}
}
6 changes: 1 addition & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ func init() {

// Output to only for logs above warn level
log.SetLevel(log.WarnLevel)

}

func main() {

//Duration in seconds nighthawk default format
// Duration in seconds nighthawk default format
testConfig := &api.NighthawkConfig{
Thread: 1,
DurationInSeconds: 5,
Expand All @@ -40,5 +37,4 @@ func main() {
}

fmt.Print(string(result))

}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module github.com/layer5io/nighthawk-go
go 1.14

require (
github.com/golangci/golangci-lint v1.30.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/tools v0.0.0-20200823205832-c024452afbcd // indirect
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
Loading

0 comments on commit 59ae7e1

Please sign in to comment.