Fix Golangci-lint configuration

This commit is contained in:
Maximilian Paß
2024-05-07 12:11:25 +02:00
parent 8c5e0e11f7
commit ec3b2a93db
6 changed files with 42 additions and 33 deletions

View File

@ -1,3 +1,6 @@
run:
go: "1.22"
linters-settings: linters-settings:
errcheck: errcheck:
check-type-assertions: true check-type-assertions: true
@ -7,8 +10,6 @@ linters-settings:
statements: 50 statements: 50
gocognit: gocognit:
min-complexity: 15 min-complexity: 15
goconst:
min-occurences: 2
gocritic: gocritic:
enabled-tags: enabled-tags:
- diagnostic - diagnostic
@ -25,35 +26,26 @@ linters-settings:
gocyclo: gocyclo:
min-complexity: 15 min-complexity: 15
gomnd: gomnd:
settings: # don't include "assign"
mnd: checks:
# don't include "assign" - argument
checks: - case
- argument - condition
- case - operation
- condition - return
- operation
- return
importas:
unaliased: false
lll: lll:
line-length: 150 line-length: 150
makezero: makezero:
always: true always: true
maligned:
suggest-new: true
misspell: misspell:
locale: US locale: US
nakedret: nakedret:
max-func-lines: 5 max-func-lines: 5
stylecheck:
go: "1.22"
linters: linters:
disable-all: true disable-all: true
enable: enable:
# default # default
- deadcode
- errcheck - errcheck
- gosimple - gosimple
- govet - govet
@ -61,7 +53,6 @@ linters:
- staticcheck - staticcheck
- typecheck - typecheck
- unused - unused
- varcheck
# additional linters, see https://golangci-lint.run/usage/linters # additional linters, see https://golangci-lint.run/usage/linters
- bodyclose - bodyclose
- dogsled - dogsled
@ -75,9 +66,9 @@ linters:
- gocritic - gocritic
- gocyclo - gocyclo
- godot - godot
- goerr113 - err113
- gofmt - gofmt
- gomnd - mnd
- goprintffuncname - goprintffuncname
- gosec - gosec
- importas - importas

View File

