Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/storage/v2/clickhouse/sql/create_spans_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ CREATE TABLE
resource_str_attributes Nested (key String, value String),
resource_complex_attributes Nested (key String, value String),
scope_name String,
scope_version String
scope_version String,
scope_bool_attributes Nested (key String, value Bool),
scope_double_attributes Nested (key String, value Float64),
scope_int_attributes Nested (key String, value Int64),
scope_str_attributes Nested (key String, value String),
scope_complex_attributes Nested (key String, value String),
) ENGINE = MergeTree PRIMARY KEY (trace_id)
32 changes: 31 additions & 1 deletion internal/storage/v2/clickhouse/sql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ INSERT INTO
resource_complex_attributes.value,
scope_name,
scope_version,
scope_bool_attributes.key,
scope_bool_attributes.value,
scope_double_attributes.key,
scope_double_attributes.value,
scope_int_attributes.key,
scope_int_attributes.value,
scope_str_attributes.key,
scope_str_attributes.value,
scope_complex_attributes.key,
scope_complex_attributes.value
)
VALUES
(
Expand Down Expand Up @@ -106,6 +116,16 @@ VALUES
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
)
`
Expand Down Expand Up @@ -169,7 +189,17 @@ SELECT
resource_complex_attributes.key,
resource_complex_attributes.value,
scope_name,
scope_version
scope_version,
scope_bool_attributes.key,
scope_bool_attributes.value,
scope_double_attributes.key,
scope_double_attributes.value,
scope_int_attributes.key,
scope_int_attributes.value,
scope_str_attributes.key,
scope_str_attributes.value,
scope_complex_attributes.key,
scope_complex_attributes.value,
FROM
spans
WHERE
Expand Down
18 changes: 13 additions & 5 deletions internal/storage/v2/clickhouse/tracestore/dbmodel/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func FromRow(storedSpan *SpanRow) ptrace.Traces {
rs.CopyTo(resource)

scope := scopeSpans.Scope()
sc := convertScope(storedSpan)
sc := convertScope(storedSpan, span)
sc.CopyTo(scope)

return trace
Expand All @@ -56,11 +56,19 @@ func convertResource(sr *SpanRow, spanForWarnings ptrace.Span) pcommon.Resource
return resource
}

func convertScope(s *SpanRow) pcommon.InstrumentationScope {
func convertScope(sr *SpanRow, spanForWarnings ptrace.Span) pcommon.InstrumentationScope {
scope := ptrace.NewScopeSpans().Scope()
scope.SetName(s.ScopeName)
scope.SetVersion(s.ScopeVersion)
// TODO: populate attributes
scope.SetName(sr.ScopeName)
scope.SetVersion(sr.ScopeVersion)
putAttributes(
scope.Attributes(),
spanForWarnings,
sr.ScopeAttributes.BoolKeys, sr.ScopeAttributes.BoolValues,
sr.ScopeAttributes.DoubleKeys, sr.ScopeAttributes.DoubleValues,
sr.ScopeAttributes.IntKeys, sr.ScopeAttributes.IntValues,
sr.ScopeAttributes.StrKeys, sr.ScopeAttributes.StrValues,
sr.ScopeAttributes.ComplexKeys, sr.ScopeAttributes.ComplexValues,
)

return scope
}
Expand Down
15 changes: 13 additions & 2 deletions internal/storage/v2/clickhouse/tracestore/dbmodel/spanrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ type SpanRow struct {
ResourceAttributes Attributes

// --- Scope ---
ScopeName string
ScopeVersion string
ScopeName string
ScopeVersion string
ScopeAttributes Attributes
}

type Attributes struct {
Expand Down Expand Up @@ -136,6 +137,16 @@ func ScanRow(rows driver.Rows) (*SpanRow, error) {
&sr.ResourceAttributes.ComplexValues,
&sr.ScopeName,
&sr.ScopeVersion,
&sr.ScopeAttributes.BoolKeys,
&sr.ScopeAttributes.BoolValues,
&sr.ScopeAttributes.DoubleKeys,
&sr.ScopeAttributes.DoubleValues,
&sr.ScopeAttributes.IntKeys,
&sr.ScopeAttributes.IntValues,
&sr.ScopeAttributes.StrKeys,
&sr.ScopeAttributes.StrValues,
&sr.ScopeAttributes.ComplexKeys,
&sr.ScopeAttributes.ComplexValues,
)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@
"ComplexValues": [["eyJkYl9jb250ZXh0IjoidXNlcmRiIn0="]]
},
"ServiceName": "db-service",
"ResourceAttributes": {
"BoolKeys": ["resource.persistent", "resource.pooled"],
"BoolValues": [true, true],
"DoubleKeys": ["resource.cpu_limit", "resource.memory_limit"],
"DoubleValues": [1.5, 512.0],
"IntKeys": ["resource.instance_id", "resource.max_connections"],
"IntValues": [67890, 100],
"StrKeys": ["service.name", "resource.host", "resource.database_type"],
"StrValues": ["db-service", "db-host-1", "postgresql"],
"ComplexKeys": ["@[email protected]"],
"ComplexValues": ["eyJkYl90eXBlIjoicG9zdGdyZXNxbCJ9"]
},
"ScopeName": "db-scope",
"ScopeVersion": "v1.0.0"
"ScopeVersion": "v1.0.0",
"ScopeAttributes": {
"BoolKeys": ["scope.enabled", "scope.persistent"],
"BoolValues": [true, false],
"DoubleKeys": ["scope.version_number", "scope.priority"],
"DoubleValues": [1.0, 0.8],
"IntKeys": ["scope.instance_count", "scope.max_spans"],
"IntValues": [5, 1000],
"StrKeys": ["scope.environment", "scope.component"],
"StrValues": ["production", "database"],
"ComplexKeys": ["@[email protected]"],
"ComplexValues": ["eyJzY29wZV90eXBlIjoiZGF0YWJhc2UifQ=="]
}
}
1 change: 1 addition & 0 deletions internal/storage/v2/clickhouse/tracestore/dbmodel/to.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func ToRow(
sr.appendLink(link)
}
appendAttributes(&sr.ResourceAttributes, resource.Attributes())
appendAttributes(&sr.ScopeAttributes, scope.Attributes())

return sr
}
Expand Down
13 changes: 13 additions & 0 deletions internal/storage/v2/clickhouse/tracestore/dbmodel/to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func createTestScope() pcommon.InstrumentationScope {
sc := pcommon.NewInstrumentationScope()
sc.SetName("test-scope")
sc.SetVersion("v1.0.0")
addTestAttributes(sc.Attributes())
return sc
}

Expand Down Expand Up @@ -155,5 +156,17 @@ func createExpectedSpanRow(now time.Time, duration time.Duration) *SpanRow {
},
ScopeName: "test-scope",
ScopeVersion: "v1.0.0",
ScopeAttributes: Attributes{
BoolKeys: []string{"bool_attr"},
BoolValues: []bool{true},
DoubleKeys: []string{"double_attr"},
DoubleValues: []float64{3.14},
IntKeys: []string{"int_attr"},
IntValues: []int64{42},
StrKeys: []string{"string_attr"},
StrValues: []string{"string_value"},
ComplexKeys: []string{"@bytes@bytes_attr"},
ComplexValues: []string{encodedBytes},
},
}
}
14 changes: 12 additions & 2 deletions internal/storage/v2/clickhouse/tracestore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func scanSpanRowFn() func(dest any, src *dbmodel.SpanRow) error {
if !ok {
return fmt.Errorf("expected []any for dest, got %T", dest)
}
if len(ptrs) != 58 {
return fmt.Errorf("expected 58 destination arguments, got %d", len(ptrs))
if len(ptrs) != 68 {
return fmt.Errorf("expected 68 destination arguments, got %d", len(ptrs))
}

values := []any{
Expand Down Expand Up @@ -89,6 +89,16 @@ func scanSpanRowFn() func(dest any, src *dbmodel.SpanRow) error {
&src.ResourceAttributes.ComplexValues,
&src.ScopeName,
&src.ScopeVersion,
&src.ScopeAttributes.BoolKeys,
&src.ScopeAttributes.BoolValues,
&src.ScopeAttributes.DoubleKeys,
&src.ScopeAttributes.DoubleValues,
&src.ScopeAttributes.IntKeys,
&src.ScopeAttributes.IntValues,
&src.ScopeAttributes.StrKeys,
&src.ScopeAttributes.StrValues,
&src.ScopeAttributes.ComplexKeys,
&src.ScopeAttributes.ComplexValues,
}

for i := range ptrs {
Expand Down
36 changes: 36 additions & 0 deletions internal/storage/v2/clickhouse/tracestore/spans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ var singleSpan = []*dbmodel.SpanRow{
},
ScopeName: "auth-scope",
ScopeVersion: "v1.0.0",
ScopeAttributes: dbmodel.Attributes{
BoolKeys: []string{"scope.enabled", "scope.persistent"},
BoolValues: []bool{true, false},
DoubleKeys: []string{"scope.version_number", "scope.priority"},
DoubleValues: []float64{1.0, 0.8},
IntKeys: []string{"scope.instance_count", "scope.max_spans"},
IntValues: []int64{5, 1000},
StrKeys: []string{"scope.environment", "scope.component"},
StrValues: []string{"production", "auth"},
ComplexKeys: []string{"@[email protected]"},
ComplexValues: []string{"eyJzY29wZV90eXBlIjoiYXV0aGVudGljYXRpb24ifQ=="},
},
},
}

Expand Down Expand Up @@ -152,6 +164,18 @@ var multipleSpans = []*dbmodel.SpanRow{
},
ScopeName: "auth-scope",
ScopeVersion: "v1.0.0",
ScopeAttributes: dbmodel.Attributes{
BoolKeys: []string{"scope.enabled", "scope.persistent"},
BoolValues: []bool{true, false},
DoubleKeys: []string{"scope.version_number", "scope.priority"},
DoubleValues: []float64{1.0, 0.8},
IntKeys: []string{"scope.instance_count", "scope.max_spans"},
IntValues: []int64{5, 1000},
StrKeys: []string{"scope.environment", "scope.component"},
StrValues: []string{"production", "auth"},
ComplexKeys: []string{"@[email protected]"},
ComplexValues: []string{"eyJzY29wZV90eXBlIjoiYXV0aGVudGljYXRpb24ifQ=="},
},
},
{
ID: "0000000000000003",
Expand Down Expand Up @@ -220,5 +244,17 @@ var multipleSpans = []*dbmodel.SpanRow{
},
ScopeName: "db-scope",
ScopeVersion: "v1.0.0",
ScopeAttributes: dbmodel.Attributes{
BoolKeys: []string{"scope.enabled", "scope.persistent"},
BoolValues: []bool{true, false},
DoubleKeys: []string{"scope.version_number", "scope.priority"},
DoubleValues: []float64{1.0, 0.8},
IntKeys: []string{"scope.instance_count", "scope.max_spans"},
IntValues: []int64{5, 1000},
StrKeys: []string{"scope.environment", "scope.component"},
StrValues: []string{"production", "database"},
ComplexKeys: []string{"@[email protected]"},
ComplexValues: []string{"eyJzY29wZV90eXBlIjoiZGF0YWJhc2UifQ=="},
},
},
}
10 changes: 10 additions & 0 deletions internal/storage/v2/clickhouse/tracestore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ func (w *Writer) WriteTraces(ctx context.Context, td ptrace.Traces) error {
sr.ResourceAttributes.ComplexValues,
sr.ScopeName,
sr.ScopeVersion,
sr.ScopeAttributes.BoolKeys,
sr.ScopeAttributes.BoolValues,
sr.ScopeAttributes.DoubleKeys,
sr.ScopeAttributes.DoubleValues,
sr.ScopeAttributes.IntKeys,
sr.ScopeAttributes.IntValues,
sr.ScopeAttributes.StrKeys,
sr.ScopeAttributes.StrValues,
sr.ScopeAttributes.ComplexKeys,
sr.ScopeAttributes.ComplexValues,
)
if err != nil {
return fmt.Errorf("failed to append span to batch: %w", err)
Expand Down
10 changes: 10 additions & 0 deletions internal/storage/v2/clickhouse/tracestore/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ func TestWriter_Success(t *testing.T) {
require.Equal(t, expected.ResourceAttributes.ComplexValues, row[45]) // Resource complex attribute values
require.Equal(t, expected.ScopeName, row[46]) // Scope name
require.Equal(t, expected.ScopeVersion, row[47]) // Scope version
require.Equal(t, expected.ScopeAttributes.BoolKeys, row[48]) // Scope bool attribute keys
require.Equal(t, expected.ScopeAttributes.BoolValues, row[49]) // Scope bool attribute values
require.Equal(t, expected.ScopeAttributes.DoubleKeys, row[50]) // Scope double attribute keys
require.Equal(t, expected.ScopeAttributes.DoubleValues, row[51]) // Scope double attribute values
require.Equal(t, expected.ScopeAttributes.IntKeys, row[52]) // Scope int attribute keys
require.Equal(t, expected.ScopeAttributes.IntValues, row[53]) // Scope int attribute values
require.Equal(t, expected.ScopeAttributes.StrKeys, row[54]) // Scope str attribute keys
require.Equal(t, expected.ScopeAttributes.StrValues, row[55]) // Scope str attribute values
require.Equal(t, expected.ScopeAttributes.ComplexKeys, row[56]) // Scope complex attribute keys
require.Equal(t, expected.ScopeAttributes.ComplexValues, row[57]) // Scope complex attribute values
}
}

Expand Down
Loading