.forgejo: Add pre-commit #7

Merged
fyrchik merged 3 commits from fyrchik/frostfs-observability:add-workflows into master 2024-09-04 19:51:22 +00:00
13 changed files with 165 additions and 17 deletions

View file

@ -0,0 +1,21 @@
name: DCO action
on: [pull_request]
jobs:
dco:
name: DCO
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Run commit format checker
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3
with:
from: 'origin/${{ github.event.pull_request.base.ref }}'

View file

@ -0,0 +1,73 @@
name: Tests and linters
on: [pull_request]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
cache: true
- name: Install linters
run: make lint-install
- name: Run linters
run: make lint
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
go_versions: [ '1.20', '1.21' ]
fail-fast: false
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '${{ matrix.go_versions }}'
cache: true
- name: Run tests
run: make test
tests-race:
name: Tests with -race
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
cache: true
- name: Run tests
run: go test ./... -count=1 -race
staticcheck:
name: Staticcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
cache: true
- name: Install staticcheck
run: make staticcheck-install
- name: Run staticcheck
run: make staticcheck-run

View file

@ -52,7 +52,7 @@ linters:
- durationcheck
- exhaustive
- exportloopref
- gofmt
- gofumpt
- goimports
- misspell
- predeclared

53
Makefile Normal file → Executable file
View file

@ -1,14 +1,63 @@
#!/usr/bin/make -f
SHELL = bash
TRUECLOUDLAB_LINT_VERSION ?= 0.0.3
TMP_DIR := .cache
OUTPUT_LINT_DIR ?= $(shell pwd)/bin
LINT_VERSION ?= 1.55.2
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
# Run all code formatters
fmts: fmt imports
# Reformat code
fmt:
@echo "⇒ Processing gofmt check"
@gofumpt -s -w .
# Reformat imports
imports:
@echo "⇒ Processing goimports check"
@goimports -w .
# Run Unit Test with go test
test:
@echo "⇒ Running go test"
@go test ./... -count=1
# Activate pre-commit hooks
pre-commit:
pre-commit install -t pre-commit -t commit-msg
# Deactivate pre-commit hooks
unpre-commit:
pre-commit uninstall -t pre-commit -t commit-msg
pre-commit-run:
@pre-commit run -a --hook-stage manual
# Install linters
lint-install:
@mkdir -p $(TMP_DIR)
@rm -rf $(TMP_DIR)/linters
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
@rm -rf $(TMP_DIR)/linters
@rmdir $(TMP_DIR) 2>/dev/null || true
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
# Run linters
lint:
@golangci-lint --timeout=5m run
@if [ ! -d "$(LINT_DIR)" ]; then \
echo "Run make lint-install"; \
exit 1; \
fi
@$(LINT_DIR)/golangci-lint run
# Install staticcheck
staticcheck-install:
@go install honnef.co/go/tools/cmd/staticcheck@latest
# Run staticcheck
staticcheck:
staticcheck-run:
@staticcheck ./...

View file

@ -1,6 +1,8 @@
package main
import (
"fmt"
"os"
"strconv"
"sync"
"time"
@ -10,8 +12,10 @@ import (
var wg sync.WaitGroup
const countMsgGroup = 100
const countMsg = 500000
const (
countMsgGroup = 100
countMsg = 500000
)
func send(loki *loki.Client) {
wg.Add(1)
@ -19,7 +23,10 @@ func send(loki *loki.Client) {
for j := 0; j < countMsg/countMsgGroup; j++ {
for i := 0; i < countMsgGroup; i++ {
loki.Send(strconv.Itoa(j)+" "+strconv.Itoa(i)+" test log message", time.Now())
err := loki.Send(strconv.Itoa(j)+" "+strconv.Itoa(i)+" test log message", time.Now())
if err != nil {
fmt.Fprintf(os.Stderr, "send: %v", err)
}
}
time.Sleep(20 * time.Millisecond)
}

View file

@ -6,8 +6,9 @@ import (
"time"
)
// Send sends the message to the loki server.
// If the client is disabled, it returns error.
// If the entries channel is full, the message is discarded and returns error
// If the entries channel is full, the message is discarded and returns error.
func (client *Client) Send(msg string, timestamp time.Time) error {
if !client.IsEnabled() {
client.missedMessages++

View file

@ -35,7 +35,6 @@ func (client *Client) sendLogs(entries []logEntry) {
func (client *Client) sendRequest(method, url string, ctype string, reqBody []byte) {
req, err := http.NewRequest(method, url, bytes.NewBuffer(reqBody))
if err != nil {
return
}

View file

@ -97,7 +97,6 @@ func main() {
resp, err := client.Echo(ctx, &srv.Request{
Value: "Hello!",
})
if err != nil {
log.Fatalf("failed to get response: %v", err)
}

View file

@ -124,7 +124,6 @@ func TestPropagator_Inject(t *testing.T) {
require.Equal(t, spanIDHex, c.Values[spanIDHeader], "unexpected span id")
require.Equal(t, "0", c.Values[flagsHeader], "unexpected flags")
})
}
func TestPropagator_Extract(t *testing.T) {