@ -393,15 +393,17 @@ func initRouter(ctx context.Context) *mux.Router {
// initServer creates a server that serves the routes provided by the router. // initServer creates a server that serves the routes provided by the router.
func initServer(router *mux.Router) *http.Server { func initServer(router *mux.Router) *http.Server {
sentryHandler := sentryhttp.New(sentryhttp.Options{}).Handle(router) sentryHandler := sentryhttp.New(sentryhttp.Options{}).Handle(router)
const readTimeout = 15 * time.Second
const idleTimeout = 60 * time.Second
return &http.Server{ return &http.Server{
Addr: config.Config.Server.URL().Host, Addr: config.Config.Server.URL().Host,
// A WriteTimeout would prohibit long-running requests such as creating an execution environment. // A WriteTimeout would prohibit long-running requests such as creating an execution environment.
// See also https://github.com/openHPI/poseidon/pull/68. // See also https://github.com/openHPI/poseidon/pull/68.
// WriteTimeout: time.Second * 15, // WriteTimeout: time.Second * 15,
ReadHeaderTimeout: time.Second * 15, ReadHeaderTimeout: readTimeout,
ReadTimeout: time.Second * 15, ReadTimeout: readTimeout,
IdleTimeout: time.Second * 60, IdleTimeout: idleTimeout,
Handler: sentryHandler, Handler: sentryHandler,
} }
} }

View File

@ -20,12 +20,18 @@ import (
"strings" "strings"
) )
const (
defaultPoseidonPort = 7200
defaultNomadPort = 4646
defaultMemoryUsageAlertThreshold = 1_000
)
// Config contains the default configuration of Poseidon. // Config contains the default configuration of Poseidon.
var ( var (
Config = &configuration{ Config = &configuration{
Server: server{ Server: server{
Address: "127.0.0.1", Address: "127.0.0.1",
Port: 7200, Port: defaultPoseidonPort,
SystemdSocketActivation: false, SystemdSocketActivation: false,
Token: "", Token: "",
TLS: TLS{ TLS: TLS{
@ -45,7 +51,7 @@ var (
Nomad: Nomad{ Nomad: Nomad{
Enabled: true, Enabled: true,
Address: "127.0.0.1", Address: "127.0.0.1",
Port: 4646, Port: defaultNomadPort,
Token: "", Token: "",
TLS: TLS{ TLS: TLS{
Active: false, Active: false,
@ -70,7 +76,7 @@ var (
Formatter: dto.FormatterText, Formatter: dto.FormatterText,
}, },
Profiling: Profiling{ Profiling: Profiling{
MemoryThreshold: 1_000, MemoryThreshold: defaultMemoryUsageAlertThreshold,
}, },
Sentry: sentry.ClientOptions{ Sentry: sentry.ClientOptions{
AttachStacktrace: true, AttachStacktrace: true,

View File

@ -435,17 +435,21 @@ func fileDeletionCommand(pathsToDelete []dto.FilePath) string {
} }
func tarHeader(file dto.File) *tar.Header { func tarHeader(file dto.File) *tar.Header {
// See #236. Sticky bit is to allow creating files next to write-protected files.
const directoryPermission int64 = 0o1777
const filePermission int64 = 0o744
if file.IsDirectory() { if file.IsDirectory() {
return &tar.Header{ return &tar.Header{
Typeflag: tar.TypeDir, Typeflag: tar.TypeDir,
Name: file.CleanedPath(), Name: file.CleanedPath(),
Mode: 0o1777, // See #236. Sticky bit is to allow creating files next to write-protected files. Mode: directoryPermission,
} }
} else { } else {
return &tar.Header{ return &tar.Header{
Typeflag: tar.TypeReg, Typeflag: tar.TypeReg,
Name: file.CleanedPath(), Name: file.CleanedPath(),
Mode: 0o744, Mode: filePermission,
Size: int64(len(file.Content)), Size: int64(len(file.Content)),
} }
} }

View File

@ -27,12 +27,15 @@ const (
DefaultMockID = "m0ck-1d" DefaultMockID = "m0ck-1d"
ShortTimeout = 100 * time.Millisecond ShortTimeout = 100 * time.Millisecond
DefaultTestTimeout = 10 * time.Minute DefaultTestTimeout = 10 * time.Minute
defaultPort = 42
anotherPort = 1337
) )
var ( var (
ErrDefault = errors.New("an error occurred") ErrDefault = errors.New("an error occurred")
ErrCleanupDestroyReason = errors.New("destruction required for cleanup") ErrCleanupDestroyReason = errors.New("destruction required for cleanup")
DefaultPortMappings = []nomadApi.PortMapping{{To: 42, Value: 1337, Label: "lit", HostIP: "127.0.0.1"}} DefaultPortMappings = []nomadApi.PortMapping{{To: defaultPort, Value: anotherPort, Label: "lit", HostIP: "127.0.0.1"}}
DefaultMappedPorts = []*dto.MappedPort{{ExposedPort: 42, HostAddress: "127.0.0.1:1337"}} DefaultMappedPorts = []*dto.MappedPort{{ExposedPort: defaultPort, HostAddress: "127.0.0.1:1337"}}
) )

View File

@ -16,10 +16,13 @@ var log = logging.GetLogger("e2e-helpers")
func CreateDefaultEnvironment(prewarmingPoolSize uint, image string) dto.ExecutionEnvironmentRequest { func CreateDefaultEnvironment(prewarmingPoolSize uint, image string) dto.ExecutionEnvironmentRequest {
path := helpers.BuildURL(api.BasePath, api.EnvironmentsPath, tests.DefaultEnvironmentIDAsString) path := helpers.BuildURL(api.BasePath, api.EnvironmentsPath, tests.DefaultEnvironmentIDAsString)
const smallCPULimit uint = 20
const smallMemoryLimit uint = 100
defaultNomadEnvironment := dto.ExecutionEnvironmentRequest{ defaultNomadEnvironment := dto.ExecutionEnvironmentRequest{
PrewarmingPoolSize: prewarmingPoolSize, PrewarmingPoolSize: prewarmingPoolSize,
CPULimit: 20, CPULimit: smallCPULimit,
MemoryLimit: 100, MemoryLimit: smallMemoryLimit,
Image: image, Image: image,
NetworkAccess: false, NetworkAccess: false,
ExposedPorts: nil, ExposedPorts: nil,