diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml index af1f512..f007e97 100644 --- a/.deploy/deploy-prod.yaml +++ b/.deploy/deploy-prod.yaml @@ -1,23 +1,20 @@ version: "3.4" services: - queues: + monitoring: image: mathwave/sprint-repo:monitoring networks: - - monitoring + - clickhouse environment: - MONGO_HOST: "mongo.sprinthub.ru" - MONGO_PASSWORD: $MONGO_PASSWORD_PROD + CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD deploy: mode: replicated restart_policy: condition: any - placement: - constraints: [node.labels.stage == production] update_config: parallelism: 1 order: start-first networks: - queues: - external: true \ No newline at end of file + clickhouse: + external: true diff --git a/app/storage/clickhouse/client.go b/app/storage/clickhouse/client.go index e641b23..3195d1a 100644 --- a/app/storage/clickhouse/client.go +++ b/app/storage/clickhouse/client.go @@ -57,15 +57,16 @@ func Migrate() error { context.TODO(), `CREATE TABLE IF NOT EXISTS endpoints ( timestamp DateTime, - service_name LowCardinality(String), + service LowCardinality(String), + environment LowCardinality(String), endpoint LowCardinality(String), status_code UInt16, response_time_ms UInt32, - request_method LowCardinality(String) + method LowCardinality(String) ) ENGINE = MergeTree PARTITION BY toYYYYMM(timestamp) - ORDER BY (service_name, endpoint, request_method, timestamp);`, + ORDER BY (service, environment, endpoint, request_method, timestamp);`, ) if err != nil { log.Fatal(err) @@ -76,14 +77,15 @@ func Migrate() error { context.TODO(), `CREATE TABLE IF NOT EXISTS tasks ( timestamp DateTime, - service_name LowCardinality(String), - queue_name LowCardinality(String), + service LowCardinality(String), + environment LowCardinality(String), + queue LowCardinality(String), success Bool, execution_time_ms UInt32 ) ENGINE = MergeTree PARTITION BY toYYYYMM(timestamp) - ORDER BY (service_name, queue_name, timestamp);`, + ORDER BY (service, environment, queue, timestamp);`, ) if err != nil { log.Fatal(err) diff --git a/app/storage/clickhouse/tables/endpoints.go b/app/storage/clickhouse/tables/endpoints.go index 13636e1..530b11e 100644 --- a/app/storage/clickhouse/tables/endpoints.go +++ b/app/storage/clickhouse/tables/endpoints.go @@ -11,6 +11,7 @@ import ( 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"` @@ -26,6 +27,7 @@ func AddEndpointMetric(metric EndpointMetric) error { err = batch.Append( metric.Timestamp, metric.Service, + metric.Environment, metric.Endpoint, metric.StatusCode, metric.ResponseTime, diff --git a/app/storage/clickhouse/tables/tasks.go b/app/storage/clickhouse/tables/tasks.go index 3b03485..8da7ada 100644 --- a/app/storage/clickhouse/tables/tasks.go +++ b/app/storage/clickhouse/tables/tasks.go @@ -8,6 +8,7 @@ import ( 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"` @@ -22,6 +23,7 @@ func AddTaskMetric(metric TaskMetric) error { err = batch.Append( metric.Timestamp, metric.Service, + metric.Environment, metric.Queue, metric.Success, metric.ExecutionTimeMs,