fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 1m4s
Deploy Dev / Push (pull_request) Successful in 36s
Deploy Dev / Deploy dev (pull_request) Successful in 10s
Deploy Prod / Build (pull_request) Successful in 1m0s
Deploy Prod / Push (pull_request) Successful in 36s
Deploy Prod / Deploy prod (pull_request) Successful in 16s

This commit is contained in:
Egor Matveev
2025-06-21 12:04:27 +03:00
parent dce65faffd
commit ea63cd794c
8 changed files with 173 additions and 108 deletions

View File

@@ -1,45 +1,11 @@
package storage
import (
"context"
client "monitoring/app/storage/clickhouse"
"time"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
)
type EndpointMetric struct {
Timestamp time.Time `json:"timestamp"`
Service string `json:"service"`
Environment string `json:"environment"`
Endpoint string `json:"endpoint"`
StatusCode int `json:"status_code"`
ResponseTime int `json:"response_time"`
Method string `json:"method"`
}
func AddEndpointMetric(metric EndpointMetric) error {
batch, err := connection().PrepareBatch(context.Background(), "INSERT INTO endpoints")
if err != nil {
return err
}
err = batch.Append(
metric.Timestamp,
metric.Service,
metric.Environment,
metric.Endpoint,
metric.StatusCode,
metric.ResponseTime,
metric.Method,
)
if err != nil {
return err
}
return batch.Send()
}
func connection() driver.Conn {
return client.Connection
func AddEndpointMetric(metric client.EndpointMetric) {
client.EndpointsMutex.Lock()
defer client.EndpointsMutex.Unlock()
client.EndpointsCol = append(client.EndpointsCol, metric)
}

View File

@@ -1,34 +1,11 @@
package storage
import (
"context"
"time"
client "monitoring/app/storage/clickhouse"
)
type IncrementMetric struct {
Timestamp time.Time `json:"timestamp"`
Service string `json:"service"`
Environment string `json:"environment"`
Name string `json:"name"`
Count int `json:"count"`
}
func AddIncrementMetric(metric IncrementMetric) error {
batch, err := connection().PrepareBatch(context.Background(), "INSERT INTO increments")
if err != nil {
return err
}
err = batch.Append(
metric.Timestamp,
metric.Service,
metric.Environment,
metric.Name,
metric.Count,
)
if err != nil {
return err
}
return batch.Send()
func AddIncrementMetric(metric client.IncrementMetric) {
client.IncrementsMutex.Lock()
defer client.IncrementsMutex.Unlock()
client.IncrementsCol = append(client.IncrementsCol, metric)
}

View File

@@ -1,36 +1,11 @@
package storage
import (
"context"
"time"
client "monitoring/app/storage/clickhouse"
)
type TaskMetric struct {
Timestamp time.Time `json:"timestamp"`
Service string `json:"service"`
Environment string `json:"environment"`
Queue string `json:"queue"`
Success bool `json:"success"`
ExecutionTimeMs int `json:"execution_time_ms"`
}
func AddTaskMetric(metric TaskMetric) error {
batch, err := connection().PrepareBatch(context.Background(), "INSERT INTO tasks")
if err != nil {
return err
}
err = batch.Append(
metric.Timestamp,
metric.Service,
metric.Environment,
metric.Queue,
metric.Success,
metric.ExecutionTimeMs,
)
if err != nil {
return err
}
return batch.Send()
func AddTaskMetric(metric client.TaskMetric) {
client.TasksMutex.Lock()
defer client.TasksMutex.Unlock()
client.TasksCol = append(client.TasksCol, metric)
}