fix
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Deploy Dev / Build (pull_request) Successful in 59s
				
			
		
			
				
	
				Deploy Dev / Push (pull_request) Successful in 37s
				
			
		
			
				
	
				Deploy Dev / Deploy dev (pull_request) Successful in 15s
				
			
		
			
				
	
				Deploy Prod / Build (pull_request) Successful in 58s
				
			
		
			
				
	
				Deploy Prod / Push (pull_request) Successful in 39s
				
			
		
			
				
	
				Deploy Prod / Deploy prod (pull_request) Successful in 15s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Deploy Dev / Build (pull_request) Successful in 59s
				
			Deploy Dev / Push (pull_request) Successful in 37s
				
			Deploy Dev / Deploy dev (pull_request) Successful in 15s
				
			Deploy Prod / Build (pull_request) Successful in 58s
				
			Deploy Prod / Push (pull_request) Successful in 39s
				
			Deploy Prod / Deploy prod (pull_request) Successful in 15s
				
			This commit is contained in:
		@@ -8,6 +8,7 @@ services:
 | 
				
			|||||||
      - clickhouse-development
 | 
					      - clickhouse-development
 | 
				
			||||||
    environment:
 | 
					    environment:
 | 
				
			||||||
      CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_DEV
 | 
					      CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_DEV
 | 
				
			||||||
 | 
					      STAGE: "development"
 | 
				
			||||||
    deploy:
 | 
					    deploy:
 | 
				
			||||||
      mode: replicated
 | 
					      mode: replicated
 | 
				
			||||||
      restart_policy:
 | 
					      restart_policy:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ services:
 | 
				
			|||||||
      - monitoring
 | 
					      - monitoring
 | 
				
			||||||
    environment:
 | 
					    environment:
 | 
				
			||||||
      CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD
 | 
					      CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD
 | 
				
			||||||
 | 
					      STAGE: "production"
 | 
				
			||||||
    deploy:
 | 
					    deploy:
 | 
				
			||||||
      mode: replicated
 | 
					      mode: replicated
 | 
				
			||||||
      restart_policy:
 | 
					      restart_policy:
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										19
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								main.go
									
									
									
									
									
								
							@@ -7,10 +7,28 @@ import (
 | 
				
			|||||||
	increment "monitoring/app/routers/metrics"
 | 
						increment "monitoring/app/routers/metrics"
 | 
				
			||||||
	task "monitoring/app/routers/metrics"
 | 
						task "monitoring/app/routers/metrics"
 | 
				
			||||||
	client "monitoring/app/storage/clickhouse"
 | 
						client "monitoring/app/storage/clickhouse"
 | 
				
			||||||
 | 
						endpoints "monitoring/app/storage/clickhouse/tables"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func writeMetric(timestamp time.Time, endpoint string, statusCode int, responseTime int, method string) {
 | 
				
			||||||
 | 
						loc, _ := time.LoadLocation("Europe/Moscow")
 | 
				
			||||||
 | 
						err := endpoints.AddEndpointMetric(endpoints.EndpointMetric{
 | 
				
			||||||
 | 
							Timestamp:    timestamp.In(loc),
 | 
				
			||||||
 | 
							Service:      "monitoring",
 | 
				
			||||||
 | 
							Environment:  os.Getenv("STAGE"),
 | 
				
			||||||
 | 
							Endpoint:     endpoint,
 | 
				
			||||||
 | 
							StatusCode:   statusCode,
 | 
				
			||||||
 | 
							ResponseTime: responseTime,
 | 
				
			||||||
 | 
							Method:       method,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("Error sending metrics %s", err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.ResponseWriter, *http.Request) {
 | 
					func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.ResponseWriter, *http.Request) {
 | 
				
			||||||
	return func(w http.ResponseWriter, r *http.Request) {
 | 
						return func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		start := time.Now()
 | 
							start := time.Now()
 | 
				
			||||||
@@ -26,6 +44,7 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response
 | 
				
			|||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			w.WriteHeader(status)
 | 
								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))
 | 
							log.Printf("%s %d %s", r.URL, status, time.Since(start))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user