Skip to content

Commit

Permalink
Improving test
Browse files Browse the repository at this point in the history
Signed-off-by: Alok Kumar Singh <dev.alok.singh123@gmail.com>
  • Loading branch information
akstron committed Oct 29, 2024
1 parent 18dcf1e commit b230412
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
52 changes: 50 additions & 2 deletions plugin/storage/cassandra/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,61 @@ import (
"github.com/stretchr/testify/require"
)

func TestTemplateRendering(t *testing.T) {
func TestQueryCreationFromTemplate(t *testing.T) {
cfg := DefaultSchema()
res, err := getQueryFileAsBytes(`v004-go-tmpl-test.cql.tmpl`, &cfg)
require.NoError(t, err)

queryStrings, err := getQueriesFromBytes(res)
require.NoError(t, err)

assert.Equal(t, 9, len(queryStrings))
expOutputQueries := []string{
`CREATE TYPE IF NOT EXISTS jaeger_v2_test.keyvalue (
key text,
value_type text,
value_string text,
value_bool boolean,
value_long bigint,
value_double double,
value_binary blob
);
`,
`CREATE TYPE IF NOT EXISTS jaeger_v2_test.log (
ts bigint,
fields frozen<list<frozen<jaeger_v2_test.keyvalue>>>
);
`,
`CREATE TABLE IF NOT EXISTS jaeger_v2_test.service_names (
service_name text,
PRIMARY KEY (service_name)
)
WITH compaction = {
'min_threshold': '4',
'max_threshold': '32',
'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'
}
AND default_time_to_live = 172800
AND speculative_retry = 'NONE'
AND gc_grace_seconds = 10800;
`,
`CREATE TABLE IF NOT EXISTS jaeger_v2_test.dependencies_v2 (
ts_bucket timestamp,
ts timestamp,
dependencies list<frozen<dependency>>,
PRIMARY KEY (ts_bucket, ts)
) WITH CLUSTERING ORDER BY (ts DESC)
AND compaction = {
'min_threshold': '4',
'max_threshold': '32',
'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'
}
AND default_time_to_live = 0;
`,
}

assert.Equal(t, len(expOutputQueries), len(queryStrings))

for i := range expOutputQueries {
assert.Equal(t, expOutputQueries[i], queryStrings[i])
}
}
43 changes: 1 addition & 42 deletions plugin/storage/cassandra/schema/v004-go-tmpl-test.cql.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
-- There are total 9 queries here

CREATE KEYSPACE IF NOT EXISTS {{.Keyspace}} WITH replication = {{.Replication}};
-- There are total 4 queries here

CREATE TYPE IF NOT EXISTS {{.Keyspace}}.keyvalue (
key text,
Expand All @@ -17,17 +15,6 @@ CREATE TYPE IF NOT EXISTS {{.Keyspace}}.log (
fields frozen<list<frozen<{{.Keyspace}}.keyvalue>>>
);

CREATE TYPE IF NOT EXISTS {{.Keyspace}}.span_ref (
ref_type text,
trace_id blob,
span_id bigint
);

CREATE TYPE IF NOT EXISTS {{.Keyspace}}.process (
service_name text,
tags frozen<list<frozen<{{.Keyspace}}.keyvalue>>>
);

CREATE TABLE IF NOT EXISTS {{.Keyspace}}.service_names (
service_name text,
PRIMARY KEY (service_name)
Expand All @@ -41,34 +28,6 @@ CREATE TABLE IF NOT EXISTS {{.Keyspace}}.service_names (
AND speculative_retry = 'NONE'
AND gc_grace_seconds = 10800; -- 3 hours of downtime acceptable on nodes

-- a bucketing strategy may have to be added for tag queries
-- we can make this table even better by adding a timestamp to it
CREATE TABLE IF NOT EXISTS {{.Keyspace}}.tag_index (
service_name text,
tag_key text,
tag_value text,
start_time bigint, -- microseconds since epoch
trace_id blob,
span_id bigint,
PRIMARY KEY ((service_name, tag_key, tag_value), start_time, trace_id, span_id)
)
WITH CLUSTERING ORDER BY (start_time DESC)
AND compaction = {
'compaction_window_size': '1',
'compaction_window_unit': 'HOURS',
'class': 'org.apache.cassandra.db.compaction.TimeWindowCompactionStrategy'
}
AND default_time_to_live = {{.TraceTTL}}
AND speculative_retry = 'NONE'
AND gc_grace_seconds = 10800; -- 3 hours of downtime acceptable on nodes

CREATE TYPE IF NOT EXISTS {{.Keyspace}}.dependency (
parent text,
child text,
call_count bigint,
source text
);

-- compaction strategy is intentionally different as compared to other tables due to the size of dependencies data
CREATE TABLE IF NOT EXISTS {{.Keyspace}}.dependencies_v2 (
ts_bucket timestamp,
Expand Down

0 comments on commit b230412

Please sign in to comment.