From b75a3f77139bcb278a84a2d37e62687eb56e0962 Mon Sep 17 00:00:00 2001 From: tomershafir Date: Mon, 5 Feb 2024 16:19:12 +0200 Subject: [PATCH] profiles: add ttl to clickhouse tables --- lib/db/maintain/index.js | 22 +++++++++++++++++++++- test/e2e | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/db/maintain/index.js b/lib/db/maintain/index.js index c2076e79..c1c88faa 100644 --- a/lib/db/maintain/index.js +++ b/lib/db/maintain/index.js @@ -103,7 +103,8 @@ module.exports.rotate = async (opts) => { { type: 'rotate', name: 'v3_time_series_days' }, { type: 'rotate', name: 'v3_storage_policy' }, { type: 'rotate', name: 'v1_traces_days' }, - { type: 'rotate', name: 'v1_traces_storage_policy' } + { type: 'rotate', name: 'v1_traces_storage_policy' }, + { type: 'rotate', name: 'v1_profiles_days' } ], db.db) const _update = (req) => { return upgradeRequest({ db: db.db, useDefaultDB: true }, req) @@ -161,5 +162,24 @@ module.exports.rotate = async (opts) => { await _update(alterSm, null, db.db) await client.addSetting('rotate', 'v1_traces_storage_policy', db.storage_policy, db.db) } + if (db.samples_days + '' !== settings.v1_profiles_days) { + let alterTable = 'ALTER TABLE profiles {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + let rotateTable = `ALTER TABLE profiles {{{OnCluster}}} MODIFY TTL toDateTime(timestamp_ns / 1000000000) + INTERVAL ${db.samples_days} DAY` + await _update(alterTable, null, db.db) + await _update(rotateTable, null, db.db) + alterTable = 'ALTER TABLE profiles_series {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + rotateTable = `ALTER TABLE profiles_series {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` + await _update(alterTable, null, db.db) + await _update(rotateTable, null, db.db) + alterTable = 'ALTER TABLE profiles_series_gin {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + rotateTable = `ALTER TABLE profiles_series_gin {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` + await _update(alterTable, null, db.db) + await _update(rotateTable, null, db.db) + alterTable = 'ALTER TABLE profiles_series_keys {{{OnCluster}}} MODIFY SETTING ttl_only_drop_parts = 1, merge_with_ttl_timeout = 3600, index_granularity = 8192' + rotateTable = `ALTER TABLE profiles_series_keys {{{OnCluster}}} MODIFY TTL date + INTERVAL ${db.samples_days} DAY` + await _update(alterTable, null, db.db) + await _update(rotateTable, null, db.db) + await client.addSetting('rotate', 'v1_profiles_days', db.samples_days + '', db.db) + } } } diff --git a/test/e2e b/test/e2e index 81b163a5..fc6ab17e 160000 --- a/test/e2e +++ b/test/e2e @@ -1 +1 @@ -Subproject commit 81b163a554f8e92b7312845211eec9fba8931f0a +Subproject commit fc6ab17eb3946cb84c7a5d2114c51c67e272e6be