Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
name: lint
on:
pull_request:
push:
branches: [ main ]
pull_request:
push:
branches: [main]

jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m

staticlint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Install dependencies
run: go mod tidy
- name: Run Staticlint
run: go run ./cmd/staticlint/main.go ./...
147 changes: 72 additions & 75 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,81 @@
version: "2"

run:
timeout: 5m
tests: true
concurrency: 0
timeout: 5m
tests: true
concurrency: 0

linters:
default: none
enable:
- govet
- staticcheck
- errcheck
- ineffassign
- unused
- revive
- gocyclo
- dupl
- goconst
- gocritic
- misspell
- prealloc
- copyloopvar
- nakedret
- unparam
- gosec
- noctx
- sqlclosecheck
- nolintlint
settings:
gocyclo:
min-complexity: 15
dupl:
threshold: 150
goconst:
min-len: 2
min-occurrences: 3
misspell:
locale: US
gocritic:
enabled-checks:
- rangeValCopy
- appendCombine
- captLocal
- ifElseChain
- sloppyLen
nolintlint:
require-explanation: true
require-specific: true
revive:
rules:
- name: exported
disabled: false
exclusions:
paths:
- vendor
- third_party
- gen
- generated
- ".*_generated\\.go"
- ".*\\.pb\\.go"
- ".*_mock\\.go"
rules:
- path: '(.+)_test\.go'
linters:
- unparam
- gocyclo
- dupl
- gosec
- linters: [errcheck]
text: "Error return value of .*\\.(Close|Stop)\\(\\) is not checked"
- text: "context.WithCancel function results are not used"
source: "context\\.WithCancel\\("
default: none
enable:
- govet
- staticcheck
- errcheck
- ineffassign
- unused
- revive
- gocyclo
- dupl
- goconst
- gocritic
- misspell
- prealloc
- copyloopvar
- nakedret
- unparam
- gosec
- noctx
- sqlclosecheck
- nolintlint
settings:
gocyclo:
min-complexity: 15
dupl:
threshold: 150
goconst:
min-len: 2
min-occurrences: 3
misspell:
locale: US
gocritic:
enabled-checks:
- rangeValCopy
- appendCombine
nolintlint:
require-explanation: true
require-specific: true
revive:
rules:
- name: exported
disabled: false
exclusions:
paths:
- vendor
- third_party
- gen
- generated
- ".*_generated\\.go"
- ".*\\.pb\\.go"
- ".*_mock\\.go"
rules:
- path: '(.+)_test\.go'
linters:
- unparam
- gocyclo
- dupl
- gosec
- linters: [errcheck]
text: "Error return value of .*\\.(Close|Stop)\\(\\) is not checked"
- text: "context.WithCancel function results are not used"
source: "context\\.WithCancel\\("

issues:
max-issues-per-linter: 0
max-same-issues: 0
max-issues-per-linter: 0
max-same-issues: 0

formatters:
enable:
- gofumpt
settings:
gofumpt:
extra-rules: true
enable:
- gofumpt
settings:
gofumpt:
extra-rules: true
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ go run ./cmd/agent -a http://localhost:8080 -r 10 -p 2 -l 2
# -r report interval (s), -p poll interval (s), -l parallel senders
```

3) Build with version info
To include build version, date, and commit in the binaries, use the following commands:

```bash
go build -o bin/server \
-ldflags "\
-X 'main.buildVersion=v1.2.5' \
-X 'main.buildDate=2025-12-14T10:00:00Z' \
-X 'main.buildCommit=abc1234' \
" ./cmd/server

go build -o bin/agent \
-ldflags "\
-X 'main.buildVersion=v1.2.5' \
-X 'main.buildDate=2025-12-14T10:00:00Z' \
-X 'main.buildCommit=abc1234' \
" ./cmd/agent
```

Open http://localhost:8080 to see metrics.

## API (HTTP)
Expand Down Expand Up @@ -126,4 +145,4 @@ You can use ENV, CLI flags, or defaults (ENV > CLI > defaults).

## Metrics you’ll see

Go runtime gauges like Alloc, HeapAlloc, NumGC, PauseTotalNs, plus host gauges TotalMemory, FreeMemory, and per-core CPUutilization{N}; counters include PollCount, etc.
Go runtime gauges like Alloc, HeapAlloc, NumGC, PauseTotalNs, plus host gauges TotalMemory, FreeMemory, and per-core CPUutilization{N}; counters include PollCount, etc.
13 changes: 13 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ import (
"github.com/vshulcz/Golectra/internal/adapters/publisher/httpjson"
"github.com/vshulcz/Golectra/internal/config"
agentsvc "github.com/vshulcz/Golectra/internal/services/agent"
"github.com/vshulcz/Golectra/pkg/util"
)

var (
buildVersion string
buildDate string
buildCommit string
)

func main() {
printBuildInfo()

cfg, err := config.LoadAgentConfig(os.Args[1:], nil)
if err != nil {
log.Fatalf("failed to parse flags: %v", err)
Expand All @@ -36,3 +45,7 @@ func main() {
log.Fatal(err)
}
}

func printBuildInfo() {
util.PrintBuildInfo(buildVersion, buildDate, buildCommit)
}
11 changes: 11 additions & 0 deletions cmd/agent/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"testing"
)

func TestBuildVariablesExist(t *testing.T) {
_ = buildVersion
_ = buildDate
_ = buildCommit
}
28 changes: 28 additions & 0 deletions cmd/reset/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"fmt"
"os"
"path/filepath"
)

// findModuleRoot finds the root directory of the Go module by looking for the go.mod file upwards from the current working directory.
func findModuleRoot() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}
dir := wd

for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
return dir, nil
}
parent := filepath.Dir(dir)
if parent == dir {
break
}
dir = parent
}
return "", fmt.Errorf("go.mod not found upwards from %s", wd)
}
Loading