-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(graphqlmetrics): dont store raw data for intermediate table,…
… use NULL engine (#1376)
- Loading branch information
Showing
3 changed files
with
146 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
graphqlmetrics/migrations/20241115112140_drop_gql_metrics_schema_usage_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- migrate:up | ||
|
||
DROP TABLE IF EXISTS gql_metrics_schema_usage; | ||
|
||
-- migrate:down | ||
|
||
CREATE TABLE IF NOT EXISTS gql_metrics_schema_usage | ||
( | ||
`Timestamp` DateTime('UTC') CODEC(Delta(4), ZSTD(3)), | ||
`OrganizationID` LowCardinality(String) CODEC(ZSTD(3)), | ||
`FederatedGraphID` LowCardinality(String) CODEC(ZSTD(3)), | ||
`RouterConfigVersion` LowCardinality(String) CODEC(ZSTD(3)), | ||
`OperationHash` LowCardinality(String) CODEC(ZSTD(3)), | ||
`OperationName` LowCardinality(String) CODEC(ZSTD(3)), | ||
`OperationType` LowCardinality(String) CODEC(ZSTD(3)), | ||
`Count` UInt64 CODEC(Delta(8), ZSTD(3)), | ||
`Path` Array(String) CODEC(ZSTD(3)), | ||
`TypeNames` Array(String) CODEC(ZSTD(3)), | ||
`NamedType` String CODEC(ZSTD(3)), | ||
`ClientName` LowCardinality(String) CODEC(ZSTD(3)), | ||
`ClientVersion` LowCardinality(String) CODEC(ZSTD(3)), | ||
`HttpStatusCode` String CODEC(ZSTD(3)), | ||
`HasError` Bool CODEC(ZSTD(3)), | ||
`SubgraphIDs` Array(LowCardinality(String)) CODEC(ZSTD(3)), | ||
`IsArgument` Bool CODEC(ZSTD(3)), | ||
`IsInput` Bool CODEC(ZSTD(3)), | ||
`Attributes` Map(LowCardinality(String), String) CODEC(ZSTD(3)), | ||
`IsIndirectFieldUsage` Bool DEFAULT false CODEC(ZSTD(3)), | ||
INDEX idx_operation_hash OperationHash TYPE bloom_filter(0.001) GRANULARITY 1, | ||
INDEX idx_path Path TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_source_ids SubgraphIDs TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_type_names TypeNames TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1, | ||
INDEX idx_count Count TYPE minmax GRANULARITY 1 | ||
) | ||
ENGINE = MergeTree | ||
PARTITION BY toDate(Timestamp) | ||
ORDER BY (OrganizationID, FederatedGraphID, ClientName, ClientVersion, RouterConfigVersion, OperationHash, HttpStatusCode, HasError, toUnixTimestamp(Timestamp)) | ||
TTL toDateTime(Timestamp) + toIntervalDay(7) | ||
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1 | ||
|
58 changes: 58 additions & 0 deletions
58
graphqlmetrics/migrations/20241115112150_use_null_table_for_raw_schema_usage_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- migrate:up | ||
|
||
CREATE TABLE IF NOT EXISTS gql_metrics_schema_usage | ||
( | ||
-- See https://github.com/PostHog/posthog/issues/10616 why ZSTD(3) is used | ||
Timestamp DateTime('UTC') CODEC(Delta, ZSTD(3)), | ||
|
||
-- Organization | ||
OrganizationID LowCardinality(String) CODEC(ZSTD(3)), | ||
|
||
-- Router configuration | ||
FederatedGraphID LowCardinality(String) CODEC(ZSTD(3)), | ||
RouterConfigVersion LowCardinality(String) CODEC(ZSTD(3)), -- running schema version | ||
|
||
-- Operation | ||
OperationHash LowCardinality(String) CODEC(ZSTD(3)), | ||
OperationName LowCardinality(String) CODEC(ZSTD(3)), | ||
OperationType LowCardinality(String) CODEC(ZSTD(3)), -- query, mutation, subscription | ||
|
||
-- Define how often a field is used. Useful for batching at the collection layer. | ||
Count UInt64 CODEC(Delta, ZSTD(3)), | ||
|
||
-- Schema usage | ||
Path Array(String) CODEC(ZSTD(3)), | ||
TypeNames Array(String) CODEC(ZSTD(3)), -- Sorted before insertion | ||
NamedType String CODEC(ZSTD(3)), | ||
|
||
-- Client information | ||
ClientName LowCardinality(String) CODEC(ZSTD(3)), | ||
ClientVersion LowCardinality(String) CODEC(ZSTD(3)), | ||
|
||
--- Request information | ||
HttpStatusCode String CODEC (ZSTD(3)), | ||
HasError bool CODEC(ZSTD(3)), -- Whether the operation has an error of any kind | ||
|
||
-- SubgraphIDs identify the subgraphs that were used to resolve the field | ||
SubgraphIDs Array(LowCardinality(String)) CODEC(ZSTD(3)), -- Sorted before insertion | ||
|
||
-- Indicates if the usage was from an argument or a field | ||
IsArgument bool CODEC(ZSTD(3)), | ||
|
||
-- Indicates if the usage was from an input field | ||
IsInput bool CODEC(ZSTD(3)), | ||
|
||
-- Additional information | ||
Attributes Map(LowCardinality(String), String) CODEC(ZSTD(3)), | ||
|
||
IsIndirectFieldUsage bool DEFAULT false | ||
) | ||
-- The Null table engine is a powerful optimization - think of it as /dev/null. | ||
-- When data is inserted into the Null table, it is immediately discarded but materialized views are still updated. | ||
-- This is useful for cases where you want to track metrics but don't need to store the raw data. | ||
engine = Null; | ||
|
||
-- migrate:down | ||
|
||
DROP TABLE IF EXISTS gql_metrics_schema_usage; | ||
|