Compare commits

..

No commits in common. "828eca445a6c7fe5b9d2340da89db749f08a8018" and "2afbdc7a940be8de6efafdbd3cf9423ff4883500" have entirely different histories.

4 changed files with 8 additions and 69 deletions

View File

@ -1,25 +0,0 @@
package routers
import (
"encoding/json"
"log"
tasks "monitoring/app/storage/clickhouse/tables"
"net/http"
)
func AddTaskMetric(r *http.Request) (interface{}, int) {
d := json.NewDecoder(r.Body)
body := tasks.TaskMetric{}
err := d.Decode(&body)
if err != nil {
return nil, http.StatusBadRequest
}
err = tasks.AddTaskMetric(body)
if err != nil {
log.Print(err.Error())
return nil, http.StatusInternalServerError
}
return nil, http.StatusAccepted
}

View File

@ -1,34 +0,0 @@
package storage
import (
"context"
"time"
)
type TaskMetric struct {
Timestamp time.Time `json:"timestamp"`
Service string `json:"service"`
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.Queue,
metric.Success,
metric.ExecutionTimeMs,
)
if err != nil {
return err
}
return batch.Send()
}

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"log"
endpoint "monitoring/app/routers/metrics"
task "monitoring/app/routers/metrics"
client "monitoring/app/storage/clickhouse"
"net/http"
"time"
@ -42,7 +41,6 @@ func main() {
}
http.HandleFunc("/api/v1/metrics/endpoint", handlerWrapper(endpoint.AddEndpointMetric))
http.HandleFunc("/api/v1/metrics/task", handlerWrapper(task.AddTaskMetric))
log.Printf("Server started")
http.ListenAndServe(":1237", nil)
}