Compare commits

..

No commits in common. "22e5c275a91ba105b87420d7a2b28612a9bae404" and "56028ac4792d4a9c2ef4a70bc812bc49867c69e2" have entirely different histories.

4 changed files with 3 additions and 33 deletions

View File

@ -17,7 +17,7 @@ func AddEndpointMetric (r *http.Request) (interface{}, int) {
err = endpoints.AddEndpointMetric(body)
if err != nil {
log.Print(err.Error())
log.Printf(err.Error())
return nil, http.StatusInternalServerError
}

View File

@ -3,7 +3,6 @@ package storage
import (
"context"
"fmt"
"log"
"os"
"github.com/ClickHouse/clickhouse-go/v2"
@ -21,10 +20,6 @@ func Connect() error {
return nil
}
func Close() {
Connection.Close()
}
func connect() (*driver.Conn, error) {
var (
ctx = context.Background()
@ -50,27 +45,4 @@ func connect() (*driver.Conn, error) {
return nil, err
}
return &conn, nil
}
func Migrate() error {
rows, err := Connection.Query(
context.TODO(),
`CREATE TABLE IF NOT EXISTS endpoints (
timestamp DateTime,
service_name LowCardinality(String),
endpoint LowCardinality(String),
status_code UInt16,
response_time_ms UInt32,
request_method LowCardinality(String),
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(timestamp)
ORDER BY (service_name, endpoint, request_method, timestamp)`,
)
if err != nil {
log.Fatal(err)
return err
}
defer rows.Close()
return nil
}

View File

@ -3,13 +3,12 @@ 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"`
Timestamp int `json:"timestamp"`
Service string `json:"service"`
Endpoint string `json:"endpoint"`
StatusCode int `json:"status_code"`

View File

@ -33,8 +33,7 @@ func main() {
if err != nil {
panic(err)
}
defer client.Close()
http.HandleFunc("/api/v1/metrics/endpoint", handlerWrapper(endpoint.AddEndpointMetric))
log.Printf("Server started")
http.ListenAndServe(":1237", nil)