-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[clickhouse] Implement GetTraces for ClickHouse Storage #7207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clickhouse] Implement GetTraces for ClickHouse Storage #7207
Conversation
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
0f22460
to
5f00851
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7207 +/- ##
==========================================
+ Coverage 96.17% 96.18% +0.01%
==========================================
Files 366 369 +3
Lines 21947 22184 +237
==========================================
+ Hits 21107 21338 +231
- Misses 627 632 +5
- Partials 213 214 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
7b78c99
to
32017da
Compare
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
scope_version String | ||
) | ||
ENGINE = MergeTree | ||
PRIMARY KEY(trace_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add any other primary keys here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trace_id cannot be primary key, since we have many spans with the same ID.
In Cassandra we used (trace_id, span_id, span_hash)
as PK, since we never actually retrieve by PK, only by partial PK scan like (trace_id, *)
. Adding a hash allows storing partial spans (even though we don't fully support that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurishkuro Primary keys in ClickHouse work differently and are not required to be unique per row. The primary key instead acts like an index to reduce the amount of data that is scanned (more info at https://clickhouse.com/docs/migrations/postgresql/data-modeling-techniques#how-are-clickhouse-primary-keys-different).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the guidance that ClickHouse gives on choosing an effective primary key (ref: https://clickhouse.com/docs/best-practices/choosing-a-primary-key)
When selecting an ordering key, prioritize columns frequently used in query filters (i.e. the WHERE clause), especially those that exclude large numbers of rows.
Columns highly correlated with other data in the table are also beneficial, as contiguous storage improves compression ratios and memory efficiency during GROUP BY and ORDER BY operations.
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
PRIMARY KEY(name); | ||
|
||
CREATE MATERIALIZED VIEW IF NOT EXISTS services_mv | ||
TO services |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not following, what does TO services
mean? Can't materializes view exist by itself, derived from spans table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurishkuro Materialized views require a target table, which in this case is services
. It is derived from the spans
table and stored in the services
table. See the following from ClickHouse documentation (ref: https://clickhouse.com/docs/best-practices/use-materialized-views)
Incremental materialized views are updated in real-time. As new data is inserted into the source table, ClickHouse automatically applies the materialized view's query to the new data block and writes the results to a separate target table. Over time, ClickHouse merges these partial results to produce a complete, up-to-date view.
) ENGINE = AggregatingMergeTree | ||
PRIMARY KEY(name, span_kind); | ||
|
||
CREATE MATERIALIZED VIEW IF NOT EXISTS operations_mv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say anything about this approach without us doing stress testing, to see how it performs under heavy insert load. We can use OCI hardware for testing.
status_message String, | ||
duration Int64, | ||
|
||
events Nested ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without attributes, which are the core data element, it's hard to evaluate how good this schema is.
CREATE TABLE IF NOT EXISTS spans ( | ||
id String, | ||
trace_id String, | ||
trace_state String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the tracestate
header? can we add comments? why is it so high at the top?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to keep the ordering consistent with https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/internal/data/protogen/trace/v1/trace.pb.go#L398
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add the link as comment
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
if len(parentSpanId) != 0 { | ||
span.SetParentSpanID(pcommon.SpanID(parentSpanId)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for empty parent span ID currently only verifies string length. Consider also checking if it's a zero span ID (all zeros), as a span with a zero parent ID should be treated as having no parent. This would make the validation more robust against different representations of "no parent".
if len(parentSpanId) != 0 { | |
span.SetParentSpanID(pcommon.SpanID(parentSpanId)) | |
} | |
if len(parentSpanId) != 0 && !isZeroSpanID(parentSpanId) { | |
span.SetParentSpanID(pcommon.SpanID(parentSpanId)) | |
} | |
// isZeroSpanID checks if a span ID consists of all zeros | |
func isZeroSpanID(id []byte) bool { | |
for _, b := range id { | |
if b != 0 { | |
return false | |
} | |
} | |
return true | |
} |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Which problem is this PR solving?
Description of the changes
GetTraces
function for ClickHouse storage.How was this change tested?
Started the ClickHouse server on my local machine using
Initialized the tables using
Seeded the database using test.sql
Wrote a Go unit test to run
GetTraces
and got the following outputChecklist
jaeger
:make lint test
jaeger-ui
:npm run lint
andnpm run test