Skip to content

(feat/server) Collecting runtime metrics#1

Merged
srg-bnd merged 16 commits intomainfrom
iter1
Feb 24, 2025
Merged

(feat/server) Collecting runtime metrics#1
srg-bnd merged 16 commits intomainfrom
iter1

Conversation

@srg-bnd
Copy link
Owner

@srg-bnd srg-bnd commented Feb 4, 2025

No description provided.

@srg-bnd srg-bnd added the enhancement New feature or request label Feb 4, 2025
@srg-bnd srg-bnd requested a review from Perederey February 4, 2025 10:57
@srg-bnd srg-bnd self-assigned this Feb 4, 2025
Copy link

@Perederey Perederey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет
Хорошая базовая структура проекта и тестовое покрытие!

@@ -0,0 +1,60 @@
package storage

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отличное покрытие тестами для пакета

"github.com/srg-bnd/observator/internal/storage"
)

var (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используй отдельную структуру для обработчиков, чтобы избежать глобальных переменных


type Middleware func(http.Handler) http.Handler

func Conveyor(h http.Handler, middlewares ...Middleware) http.Handler {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переименуй в Chain, так  обычно это делают в гоу

)

var (
MemStorage *storage.MemStorage

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И тут еще, нарушен принцип инверсии зависимостей - сервер не должен знать о конкретной реализации хранилища


// Services

func UpdateMetricService(metricType, metricName, metricValue string) *Data {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И вот тут еще у тебя, слой содержит бизнес-логику смешанную с форматированием данных, надо разделить ответственность

MemStorage *storage.MemStorage
)

func UpdateMetricHandler(res http.ResponseWriter, req *http.Request) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateMetricHandler содержит слишком много логики. Лучше разделить на валидацию и обработку. Типа такого:

func (h *Handler) UpdateMetricHandler(w http.ResponseWriter, r *http.Request) {
    metric, err := h.parseAndValidateMetric(r)
    if err != nil {
        h.handleError(w, err)
        return
    }
    h.processMetric(w, metric)
}

"github.com/srg-bnd/observator/internal/storage"
)

var memStorage storage.MemStorage

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И еще тут напишу, вместо глобальных переменных и init() лучше использовать внедрение зависимостей. Вот так примерно
Как обещал на 1:1 вот код

type App struct {
    storage *storage.MemStorage
    server  *server.Server
}

func NewApp() *App {
    storage := storage.NewMemStorage()
    return &App{
        storage: storage,
        server: server.NewServer(storage),
    }
}

@srg-bnd
Copy link
Owner Author

srg-bnd commented Feb 12, 2025

@Perederey решил все конфликты и влил в iter2

@srg-bnd srg-bnd changed the title Server for collecting runtime metrics (feat/server) Collecting runtime metrics Feb 13, 2025
@srg-bnd srg-bnd merged commit a6cea9e into main Feb 24, 2025
3 checks passed
@srg-bnd srg-bnd deleted the iter1 branch May 31, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants