Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iter21 #24

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d1eb11a
добавил TODO
StasMerzlyakov Mar 20, 2024
9786d78
актуализировал вопросы
StasMerzlyakov Mar 20, 2024
a1b5354
переделал metric_operation_handler - убрал все что относится к бизнес…
StasMerzlyakov Mar 22, 2024
7e4c3a8
восстанавливаю тесты;
StasMerzlyakov Mar 22, 2024
c068828
убрал лишний код, поправил мидлу с логированием статуса ответа
StasMerzlyakov Mar 23, 2024
30cc8b6
актуализировал вопросы
StasMerzlyakov Mar 23, 2024
531f64a
реализовал agent
StasMerzlyakov Mar 23, 2024
0a35610
отладил проверку запроса
StasMerzlyakov Mar 23, 2024
1492c7f
мидла на ответ
StasMerzlyakov Mar 23, 2024
e5dacd7
поправпил статику
StasMerzlyakov Mar 23, 2024
c787c18
актуализировал вопросы
StasMerzlyakov Mar 23, 2024
98be88a
iter15
StasMerzlyakov Mar 27, 2024
bd3cb60
переименовал sender, отвечаюищий за пул
StasMerzlyakov Mar 27, 2024
0bd408e
поправил время в time.Sleep
StasMerzlyakov Mar 27, 2024
861d389
добавил вопрос по горутины
StasMerzlyakov Mar 27, 2024
fa5d552
iter16
StasMerzlyakov May 15, 2024
1548689
передалал на общий логгер
StasMerzlyakov May 19, 2024
3cb3b6d
добавил профилирование
StasMerzlyakov May 19, 2024
40ce5bf
Наработки
StasMerzlyakov May 19, 2024
6b7fe19
Merge branch 'main' into iter16
StasMerzlyakov May 19, 2024
2e60e3a
поправил импорт
StasMerzlyakov May 19, 2024
7c0a33b
добавил вопрос
StasMerzlyakov May 19, 2024
cbac13c
ещё правка
StasMerzlyakov May 19, 2024
bb38b0a
добавил скрипт для локального прогона тестов
StasMerzlyakov May 19, 2024
8dcbe54
добавил скрипт форматирования
StasMerzlyakov May 20, 2024
88b00c0
отформатировал goimports
StasMerzlyakov May 20, 2024
5af9320
убрал мусор
StasMerzlyakov May 20, 2024
43ebf89
добавил скрипт для сравнения результатов
StasMerzlyakov May 21, 2024
4f6f001
инкремент 18
StasMerzlyakov May 22, 2024
d813ad4
поправил ReadAll, добавил Questions
StasMerzlyakov May 23, 2024
961c096
Актуализировал TODO, Questions по итогам созвона
StasMerzlyakov May 26, 2024
00bd9d8
добавил requestID мидлу; убрал лишие выводы в лог
StasMerzlyakov May 29, 2024
12db9c3
добавил тестов с testcontainers
StasMerzlyakov May 29, 2024
56696da
добавил retriable мидлу, убрал retriable-wrapper перед хранилищем
StasMerzlyakov May 29, 2024
b3ee753
поправил проект для работы staticcheck
StasMerzlyakov Jun 3, 2024
998d257
перенес retryable в agent - применяется только там; server переведен …
StasMerzlyakov Jun 3, 2024
e52a0fe
наработки
StasMerzlyakov Jun 3, 2024
c726b66
добавил config.json
StasMerzlyakov Jun 4, 2024
3f2d8ce
отключил проверку генерируемых go test файлов
StasMerzlyakov Jun 4, 2024
2f2896f
Merge branch 'main' into iter19
StasMerzlyakov Jun 4, 2024
15865d6
добавил глобальные переменные
StasMerzlyakov Jun 9, 2024
ba815ad
поправил вызов shell-команд через Makefile
StasMerzlyakov Jun 9, 2024
b9dfa0c
убрал бинарник из исходников
StasMerzlyakov Jun 9, 2024
d870562
исправления по замечаниям
StasMerzlyakov Jun 12, 2024
721fac6
Merge branch 'iter20' into iter21
StasMerzlyakov Jun 12, 2024
1e7ae05
добавил nolint(для примера)
StasMerzlyakov Jun 12, 2024
b0bf085
добавил скрипт для проверки тестового покрытия
StasMerzlyakov Jun 12, 2024
a82a6a7
забытое изменение с http.Error
StasMerzlyakov Jun 12, 2024
aad3a6e
разбираюсь с coverage
StasMerzlyakov Jun 12, 2024
9cbe995
обновил зависимости
StasMerzlyakov Jun 12, 2024
0688ff4
обновил зависимости
StasMerzlyakov Jun 12, 2024
a636f16
разобрался с cover
StasMerzlyakov Jun 12, 2024
8e0475f
добавляю тесты
StasMerzlyakov Jun 13, 2024
a58722f
ещё тесты
StasMerzlyakov Jun 13, 2024
c3987b1
оптимизация
StasMerzlyakov Jun 13, 2024
524f34b
убрал goconvey sample тест
StasMerzlyakov Jun 14, 2024
2c0bf4d
Для исключения сгенерированных mock-файлов из анализа go cover, gomoc…
StasMerzlyakov Jun 14, 2024
ee4c085
добавил тестов
StasMerzlyakov Jun 14, 2024
88a61ae
ещё тесты
StasMerzlyakov Jun 14, 2024
a15cab8
убрал лишний метод
StasMerzlyakov Jun 14, 2024
c920e11
добавил ещё тестов - покрытие 41.49%
StasMerzlyakov Jun 14, 2024
550d346
утилита для генерации файлов с ключами
StasMerzlyakov Jun 16, 2024
7170930
реализовал шифрование данных
StasMerzlyakov Jun 16, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.html

