diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b270e9a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + lint-and-test: + name: Lint and Test + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22.6' + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum', '**/go.mod') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61.0 + args: --timeout=5m + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..c9af838 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,36 @@ +linters-settings: + govet: + enable-all: true + gocyclo: + min-complexity: 15 + misspell: + locale: US + lll: + line-length: 120 + +linters: + enable: + - errcheck + - gofmt + - goimports + - misspell + - ineffassign + - unconvert + disable: + - govet # Disabled due to version compatibility + - staticcheck # Disabled due to version compatibility + - unused # Disabled due to version compatibility + - gosimple # Disabled due to version compatibility + - typecheck # Disabled due to version compatibility + - gocritic # Disabled due to version compatibility + - gosec # Disabled due to version compatibility + - gocyclo # Can be enabled later if needed + +run: + timeout: 5m + modules-download-mode: readonly + +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 \ No newline at end of file diff --git a/plugin/gthulhu/auth.go b/plugin/gthulhu/auth.go index a49381e..c456b23 100644 --- a/plugin/gthulhu/auth.go +++ b/plugin/gthulhu/auth.go @@ -97,7 +97,12 @@ func (c *JWTClient) requestToken() error { if err != nil { return fmt.Errorf("failed to send token request: %v", err) } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + if err != nil { + fmt.Printf("Body.Close() failed: %v", err) + } + }() body, err := io.ReadAll(resp.Body) if err != nil { diff --git a/plugin/gthulhu/metrics.go b/plugin/gthulhu/metrics.go index 3c96b34..af90f4c 100644 --- a/plugin/gthulhu/metrics.go +++ b/plugin/gthulhu/metrics.go @@ -17,7 +17,7 @@ type BssData struct { NrOnlineCpus uint64 `json:"nr_online_cpus"` // Number of online CPUs in the system NrUserDispatches uint64 `json:"nr_user_dispatches"` // Number of user-space dispatches NrKernelDispatches uint64 `json:"nr_kernel_dispatches"` // Number of kernel-space dispatches - NrCancelDispatches uint64 `json:"nr_cancel_dispatches"` // Number of cancelled dispatches + NrCancelDispatches uint64 `json:"nr_cancel_dispatches"` // Number of canceled dispatches NrBounceDispatches uint64 `json:"nr_bounce_dispatches"` // Number of bounce dispatches NrFailedDispatches uint64 `json:"nr_failed_dispatches"` // Number of failed dispatches NrSchedCongested uint64 `json:"nr_sched_congested"` // Number of times the scheduler was congested @@ -65,7 +65,12 @@ func (c *MetricsClient) SendMetrics(data BssData) error { if err != nil { return fmt.Errorf("failed to send metrics request: %v", err) } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + if err != nil { + fmt.Printf("Body.Close() failed: %v", err) + } + }() // Check response if resp.StatusCode != 200 { diff --git a/plugin/gthulhu/strategy.go b/plugin/gthulhu/strategy.go index 848e8c4..5c25607 100644 --- a/plugin/gthulhu/strategy.go +++ b/plugin/gthulhu/strategy.go @@ -53,7 +53,12 @@ func FetchSchedulingStrategies(apiUrl string) ([]SchedulingStrategy, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer func() { + err = resp.Body.Close() + if err != nil { + fmt.Printf("Body.Close() failed: %v", err) + } + }() body, err := io.ReadAll(resp.Body) if err != nil {