Skip to content

Commit

Permalink
profiles: add ttl to clickhouse tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershafir committed Feb 5, 2024
1 parent 7475601 commit b75a3f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/db/maintain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion test/e2e
Submodule e2e updated from 81b163 to fc6ab1

0 comments on commit b75a3f7

Please sign in to comment.