# Binaries
cmd/agent/main
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
.PHONY: build test clean

build:
go clean -testcache
GOOS=linux GOARCH=amd64 go build -buildvcs=false -o=cmd/server ./cmd/server/...
GOOS=linux GOARCH=amd64 go build -buildvcs=false -ldflags "-X main.buildVersion=v1.0.1 -X main.buildDate=$(shell date +'%Y-%m-%d') -X main.buildCommit=$(shell git rev-parse HEAD)" -o=cmd/agent ./cmd/agent/...
GOOS=linux GOARCH=amd64 go build -buildvcs=false -o=cmd/keygen ./cmd/keygen/...

test: build
GOOS=linux GOARCH=amd64 go build -buildvcs=false -o=cmd/staticlint ./cmd/staticlint/...
cmd/staticlint/staticlint ./...
go mod tidy
go mod vendor
go test ./...
go clean -testcache
go test ./... -coverprofile cover.out.tmp
cat cover.out.tmp | grep -v "mocks" > cover.out
rm cover.out.tmp

cover: test
go tool cover -html=cover.out -o coverage.html
firefox coverage.html &
3 changes: 1 addition & 2 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"syscall"

"github.com/StasMerzlyakov/go-metrics/internal/agent"
"github.com/StasMerzlyakov/go-metrics/internal/agent/retriable"
"github.com/StasMerzlyakov/go-metrics/internal/config"
)

