Skip to content
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

feat(Gong) - add an optional retention policy #11264

Merged
merged 36 commits into from
Mar 17, 2025
Merged

Conversation

aubin-tchoi
Copy link
Contributor

@aubin-tchoi aubin-tchoi commented Mar 6, 2025

Description

This PR implements an optional retention policy.

  • When disabled, all transcripts are synced (no change here).
  • When enabled, only the transcripts that are no older than the retention period are synced.

This behavior is implemented using two things:

  • We fetch transcripts starting from the retention period at minimum.
  • We garbage collect outdated transcripts.

There is currently no UI for configuring it, it will be added to the GongOptionComponent in a follow up PR (get/set already there on the connector manager).

The main workflow is updated to add an optional step of garbage collection:

  • We store the lastGarbageCollectionTimestamp in the gong_configuration alongside the lastSyncTimestamp.
  • After completing the sync, we check whether the garbage collection should be run (using retentionPeriodDays, current date and lastGarbageCollectionTimestamp).
  • If so, we run it and update lastGarbageCollectionTimestamp

Tests

  • Ongoing.

Risk

  • N/A.

Deploy Plan

  • Apply migration_62.sql.
  • Deploy connectors.

Copy link

github-actions bot commented Mar 6, 2025

Warnings
⚠️

Files in **/lib/models/ have been modified and the PR has the migration-ack label. Don't forget to run the migration from prodbox.

Generated by 🚫 dangerJS against 2982782

@aubin-tchoi aubin-tchoi force-pushed the gong-retention-policy branch 2 times, most recently from ce6bcc7 to 584667b Compare March 6, 2025 16:23
@aubin-tchoi aubin-tchoi added the migration-ack 📁 Label to acknowledge that a migration is required. label Mar 6, 2025
@aubin-tchoi aubin-tchoi force-pushed the gong-retention-policy branch from 19da437 to 2c40deb Compare March 6, 2025 22:08
@aubin-tchoi aubin-tchoi force-pushed the gong-retention-policy branch from 2c40deb to 373d4f4 Compare March 14, 2025 10:44
@aubin-tchoi aubin-tchoi force-pushed the gong-retention-policy branch from d92f873 to ef487c2 Compare March 14, 2025 13:03
@aubin-tchoi aubin-tchoi force-pushed the gong-retention-policy branch from b2b0402 to 4a1f733 Compare March 14, 2025 13:58
@aubin-tchoi aubin-tchoi requested a review from flvndvd March 14, 2025 14:24
# Conflicts:
#	connectors/src/connectors/gong/temporal/activities.ts
switch (configKey) {
case RETENTION_PERIOD_CONFIG_KEY: {
const configuration = await fetchGongConfiguration(connector);
const retentionPeriodDays = configValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to check the result of this with a Number.isFinite() to avoid saving NaN.

garbageCollectionStartTs: number;
}) {
let hasMoreTranscripts = true;
while (hasMoreTranscripts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a do/while to align with code above. Also do/while runs at least once 😉

return Date.now() - this.retentionPeriodDays * 24 * 60 * 60 * 1000;
}
return Math.max(
this.lastSyncTimestamp,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to see the value of this field? In both cases we add an SQL clause on a data field, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand, does this make sense?

if (this.retentionPeriodDays && this.lastSyncTimestamp === null) {
  return Date.now() - daysToMs(this.retentionPeriodDays);
}
return this.lastSyncTimestamp;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is more, why do we store the last GC timestamp? I don't see the value it brings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok the comment line number bugged out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use it to prevent the gc from running every time: currentTimestamp - this.lastGarbageCollectionTimestamp > GC_FREQUENCY_MS, it could be replaced with a modulo on the hour number but this seemed more simple to understand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also run the GC every time, wdyt?


const retentionPeriodStart =
garbageCollectionStartTs -
configuration.retentionPeriodDays * 24 * 60 * 60 * 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit helper for days to ms.

@aubin-tchoi aubin-tchoi merged commit 947027f into main Mar 17, 2025
9 checks passed
@aubin-tchoi aubin-tchoi deleted the gong-retention-policy branch March 17, 2025 09:00
frankaloia pushed a commit that referenced this pull request Mar 17, 2025
* add retentionPeriodDays to GongConfigurationModel

* add migration file

* set lastSyncTimestamp based on the retention period

* make lastSyncTimestamp non nullable

* make lastSyncTimestamp non nullable in db

* merge both sql migration scripts

* add an activity that deleted outdated transcripts

* add a column callDate

* add migration script to create the new column

* make retentionPeriodDays optional (keeps all transcripts)

* add a garbage collect workflow

* fix

* keep lastSyncTimestamp and retentionPeriodDays separate

* Revert "allow selecting the Transcripts folder"

This reverts commit da48897.

* add get/set configuration key methods

* whitelist the new key

* add the garbage collection as a child workflow of the main workflow

* add baseUrl and retentionPeriodDays to the resource's toJSON

* add a column lastGarbageCollectTimestamp to GongConfigurationModel

* add the column lastGarbageCollectTimestamp to the db migration

* rename the column

* prevent the GC from running more than once a day

* move the pagination on GC at the activity level instead of within a single activity

* sort activity list

* add lastGarbageCollectionTimestamp to toJSON

* refactor: simplify checkGarbageCollectionState

* pass along the garbageCollectionStartTs

* rename

* rename

* correctly use the callDate

* remove rebase artefact

* refactor: uniformize a while into a do/while

* add a Number.isFinite check on the parsed value for the retention period

* add an util daysToMs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migration-ack 📁 Label to acknowledge that a migration is required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants