From 103965968b58c9c270dc5c2dd6e2e4bb51028923 Mon Sep 17 00:00:00 2001 From: dbbh Date: Mon, 15 Apr 2024 14:10:12 +0100 Subject: [PATCH] [DBInstance] Send EnablePerformanceInsights when changing PerformanceInsightsRetentionPeriod (#531) Co-authored-by: dbbh --- .../amazon/rds/dbinstance/Translator.java | 13 ++++-- .../amazon/rds/dbinstance/TranslatorTest.java | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java b/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java index 06a1aaa3d..3057d810f 100644 --- a/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java +++ b/aws-rds-dbinstance/src/main/java/software/amazon/rds/dbinstance/Translator.java @@ -473,7 +473,6 @@ public static ModifyDbInstanceRequest modifyDbInstanceRequest( .multiAZ(diff(previousModel.getMultiAZ(), desiredModel.getMultiAZ())) .networkType(diff(previousModel.getNetworkType(), desiredModel.getNetworkType())) .optionGroupName(diff(previousModel.getOptionGroupName(), desiredModel.getOptionGroupName())) - .performanceInsightsRetentionPeriod(diff(previousModel.getPerformanceInsightsRetentionPeriod(), desiredModel.getPerformanceInsightsRetentionPeriod())) .preferredBackupWindow(diff(previousModel.getPreferredBackupWindow(), desiredModel.getPreferredBackupWindow())) .preferredMaintenanceWindow(diff(previousModel.getPreferredMaintenanceWindow(), desiredModel.getPreferredMaintenanceWindow())) .promotionTier(desiredModel.getPromotionTier()) // promotion tier is set unconditionally @@ -514,13 +513,15 @@ public static ModifyDbInstanceRequest modifyDbInstanceRequest( builder.useDefaultProcessorFeatures(desiredModel.getUseDefaultProcessorFeatures()); } - // EnablePerformanceInsights (EPI) and PerformanceInsightsKMSKeyId (PKI) are coupled parameters. - // The following logic stands: + // EnablePerformanceInsights (EPI), PerformanceInsightsKMSKeyId (PKI) and PerformanceInsightsRetentionPeriod (PIP) + // are coupled parameters. The following logic stands: // 0. If EPI or PKI are changed, provide the diff unconditionally. // 1. if EPI is true, provide the desired PKI unconditionally. // 2. if PKI is changed, provide the desired EPI unconditionally. + // 3. if PIP is changed, provide the desired EPI unconditionally. final Boolean enablePerformanceInsightsDiff = diff(previousModel.getEnablePerformanceInsights(), desiredModel.getEnablePerformanceInsights()); final String performanceInsightsKMSKeyIdDiff = diff(previousModel.getPerformanceInsightsKMSKeyId(), desiredModel.getPerformanceInsightsKMSKeyId()); + final Integer performanceInsightsRetentionPeriodDiff = diff(previousModel.getPerformanceInsightsRetentionPeriod(), desiredModel.getPerformanceInsightsRetentionPeriod()); if (enablePerformanceInsightsDiff != null || performanceInsightsKMSKeyIdDiff != null) { builder.enablePerformanceInsights(enablePerformanceInsightsDiff); @@ -533,6 +534,11 @@ public static ModifyDbInstanceRequest modifyDbInstanceRequest( } } + if (performanceInsightsRetentionPeriodDiff != null) { + builder.performanceInsightsRetentionPeriod(performanceInsightsRetentionPeriodDiff); + builder.enablePerformanceInsights(desiredModel.getEnablePerformanceInsights()); + } + if (BooleanUtils.isTrue(desiredModel.getManageMasterUserPassword())) { builder.manageMasterUserPassword(true); if (desiredModel.getMasterUserSecret() != null) { @@ -617,6 +623,7 @@ public static ModifyDbInstanceRequest modifyDbInstanceAfterCreateRequest(final R .maxAllocatedStorage(model.getMaxAllocatedStorage()) .monitoringInterval(model.getMonitoringInterval()) .monitoringRoleArn(model.getMonitoringRoleArn()) + .performanceInsightsRetentionPeriod(model.getPerformanceInsightsRetentionPeriod()) .performanceInsightsKMSKeyId(model.getPerformanceInsightsKMSKeyId()) .preferredBackupWindow(model.getPreferredBackupWindow()) .preferredMaintenanceWindow(model.getPreferredMaintenanceWindow()); diff --git a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java index 37a0b2562..34697f558 100644 --- a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java +++ b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/TranslatorTest.java @@ -816,6 +816,38 @@ public void test_modifyDbInstanceRequest_PerformanceInsightsToggleEnabledToDisab assertThat(request.performanceInsightsKMSKeyId()).isNull(); } + @Test + public void test_modifyDbInstanceRequest_PerformanceInsightsChangeRetentionPeriod() { + final int NEW_RETENTION_PERIOD = 31; + final ResourceModel previousModel = ResourceModel.builder() + .enablePerformanceInsights(true) + .performanceInsightsRetentionPeriod(7) + .build(); + final ResourceModel desiredModel = ResourceModel.builder() + .enablePerformanceInsights(true) + .performanceInsightsRetentionPeriod(NEW_RETENTION_PERIOD) + .build(); + final ModifyDbInstanceRequest request = Translator.modifyDbInstanceRequest(previousModel, desiredModel, false); + assertThat(request.enablePerformanceInsights()).isTrue(); + assertThat(request.performanceInsightsRetentionPeriod()).isEqualTo(NEW_RETENTION_PERIOD); + } + + @Test + public void test_modifyDbInstanceRequest_NoPerformanceInsightsChangeRetentionPeriod() { + final int NEW_RETENTION_PERIOD = 31; + final ResourceModel previousModel = ResourceModel.builder() + .enablePerformanceInsights(false) + .performanceInsightsRetentionPeriod(7) + .build(); + final ResourceModel desiredModel = ResourceModel.builder() + .enablePerformanceInsights(false) + .performanceInsightsRetentionPeriod(NEW_RETENTION_PERIOD) + .build(); + final ModifyDbInstanceRequest request = Translator.modifyDbInstanceRequest(previousModel, desiredModel, false); + assertThat(request.enablePerformanceInsights()).isFalse(); + assertThat(request.performanceInsightsRetentionPeriod()).isEqualTo(NEW_RETENTION_PERIOD); + } + @Test public void test_modifyDbInstanceRequest_PerformanceInsightsEnabledChangeKMSKeyId() { final String kmsKeyId1 = "test-kms-key-id-1"; @@ -1097,6 +1129,18 @@ public void test_modifyAfterCreate_shouldSetEnablePerformanceInsights() { assertThat(request.enablePerformanceInsights()).isTrue(); } + @Test + public void test_modifyAfterCreate_shouldSetEnablePerformanceInsightsRetentionPeriod() { + final int PI_RETENTION_PERIOD = 31; + final ResourceModel model = RESOURCE_MODEL_BLDR() + .enablePerformanceInsights(true) + .performanceInsightsRetentionPeriod(PI_RETENTION_PERIOD) + .build(); + final ModifyDbInstanceRequest request = Translator.modifyDbInstanceAfterCreateRequest(model); + assertThat(request.enablePerformanceInsights()).isTrue(); + assertThat(request.performanceInsightsRetentionPeriod()).isEqualTo(PI_RETENTION_PERIOD); + } + @Test public void test_modifyAfterCreate_shouldSetEnhancedMonitoring() { final String monitoringRoleArn = "monitoring-role-arn";