Expand Down Expand Up @@ -46,7 +45,7 @@ func main() {
resultSender := agent.NewHTTPResultSender(agentCfg)

// Отвечает за повтор отправки
retryCfg := retriable.DefaultConf(syscall.ECONNREFUSED)
retryCfg := agent.DefaultConf(syscall.ECONNREFUSED)
retryableResultSender := agent.NewHTTPRetryableResultSender(*retryCfg, resultSender)

// Отвечает за пулы отправки
Expand Down
Binary file added cmd/keygen/keygen
Binary file not shown.
32 changes: 32 additions & 0 deletions cmd/keygen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Package main contains utility for key generation
package main

import (
"os"

"github.com/StasMerzlyakov/go-metrics/internal/keygen"
)

const (
publicKeyFileName = "./public.key"
privateKeyFileName = "./private.key"
)

func main() {

privKeyFile, err := os.Create(privateKeyFileName)
if err != nil {
panic(err)
}
defer privKeyFile.Close()

pubKeyFile, err := os.Create(publicKeyFileName)
if err != nil {
panic(err)
}
defer privKeyFile.Close()

if err := keygen.Create(pubKeyFile, privKeyFile); err != nil {
panic(err)
}
}
27 changes: 23 additions & 4 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"time"

"github.com/StasMerzlyakov/go-metrics/internal/config"
"github.com/StasMerzlyakov/go-metrics/internal/keygen"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/fs/backup"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/handler"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/compress"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/cryptomw"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/digest"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/logging"
"github.com/StasMerzlyakov/go-metrics/internal/server/adapter/http/middleware/retry"
Expand All @@ -24,7 +26,6 @@ import (
"github.com/go-chi/chi/v5"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5/pgconn"

"go.uber.org/zap"
)

Expand All @@ -33,10 +34,15 @@ type Server interface {
Shutdown(ctx context.Context)
}

const (
maxRetryCount = 4
)

func createMiddleWareList(srvConf *config.ServerConfiguration) []func(http.Handler) http.Handler {
var mwList []func(http.Handler) http.Handler
mwList = append(mwList, logging.EncrichWithRequestIDMW())
mwList = append(mwList, logging.NewLoggingResponseMW())

if srvConf.Key != "" {
mwList = append(mwList, digest.NewWriteHashDigestResponseHeaderMW(srvConf.Key))
}
Expand Down Expand Up @@ -66,7 +72,10 @@ func createMiddleWareList(srvConf *config.ServerConfiguration) []func(http.Handl
return err
}
mwList = append(mwList, retry.NewRetriableRequestMWConf(
time.Duration(time.Second), time.Duration(2*time.Second), 4, pgErrPreProcFn,
time.Duration(time.Second),
time.Duration(2*time.Second),
maxRetryCount,
pgErrPreProcFn,
))

return mwList
Expand Down Expand Up @@ -157,12 +166,22 @@ func main() {

// мидлы
mwList := createMiddleWareList(srvConf)
middleware.Add(httpHandler, mwList...)

httpHandler.Use(mwList...)

// операции с метриками
metricApp := app.NewMetrics(storage)

var updateMWList []func(http.Handler) http.Handler
var updateMWList []middleware.Middleware

if srvConf.CryptoKey != "" {
privKey, err := keygen.ReadPrivKey(srvConf.CryptoKey)
if err != nil {
panic(err)
}
updateMWList = append(updateMWList, cryptomw.NewDecrytpMw(privKey))
}

if srvConf.Key != "" {
updateMWList = append(updateMWList, digest.NewCheckHashDigestRequestMW(srvConf.Key))
}
Expand Down
4 changes: 0 additions & 4 deletions cover.sh

This file was deleted.

29 changes: 14 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
module github.com/StasMerzlyakov/go-metrics

go 1.21

toolchain go1.22.2
go 1.22.2

require (
github.com/caarlos0/env v3.5.0+incompatible
github.com/go-chi/chi/v5 v5.0.11
github.com/go-resty/resty/v2 v2.11.0
github.com/go-chi/chi/v5 v5.0.12
github.com/go-resty/resty/v2 v2.13.1
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgx/v5 v5.5.4
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
github.com/jackc/pgx/v5 v5.6.0
github.com/jingyugao/rowserrcheck v1.1.1
github.com/kisielk/errcheck v1.7.0
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil/v3 v3.24.2
github.com/shirou/gopsutil/v3 v3.24.5
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.31.0
github.com/testcontainers/testcontainers-go/modules/postgres v0.31.0
github.com/ungerik/go-pool v0.0.0-20140720100922-d102a2c7872a
go.uber.org/zap v1.27.0
golang.org/x/tools v0.21.1-0.20240514024235-59d9797072e7
golang.org/x/tools v0.22.0
gotest.tools/v3 v3.5.0
honnef.co/go/tools v0.4.7
)

Expand All @@ -46,6 +45,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
Expand All @@ -61,7 +61,6 @@ require (
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
Expand All @@ -71,13 +70,13 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
Loading
Loading