Skip to content

Commit

Permalink
🔥 tcp timestamp (#1043)
Browse files Browse the repository at this point in the history
* 🔥 tcp timestamp

* 🔥 tcp timestamp
  • Loading branch information
thibaultleouay authored Oct 9, 2024
1 parent 4ca5896 commit 4452dbc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
78 changes: 43 additions & 35 deletions apps/checker/handlers/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ type TCPData struct {
Timing string `json:"timing"`
ErrorMessage string `json:"errorMessage"`
Region string `json:"region"`
Trigger string `json:"trigger"`

RequestId int64 `json:"requestId,omitempty"`
WorkspaceID int64 `json:"workspaceId"`
MonitorID int64 `json:"monitorId"`
Timestamp int64 `json:"timestamp"`
Latency int64 `json:"latency"`
RequestId int64 `json:"requestId,omitempty"`
WorkspaceID int64 `json:"workspaceId"`
MonitorID int64 `json:"monitorId"`
Timestamp int64 `json:"timestamp"`
Latency int64 `json:"latency"`
CronTimestamp int64 `json:"cronTimestamp"`

Error uint8 `json:"error"`
}
Expand Down Expand Up @@ -101,14 +103,16 @@ func (h Handler) TCPHandler(c *gin.Context) {
latency := res.TCPDone - res.TCPStart

data := TCPData{
WorkspaceID: workspaceId,
Timestamp: req.CronTimestamp,
Error: 0,
ErrorMessage: "",
Region: h.Region,
MonitorID: monitorId,
Timing: string(timingAsString),
Latency: latency,
WorkspaceID: workspaceId,
Timestamp: res.TCPStart,
Error: 0,
ErrorMessage: "",
Region: h.Region,
MonitorID: monitorId,
Timing: string(timingAsString),
Latency: latency,
CronTimestamp: req.CronTimestamp,
Trigger: "cron",
}

if req.Status == "active" && req.DegradedAfter > 0 && latency > req.DegradedAfter {
Expand Down Expand Up @@ -159,12 +163,13 @@ func (h Handler) TCPHandler(c *gin.Context) {

if err := backoff.Retry(op, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 3)); err != nil {
if err := h.TbClient.SendEvent(ctx, TCPData{
WorkspaceID: workspaceId,
Timestamp: req.CronTimestamp,
ErrorMessage: err.Error(),
Region: h.Region,
MonitorID: monitorId,
Error: 1,
WorkspaceID: workspaceId,
CronTimestamp: req.CronTimestamp,
ErrorMessage: err.Error(),
Region: h.Region,
MonitorID: monitorId,
Error: 1,
Trigger: "cron",
}, dataSourceName); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird")
}
Expand Down Expand Up @@ -265,15 +270,17 @@ func (h Handler) TCPHandlerRegion(c *gin.Context) {
latency := res.TCPDone - res.TCPStart

data := TCPData{
WorkspaceID: workspaceId,
Timestamp: req.CronTimestamp,
Error: 0,
ErrorMessage: "",
Region: h.Region,
MonitorID: monitorId,
Timing: string(timingAsString),
Latency: latency,
RequestId: req.RequestId,
WorkspaceID: workspaceId,
CronTimestamp: req.CronTimestamp,
Timestamp: res.TCPStart,
Error: 0,
ErrorMessage: "",
Region: h.Region,
MonitorID: monitorId,
Timing: string(timingAsString),
Latency: latency,
RequestId: req.RequestId,
Trigger: "API",
}

if req.RequestId != 0 {
Expand All @@ -287,13 +294,14 @@ func (h Handler) TCPHandlerRegion(c *gin.Context) {

if err := backoff.Retry(op, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 3)); err != nil && req.RequestId != 0 {
if err := h.TbClient.SendEvent(ctx, TCPData{
WorkspaceID: workspaceId,
Timestamp: req.CronTimestamp,
ErrorMessage: err.Error(),
Region: h.Region,
MonitorID: monitorId,
Error: 1,
RequestId: req.RequestId,
WorkspaceID: workspaceId,
CronTimestamp: req.CronTimestamp,
ErrorMessage: err.Error(),
Region: h.Region,
MonitorID: monitorId,
Error: 1,
RequestId: req.RequestId,
Trigger: "api",
}, dataSourceName); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird")
}
Expand Down
3 changes: 3 additions & 0 deletions packages/tinybird/datasources/tcp_response.datasource
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ SCHEMA >
`monitorId` Int32 `json:$.monitorId`,
`region` String `json:$.region`,
`timestamp` Int64 `json:$.timestamp`,
`cronTimestamp` Int64 `json:$.timestamp`,
`timing` String `json:$.timing`,
`workspaceId` Int32 `json:$.workspaceId`,
`latency` Int64 `json:$.latency`,
`errorMessage` Nullable(String) `json:$.errorMessage`,
`error` Int16 `json:$.error`
`trigger` Nullable(String) `json:$.trigger`,


ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(fromUnixTimestamp64Milli(timestamp))"
Expand Down

0 comments on commit 4452dbc

Please sign in to comment.