From 4538137ce4c3fec9483f1a76e9ad3851816e1c71 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sun, 15 Jun 2025 16:13:53 +0300 Subject: [PATCH 1/5] fix --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c7d2fdb..8d98ab8 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,8 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response w.WriteHeader(status) } go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method) - log.Printf("%s %d %s", r.URL, status, time.Since(start)) + if r.URL == "/api/v1/finish" || r.URL == "/api/v1/put": + log.Printf("%s %d %s", r.URL, status, time.Since(start)) } } -- 2.45.2 From cc2875563fdb2ccdbb9d0f46bb9863514ee85254 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sun, 15 Jun 2025 16:18:11 +0300 Subject: [PATCH 2/5] fix --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 8d98ab8..8d75555 100644 --- a/main.go +++ b/main.go @@ -49,8 +49,9 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response w.WriteHeader(status) } go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method) - if r.URL == "/api/v1/finish" || r.URL == "/api/v1/put": + if r.URL.Path != "/api/v1/take" { log.Printf("%s %d %s", r.URL, status, time.Since(start)) + } } } -- 2.45.2 From db88db8b200b7b2223d4c908ec5c27be032221f0 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sun, 15 Jun 2025 16:26:25 +0300 Subject: [PATCH 3/5] fix --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8d75555..d81b70a 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response } else { w.WriteHeader(status) } - go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method) + // go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method) if r.URL.Path != "/api/v1/take" { log.Printf("%s %d %s", r.URL, status, time.Since(start)) } -- 2.45.2 From 7a99b36b004c955c577dd6ede398ddc1951de838 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sun, 15 Jun 2025 16:35:32 +0300 Subject: [PATCH 4/5] fix --- main.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d81b70a..c7d2fdb 100644 --- a/main.go +++ b/main.go @@ -48,10 +48,8 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response } else { w.WriteHeader(status) } - // go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method) - if r.URL.Path != "/api/v1/take" { - log.Printf("%s %d %s", r.URL, status, time.Since(start)) - } + go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method) + log.Printf("%s %d %s", r.URL, status, time.Since(start)) } } -- 2.45.2 From 35dcc8390cff657e69ea295525520569946a1a94 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sun, 15 Jun 2025 17:05:18 +0300 Subject: [PATCH 5/5] fix --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index c7d2fdb..e8fb004 100644 --- a/main.go +++ b/main.go @@ -53,12 +53,18 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response } } +func metricProxy(w http.ResponseWriter, r *http.Request) { + http.Post("http://monitoring:1237/api/v1/metrics/task", "application/json", r.Body) + w.WriteHeader(202) +} + func main() { client.Connect() routers.MutexMap = make(map[string]*sync.Mutex) http.HandleFunc("/api/v1/take", handlerWrapper(routers.Take)) http.HandleFunc("/api/v1/finish", handlerWrapper(routers.Finish)) http.HandleFunc("/api/v1/put", handlerWrapper(routers.Put)) + http.HandleFunc("/api/v1/metric", metricProxy) log.Printf("Server started") http.ListenAndServe(":1239", nil) } -- 2.45.2