Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
5995530
init commit, wrote first version metrics
rAch-kaplin Jun 26, 2025
4fcd698
first version
rAch-kaplin Jun 26, 2025
68a44fe
add go.mod
rAch-kaplin Jun 26, 2025
1c11cbf
change go version for CI
rAch-kaplin Jun 26, 2025
4642ae6
wrote func removeEmptyStrings()
rAch-kaplin Jun 26, 2025
d832015
fixed bugs, first version with successful tests
rAch-kaplin Jun 27, 2025
ff4357f
for static testing I downgraded the version of go
rAch-kaplin Jun 27, 2025
d9e3fff
add my logger
rAch-kaplin Jun 29, 2025
ac4f43a
add agent v.1, without tests
rAch-kaplin Jul 1, 2025
47e938b
divided into section
rAch-kaplin Jul 1, 2025
7de3fec
add tests for server
rAch-kaplin Jul 1, 2025
60d1be8
change go version <statictest.yml>
rAch-kaplin Jul 2, 2025
983a56d
fixed errors for statictest
rAch-kaplin Jul 2, 2025
7e8e354
renamed package memStorage
rAch-kaplin Jul 2, 2025
2b448d2
deleted MemStorage
rAch-kaplin Jul 2, 2025
9622d24
again renamed memStorage
rAch-kaplin Jul 2, 2025
e5ba7d9
renamed package memstorage
rAch-kaplin Jul 2, 2025
692f20d
first version iter3, with libs: chi, resty
rAch-kaplin Jul 2, 2025
e903bff
added a command line flag handler
rAch-kaplin Jul 3, 2025
559c811
fixed the independence of the server and agent
rAch-kaplin Jul 3, 2025
008c208
fixed test 2A
rAch-kaplin Jul 3, 2025
0647cfd
fixed POST request url
rAch-kaplin Jul 3, 2025
c1076df
first version env
rAch-kaplin Jul 3, 2025
0a4e347
fixed defaults values
rAch-kaplin Jul 3, 2025
b128e7f
mada variables exportable for env
rAch-kaplin Jul 3, 2025
0a26bab
made some changes after the review
rAch-kaplin Jul 4, 2025
80e853b
rewrote the flag library to cobra
rAch-kaplin Jul 4, 2025
d76298f
made NewRouter() for test and main
rAch-kaplin Jul 4, 2025
d31986e
fixed lint errors
rAch-kaplin Jul 4, 2025
551f0a4
fixed lint errors
rAch-kaplin Jul 4, 2025
de81e2f
rewrote my logger to zerolog
rAch-kaplin Jul 5, 2025
facea5a
switched to zerolog and wrote a logger for the server
rAch-kaplin Jul 5, 2025
e6d5ea7
some commit
rAch-kaplin Jul 6, 2025
076fe0d
update go-version go.mod
rAch-kaplin Jul 6, 2025
f40ac69
update statictest for my rep
rAch-kaplin Jul 6, 2025
4410247
delete .git for rep req
rAch-kaplin Jul 6, 2025
52d9f4c
update rep in metrictest
rAch-kaplin Jul 6, 2025
6f4ca86
update to ver -> 1.24.3
rAch-kaplin Jul 6, 2025
06c1745
refactor storage
rAch-kaplin Jul 6, 2025
db279a7
empty
rAch-kaplin Jul 6, 2025
0c0f028
rewrote the storage logic
rAch-kaplin Jul 7, 2025
74cfb61
ufter review for merge to main
rAch-kaplin Jul 8, 2025
74abce7
wrote a log for the server
rAch-kaplin Jul 5, 2025
f4406df
first easyjson-JSON version
rAch-kaplin Jul 7, 2025
f2698a4
add tests
rAch-kaplin Jul 7, 2025
439daa1
after rebase iter6, change
rAch-kaplin Jul 9, 2025
ce1e133
first easyjson-JSON version
rAch-kaplin Jul 7, 2025
68039a5
add tests
rAch-kaplin Jul 7, 2025
2a39f46
first version compress file gzip
rAch-kaplin Jul 8, 2025
f41b361
after rebase iter7 (from change in iter5 to merge)
rAch-kaplin Jul 9, 2025
9dfa52e
empty commit
rAch-kaplin Jul 9, 2025
33cf189
add os data-base, need fix test (imports cycle)
rAch-kaplin Jul 10, 2025
1ab2d84
Squash merge main into current branch
rAch-kaplin Jul 10, 2025
772212a
merge from main
rAch-kaplin Jul 10, 2025
079366f
merge from main2
rAch-kaplin Jul 10, 2025
dac7d68
resolves conflicts
rAch-kaplin Jul 10, 2025
3d09f16
start write funcs options
rAch-kaplin Jul 11, 2025
0735857
add functional options pattern for server
rAch-kaplin Jul 11, 2025
621ba8e
add functional options pattern
rAch-kaplin Jul 11, 2025
89acb00
add go mod download
rAch-kaplin Jul 11, 2025
220626e
add context
rAch-kaplin Jul 11, 2025
08107ed
first version pingDataBase
rAch-kaplin Jul 11, 2025
d6b3471
fix my tests
rAch-kaplin Jul 11, 2025
2dbdc19
empty commit
rAch-kaplin Jul 11, 2025
da3dcb1
empty commit2
rAch-kaplin Jul 12, 2025
e6d73ad
some corrections
rAch-kaplin Jul 12, 2025
9ebe508
change dirs
rAch-kaplin Jul 12, 2025
c34339b
optimization compresstion
rAch-kaplin Jul 16, 2025
1094957
after code review
rAch-kaplin Jul 16, 2025
f4e15b1
some corrects
rAch-kaplin Jul 16, 2025
40b9a26
empty commit, from iter10 version
rAch-kaplin Jul 12, 2025
8264e0d
Iter11 refactor (#14)
rAch-kaplin Jul 13, 2025
aec27e1
fix sync record for file base
rAch-kaplin Jul 13, 2025
a3c0746
fix ChoiceCollector
rAch-kaplin Jul 13, 2025
efbe35f
delete if len() from LoadFromDB()
rAch-kaplin Jul 13, 2025
ce90e6f
.
rAch-kaplin Jul 13, 2025
071421d
-
rAch-kaplin Jul 14, 2025
b7847de
add len(bytes) for Load
rAch-kaplin Jul 14, 2025
7f95a65
didn't fix
rAch-kaplin Jul 14, 2025
4bb4ad3
add create file for SaveToDB()
rAch-kaplin Jul 14, 2025
8fcb4fe
add logs for CI
rAch-kaplin Jul 14, 2025
fd3638e
maybe fix problem
rAch-kaplin Jul 15, 2025
07b2a23
fix save
rAch-kaplin Jul 15, 2025
329710e
fix request for postgres
rAch-kaplin Jul 15, 2025
a289790
fix db postgres
rAch-kaplin Jul 15, 2025
54f164d
rebase from iter10
rAch-kaplin Jul 16, 2025
b275fea
empty commit, from iter10 version
rAch-kaplin Jul 12, 2025
d3eb5c5
Iter11 refactor (#14)
rAch-kaplin Jul 13, 2025
e990777
fix ChoiceCollector
rAch-kaplin Jul 13, 2025
b71e7f9
delete if len() from LoadFromDB()
rAch-kaplin Jul 13, 2025
70a7116
.
rAch-kaplin Jul 13, 2025
23ad248
-
rAch-kaplin Jul 14, 2025
be6d91f
didn't fix
rAch-kaplin Jul 14, 2025
ec357bd
add create file for SaveToDB()
rAch-kaplin Jul 14, 2025
15b5949
add logs for CI
rAch-kaplin Jul 14, 2025
dd4a9dd
maybe fix problem
rAch-kaplin Jul 15, 2025
8ad75f9
fix save
rAch-kaplin Jul 15, 2025
1861e5c
first bad version, but worked, need to do refactor code
rAch-kaplin Jul 16, 2025
8dfb7c1
add serialization dir
rAch-kaplin Jul 16, 2025
02d20a4
change return value on GetMetric bool->error
rAch-kaplin Jul 16, 2025
816eeb3
add transaction
rAch-kaplin Jul 16, 2025
58437f7
fix lint
rAch-kaplin Jul 16, 2025
8ae3676
after rebase from iter11
rAch-kaplin Jul 16, 2025
271d644
change design for CRUD app
rAch-kaplin Jul 16, 2025
dffa07d
fix mutex on files database
rAch-kaplin Jul 16, 2025
98bdfe5
fix
rAch-kaplin Jul 16, 2025
f05c74a
add retriable-errors for postgres
rAch-kaplin Jul 17, 2025
ed3f309
resolved conflicts
rAch-kaplin Jul 17, 2025
37a2edc
after code review
rAch-kaplin Jul 20, 2025
65a2e95
fix files
rAch-kaplin Jul 20, 2025
d735b5d
fix psql
rAch-kaplin Jul 20, 2025
daf73ba
some correct
rAch-kaplin Jul 21, 2025
08b08fb
rename dirs
rAch-kaplin Jul 21, 2025
e5185cd
change sign on collector, test +
rAch-kaplin Jul 21, 2025
6d484e2
add usecases
rAch-kaplin Jul 22, 2025
f7ebdaf
fix lint
rAch-kaplin Jul 22, 2025
875d543
fix tests
rAch-kaplin Jul 23, 2025
f133150
simplified file storage
rAch-kaplin Jul 23, 2025
c45b556
add squirrel
rAch-kaplin Jul 23, 2025
062269d
add pinger
rAch-kaplin Jul 23, 2025
f0967ec
after code review
rAch-kaplin Jul 25, 2025
e019237
Merge branch 'main' into iter13
rAch-kaplin Jul 25, 2025
b69c2e3
add hashing
rAch-kaplin Jul 26, 2025
6894a4d
Merge branch 'main' into iter14
rAch-kaplin Jul 26, 2025
22239c6
add worker-pool, +14test
rAch-kaplin Jul 27, 2025
c2ae223
add rateLimit for worker-pool
rAch-kaplin Jul 27, 2025
4c367f5
add funcs options for agent
rAch-kaplin Jul 27, 2025
a62578a
after code review
rAch-kaplin Jul 27, 2025
15cdbb5
add some tests
rAch-kaplin Jul 27, 2025
edfd8b9
Merge branch 'main' into iter15
rAch-kaplin Jul 27, 2025
af7eb80
add bench, tests, pprof
rAch-kaplin Jul 28, 2025
816fff5
Merge branch 'main' into iter16
rAch-kaplin Jul 28, 2025
ab6b7d3
formatted the code
rAch-kaplin Jul 28, 2025
99e7002
Merge branch 'main' into iter17
rAch-kaplin Aug 10, 2025
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
2 changes: 1 addition & 1 deletion cmd/server/cfg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func runE(cmd *cobra.Command, args []string) error {

go func() {
fmt.Println("pprof listening on :6060")
http.ListenAndServe("localhost:6060", nil)
_ = http.ListenAndServe("localhost:6060", nil)
}()

ctx, cancel := context.WithCancel(context.Background())
Expand Down
1 change: 0 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ func main() {
os.Exit(1)
}
}

74 changes: 37 additions & 37 deletions internal/handlers/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,41 +175,41 @@ func TestGetMetric(t *testing.T) {
}

func TestGetAllMetrics(t *testing.T) {
opts := &srvCfg.Options{}
for _, opt := range []func(*srvCfg.Options){
srvCfg.WithAddress("localhost:8080"),
srvCfg.WithStoreInterval(300),
srvCfg.WithFileStoragePath("/tmp/metrics-db.json"),
srvCfg.WithRestoreOnStart(true),
} {
opt(opts)
}

ctx := context.Background()
storage := repo.NewMemStorage()

if err := storage.UpdateMetric(ctx, models.GaugeType, "cpu_usage", 75.5); err != nil {
log.Error().Msgf("Failed to update metric cpu_usage: %v", err)
}

if err := storage.UpdateMetric(ctx, models.CounterType, "requests_total", int64(100)); err != nil {
log.Error().Msgf("Failed to update metric requests_total: %v", err)
}

metricUsecase := srvUsecase.NewMetricUsecase(storage, storage, storage)
router := router.NewRouter(server.NewServer(metricUsecase, nil), opts)

t.Run("GetAllMetrics returned HTML metrics", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rr := httptest.NewRecorder()

router.ServeHTTP(rr, req)

assert.Equal(t, http.StatusOK, rr.Code)
body, _ := io.ReadAll(rr.Body)

assert.Contains(t, string(body), "cpu_usage")
assert.Contains(t, string(body), "requests_total")
assert.Contains(t, string(body), "<html>")
})
opts := &srvCfg.Options{}
for _, opt := range []func(*srvCfg.Options){
srvCfg.WithAddress("localhost:8080"),
srvCfg.WithStoreInterval(300),
srvCfg.WithFileStoragePath("/tmp/metrics-db.json"),
srvCfg.WithRestoreOnStart(true),
} {
opt(opts)
}

ctx := context.Background()
storage := repo.NewMemStorage()

if err := storage.UpdateMetric(ctx, models.GaugeType, "cpu_usage", 75.5); err != nil {
log.Error().Msgf("Failed to update metric cpu_usage: %v", err)
}

if err := storage.UpdateMetric(ctx, models.CounterType, "requests_total", int64(100)); err != nil {
log.Error().Msgf("Failed to update metric requests_total: %v", err)
}

metricUsecase := srvUsecase.NewMetricUsecase(storage, storage, storage)
router := router.NewRouter(server.NewServer(metricUsecase, nil), opts)

t.Run("GetAllMetrics returned HTML metrics", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rr := httptest.NewRecorder()

router.ServeHTTP(rr, req)

assert.Equal(t, http.StatusOK, rr.Code)
body, _ := io.ReadAll(rr.Body)

assert.Contains(t, string(body), "cpu_usage")
assert.Contains(t, string(body), "requests_total")
assert.Contains(t, string(body), "<html>")
})
}
1 change: 0 additions & 1 deletion internal/models/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ func (c *counter) Update(mValue any) error {
c.value += value
return nil
}

1 change: 0 additions & 1 deletion internal/models/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ func (g *gauge) Update(mValue any) error {
g.value = value
return nil
}

1 change: 1 addition & 0 deletions internal/models/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
"errors"
)

type Metric interface {
Value() any
Name() string
Expand Down
12 changes: 9 additions & 3 deletions internal/repository/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func TestDatabase_GetMetric(t *testing.T) {
if err != nil {
t.Fatalf("failed to create sqlmock: %v", err)
}
defer db.Close()
defer func() {
_ = db.Close()
}()

repo := &repo.Database{
DB: db,
Expand Down Expand Up @@ -139,7 +141,9 @@ func TestDatabase_GetAllMetrics(t *testing.T) {
if err != nil {
t.Fatalf("failed to create sqlmock: %v", err)
}
defer db.Close()
defer func() {
_ = db.Close()
}()

repo := &repo.Database{
DB: db,
Expand Down Expand Up @@ -214,7 +218,9 @@ func TestDatabase_UpdateMetric(t *testing.T) {
if err != nil {
t.Fatalf("failed to create sqlmock: %v", err)
}
defer db.Close()
defer func() {
_ = db.Close()
}()

repo := &repo.Database{
DB: db,
Expand Down