apps/node 중심 구현 — TCP+JSON transport, Hexagonal Architecture, mock/cli adapter, fx DI, SQLite 실행 이력 저장. edge/control-plane/worker는 cobra placeholder. 유닛 테스트 및 통합 테스트 클라이언트 계획서 추가.
34 lines
891 B
Go
34 lines
891 B
Go
package observability
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
// NewLogger creates a zap production logger at the given level.
|
|
func NewLogger(level string) (*zap.Logger, error) {
|
|
cfg := zap.NewProductionConfig()
|
|
lvl, err := zapcore.ParseLevel(level)
|
|
if err != nil {
|
|
lvl = zapcore.InfoLevel
|
|
}
|
|
cfg.Level = zap.NewAtomicLevelAt(lvl)
|
|
return cfg.Build()
|
|
}
|
|
|
|
// ServeMetrics starts a Prometheus /metrics endpoint on the given port.
|
|
// It blocks until the server exits.
|
|
func ServeMetrics(port int) error {
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/metrics", promhttp.Handler())
|
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write([]byte("ok"))
|
|
})
|
|
addr := fmt.Sprintf(":%d", port)
|
|
return http.ListenAndServe(addr, mux)
|
|
}
|