Skip to content

Commit

Permalink
RHCLOUD-31370 Fix links in integration-disabled template (RedHatInsig…
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg authored Mar 8, 2024
1 parent 4f5e70b commit d0d0ee1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class IntegrationDisabledNotifier {
public static final String ERROR_TYPE_PROPERTY = "error_type";
public static final String ENDPOINT_ID_PROPERTY = "endpoint_id";
public static final String ENDPOINT_NAME_PROPERTY = "endpoint_name";
public static final String ENDPOINT_CATEGORY_PROPERTY = "endpoint_category";
public static final String STATUS_CODE_PROPERTY = "status_code";
public static final String ERRORS_COUNT_PROPERTY = "errors_count";

Expand All @@ -56,6 +57,7 @@ public static Action buildIntegrationDisabledAction(Endpoint endpoint, String er
.withAdditionalProperty(ERROR_TYPE_PROPERTY, errorType)
.withAdditionalProperty(ENDPOINT_ID_PROPERTY, endpoint.getId())
.withAdditionalProperty(ENDPOINT_NAME_PROPERTY, endpoint.getName())
.withAdditionalProperty(ENDPOINT_CATEGORY_PROPERTY, getFrontendCategory(endpoint))
.withAdditionalProperty(ERRORS_COUNT_PROPERTY, errorsCount);

if (statusCode > 0) {
Expand Down Expand Up @@ -83,4 +85,31 @@ public static Action buildIntegrationDisabledAction(Endpoint endpoint, String er
.withRecipients(List.of(recipients))
.build();
}

/*
* The following code is a problem for several reasons:
* - the endpoints category is a frontend key that shouldn't appear in the backend code
* - the endpoints subtype no longer makes sense, we should only have the type
* TODO Let's improve that and fix problems ASAP!
*/
private static String getFrontendCategory(Endpoint endpoint) {
return switch (endpoint.getType()) {
case ANSIBLE -> "Reporting";
case CAMEL -> {
yield switch (endpoint.getSubType()) {
case "google_chat", "slack", "teams" -> "Communications";
case "servicenow", "splunk" -> "Reporting";
default -> {
// The frontend will show the Cloud tab by default if we return an empty string.
yield "";
}
};
}
case WEBHOOK -> "Webhooks";
default -> {
// The frontend will show the Cloud tab by default if we return an empty string.
yield "";
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
{#content-body-section1}
{#if action.context.error_type == "client"}
<p>
Integration <a href="{environment.url}/settings/integrations?name={action.context.endpoint_name}" target="_blank">{action.context.endpoint_name}</a>
Integration <a href="{environment.url}/settings/integrations?category={action.context.endpoint_category}&name={action.context.endpoint_name}" target="_blank">{action.context.endpoint_name}</a>
was disabled because the remote endpoint responded with an HTTP status code {action.context.status_code}.
</p>
<p>
Please review the integration configuration from <a href="{environment.url}/settings/integrations?name={action.context.endpoint_name}" target="_blank">Settings > Integrations</a>
Please review the integration configuration from <a href="{environment.url}/settings/integrations?category={action.context.endpoint_category}&name={action.context.endpoint_name}" target="_blank">Settings > Integrations</a>
to troubleshoot and re-enable the integration.
</p>
{#else}
<p>
Integration <a href="{environment.url}/settings/integrations?name={action.context.endpoint_name}" target="_blank">{action.context.endpoint_name}</a>
Integration <a href="{environment.url}/settings/integrations?category={action.context.endpoint_category}&name={action.context.endpoint_name}" target="_blank">{action.context.endpoint_name}</a>
was disabled because the remote endpoint responded {action.context.errors_count} times with a server error (HTTP status code 5xx).
</p>
<p>
Please re-enable the integration from <a href="{environment.url}/settings/integrations?name={action.context.endpoint_name}" target="_blank">Settings > Integrations</a>
Please re-enable the integration from <a href="{environment.url}/settings/integrations?category={action.context.endpoint_category}&name={action.context.endpoint_name}" target="_blank">Settings > Integrations</a>
if the remote endpoint is ready.
</p>
{/if}
{/content-body-section1}
{#content-button-section1}
<a target="_blank" href="{environment.url}/settings/integrations?name={action.context.endpoint_name}">Open Integrations in Insights</a>
<a target="_blank" href="{environment.url}/settings/integrations?category={action.context.endpoint_category}&name={action.context.endpoint_name}">Open Integrations in Insights</a>
{/content-button-section1}
{/include}
{/include}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.redhat.cloud.notifications.events.ConnectorReceiver.EGRESS_CHANNEL;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.CLIENT_ERROR_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.CONSOLE_BUNDLE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.ENDPOINT_CATEGORY_PROPERTY;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.ENDPOINT_ID_PROPERTY;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.ENDPOINT_NAME_PROPERTY;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.ERRORS_COUNT_PROPERTY;
Expand All @@ -29,6 +30,7 @@
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.INTEGRATION_DISABLED_EVENT_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.SERVER_ERROR_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.STATUS_CODE_PROPERTY;
import static com.redhat.cloud.notifications.models.EndpointType.CAMEL;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -91,6 +93,7 @@ private void checkReceivedAction(Endpoint endpoint, String expectedErrorType, in
assertEquals(expectedErrorType, contextProperties.get(ERROR_TYPE_PROPERTY));
assertEquals(endpoint.getId().toString(), contextProperties.get(ENDPOINT_ID_PROPERTY));
assertEquals(endpoint.getName(), contextProperties.get(ENDPOINT_NAME_PROPERTY));
assertEquals("Communications", contextProperties.get(ENDPOINT_CATEGORY_PROPERTY));
assertEquals(expectedErrorsCount, contextProperties.get(ERRORS_COUNT_PROPERTY));
if (expectedStatusCode > 0) {
assertEquals(expectedStatusCode, contextProperties.get(STATUS_CODE_PROPERTY));
Expand All @@ -102,6 +105,8 @@ private static Endpoint buildEndpoint() {
endpoint.setId(UUID.randomUUID());
endpoint.setOrgId("org-id");
endpoint.setName("My webhook");
endpoint.setType(CAMEL);
endpoint.setSubType("slack");
return endpoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.INTEGRATION_DISABLED_EVENT_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.SERVER_ERROR_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.buildIntegrationDisabledAction;
import static com.redhat.cloud.notifications.models.EndpointType.CAMEL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -67,6 +68,8 @@ private static Endpoint buildEndpoint() {
endpoint.setId(UUID.randomUUID());
endpoint.setName("Unreliable integration");
endpoint.setOrgId(DEFAULT_ORG_ID);
endpoint.setType(CAMEL);
endpoint.setSubType("slack");
return endpoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.CLIENT_ERROR_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.INTEGRATION_DISABLED_EVENT_TYPE;
import static com.redhat.cloud.notifications.events.IntegrationDisabledNotifier.buildIntegrationDisabledAction;
import static com.redhat.cloud.notifications.models.EndpointType.CAMEL;
import static org.junit.jupiter.api.Assertions.assertEquals;

@QuarkusTest
Expand Down Expand Up @@ -45,6 +46,8 @@ private static Endpoint buildEndpoint() {
endpoint.setId(UUID.randomUUID());
endpoint.setName("Unreliable integration");
endpoint.setOrgId(DEFAULT_ORG_ID);
endpoint.setType(CAMEL);
endpoint.setSubType("slack");
return endpoint;
}
}

0 comments on commit d0d0ee1

Please sign in to comment.