Skip to content

Commit

Permalink
chore(backend): add span limits
Browse files Browse the repository at this point in the history
closes #1607
  • Loading branch information
anupcowkur committed Dec 13, 2024
1 parent ca19104 commit 872bd3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 23 additions & 2 deletions backend/api/span/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"slices"
"strings"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -46,6 +47,9 @@ var ValidNetworkGenerations = []string{
}

const (
maxSpanNameChars = 64
maxCheckpointNameChars = 64
maxNumberOfCheckpoints = 100
maxThreadNameChars = 128
maxUserIDChars = 128
maxDeviceNameChars = 32
Expand Down Expand Up @@ -171,7 +175,11 @@ func (s *SpanField) Validate() error {
}

if s.SpanName == "" {
return fmt.Errorf(`%q must be empty`, `span_name`)
return fmt.Errorf(`%q must not be empty`, `span_name`)
}

if len(s.SpanName) > maxSpanNameChars {
return fmt.Errorf(`%q exceeds maximum allowed characters of %d`, `span_name`, maxSpanNameChars)
}

if s.SpanID == "" {
Expand All @@ -198,6 +206,18 @@ func (s *SpanField) Validate() error {
return fmt.Errorf(`%q must be a valid ISO 8601 timestamp`, `end_time`)
}

if len(s.CheckPoints) > maxNumberOfCheckpoints {
return fmt.Errorf(`%q exceeds maximum allowed length of %d`, `checkpoints`, maxNumberOfCheckpoints)
}

if len(s.CheckPoints) > 0 {
for _, cp := range s.CheckPoints {
if len(cp.Name) > maxCheckpointNameChars {
return fmt.Errorf(`checkpoint name %v exceeds maximum allowed characters of %d`, cp.Name, maxNumberOfCheckpoints)
}
}
}

if s.Attributes.InstallationID == uuid.Nil {
return fmt.Errorf(`%q must be a valid UUID`, `attribute.installation_id`)
}
Expand Down Expand Up @@ -591,7 +611,8 @@ func GetTrace(ctx context.Context, traceId string) (trace TraceDisplay, err erro

// Map rawCheckpoints into CheckPointField
for _, cp := range rawCheckpoints {
name, _ := cp[0].(string)
rawName, _ := cp[0].(string)
name := strings.ReplaceAll(rawName, "\u0000", "")
timestamp, _ := cp[1].(time.Time)
span.CheckPoints = append(span.CheckPoints, CheckPointField{
Name: name,
Expand Down
4 changes: 2 additions & 2 deletions self-host/clickhouse/20241112084744_create_spans_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
create table if not exists spans
(
`app_id` UUID not null comment 'unique id of the app' codec(ZSTD(3)),
`span_name` LowCardinality(FixedString(128)) not null comment 'name of the span' codec(ZSTD(3)),
`span_name` LowCardinality(FixedString(64)) not null comment 'name of the span' codec(ZSTD(3)),
`span_id` FixedString(16) not null comment 'id of the span' codec(ZSTD(3)),
`parent_id` FixedString(16) comment 'id of the parent span' codec(ZSTD(3)),
`trace_id` FixedString(32) not null comment 'id of the trace' codec(ZSTD(3)),
`session_id` UUID not null comment 'session id' codec(ZSTD(3)),
`status` UInt8 not null comment 'status of the span 0 (Unset), 1 (Ok) or 2 (Error)' codec(ZSTD(3)),
`start_time` DateTime64(9, 'UTC') not null comment 'start time' codec(DoubleDelta, ZSTD(3)),
`end_time` DateTime64(9, 'UTC') not null comment 'end time' codec(DoubleDelta, ZSTD(3)),
`checkpoints` Array(Tuple(String, DateTime64(9, 'UTC'))) comment 'array of checkpoints - {name, timestamp}' codec(ZSTD(3)),
`checkpoints` Array(Tuple(FixedString(64), DateTime64(9, 'UTC'))) comment 'array of checkpoints - {name, timestamp}' codec(ZSTD(3)),
`attribute.app_unique_id` LowCardinality(FixedString(128)) not null comment 'app bundle identifier' codec(ZSTD(3)),
`attribute.installation_id` UUID not null comment 'unique id for an installation of an app, generated by sdk' codec(ZSTD(3)),
`attribute.user_id` LowCardinality(String) comment 'attributed user id' codec(ZSTD(3)),
Expand Down

0 comments on commit 872bd3f

Please sign in to comment.