Skip to content

Commit

Permalink
refactor: save environment history enabled by default, and also save …
Browse files Browse the repository at this point in the history
…backup and storage history
  • Loading branch information
shreddedbacon committed Oct 22, 2024
1 parent 2de092e commit b912ab6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions services/api/src/resources/retentionpolicy/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Helpers } from './helpers';
import { sqlClientPool } from '../../clients/sqlClient';
import { Sql as deploymentSql } from '../deployment/sql';
import { Sql as taskSql } from '../task/sql';
import { Sql as backupSql } from '../backup/sql';
import { Sql as environmentSql } from '../environment/sql';
import {
sendToLagoonActions,
// @ts-ignore
Expand Down Expand Up @@ -198,22 +200,27 @@ export const HistoryRetentionEnforcer = () => {
}
const saveEnvironmentHistoryBeforeDeletion = async (projectData: any, environmentData: any) => {
// ENABLE_SAVED_HISTORY_EXPORT will save the deployment and task history if set to true
// this is a way to export a full copy of the environment data (id, name, created, deleted etc..), the project, and the task/deployment history
// this is a way to export a full copy of the environment data (id, name, created, deleted etc..), the project, and the task/deployment/backup/storage history
// this is a JSON payload that could later be consumed for historical purposes
// by default this feature is DISABLED. you should enable this feature if you want to save deleted environment history
// by default this feature is ENABLED
// the deleted data ends up in the lagoon files bucket in a directory called history
const ENABLE_SAVED_HISTORY_EXPORT = process.env.ENABLE_SAVED_HISTORY_EXPORT || "false"
if (ENABLE_SAVED_HISTORY_EXPORT == "true" ) {
// the format of the path is history/{projectname}-{projectid}/{environmentname}-{environmentid}/history-{deletedunixtimestamp}.json
const ENABLE_SAVED_HISTORY_EXPORT = process.env.ENABLE_SAVED_HISTORY_EXPORT || "true"
if (ENABLE_SAVED_HISTORY_EXPORT == "true") {
const taskHistory = await query(sqlClientPool, taskSql.selectTaskHistoryForEnvironment(environmentData.id));
const deploymentHistory = await query(sqlClientPool, deploymentSql.selectDeploymentHistoryForEnvironment(environmentData.id));
const backupHistory = await query(sqlClientPool, backupSql.selectBackupsByEnvironmentId(environmentData.id));
const environmentStorage = await query(sqlClientPool, environmentSql.selectEnvironmentStorageByEnvironmentId(environmentData.id));
const actionData = {
type: "retentionHistory",
eventType: "saveHistory",
data: {
environment: environmentData,
project: projectData,
taskHistory: taskHistory,
deploymentHistory: deploymentHistory
tasks: taskHistory,
deployments: deploymentHistory,
backups: backupHistory,
storage: environmentStorage,
}
}
sendToLagoonActions("retentionHistory", actionData)
Expand Down

0 comments on commit b912ab6

Please sign in to comment.